Skip to content

Commit 7aa9a83

Browse files
committed
Merge fix/nova-435-resolve-method-signature: Nova 4.35.x compatibility fix
Fixes method signature incompatibility with Laravel Nova 4.35.x by removing strict type hints from resolve() and resolveForDisplay() methods. Closes #1
2 parents 89305cc + b3796b6 commit 7aa9a83

7 files changed

Lines changed: 106 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,22 @@
22

33
All notable changes to `nova-dependency-container` will be documented in this file.
44

5+
## [1.0.4] - 2025-11-25
6+
7+
### Fixed
8+
- Fixed Nova 4.35.x compatibility issue with `resolveForDisplay` method signature mismatch ([#1](https://github.com/iamgerwin/nova-dependency-container/issues/1))
9+
- Fixed `resolve` method signature to match parent `Laravel\Nova\Fields\Field` class
10+
- Updated `Stubs/Field.php` method signatures to align with Nova's actual implementation
11+
12+
### Changed
13+
- Removed strict type hints from `resolve($resource, $attribute = null)` method for Nova compatibility
14+
- Removed strict type hints from `resolveForDisplay($resource, $attribute = null)` method for Nova compatibility
15+
- Updated `MockField` test mock to use compatible method signatures
16+
17+
### Added
18+
- Added comprehensive tests for method signature compatibility using PHP Reflection API
19+
- Added tests for method invocation with various argument types
20+
521
## [1.0.3] - 2025-09-26
622

723
### Added

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ A Laravel Nova field container allowing fields to depend on other field values.
1414
- **Conditional Field Display**: Show/hide fields based on other field values
1515
- **Multiple Dependency Types**: Support for various comparison operators
1616
- **Complex Logic**: Chain multiple conditions together
17-
- **Nova 4 & 5 Compatible**: Works with Laravel Nova 4.x and 5.x (tested with Nova 5.7.5)
17+
- **Nova 4 & 5 Compatible**: Works with Laravel Nova 4.x and 5.x (tested with Nova 4.35.x and Nova 5.7.5)
1818
- **Laravel 12 Ready**: Full support for Laravel 11.x and 12.x
1919
- **PHP 8.3 Support**: Modern PHP features and type safety
2020
- **Fully Tested**: Comprehensive test coverage with Pest

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "iamgerwin/nova-dependency-container",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"description": "A Laravel Nova 4 and 5 field container allowing to depend on other fields values",
55
"keywords": [
66
"laravel",

src/NovaDependencyContainer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public function fill($request, $model): void
187187
}
188188
}
189189

190-
public function resolve($resource, ?string $attribute = null): void
190+
public function resolve($resource, $attribute = null)
191191
{
192192
foreach ($this->fields as $field) {
193193
if ($field instanceof Field) {
@@ -196,7 +196,7 @@ public function resolve($resource, ?string $attribute = null): void
196196
}
197197
}
198198

199-
public function resolveForDisplay($resource, ?string $attribute = null): void
199+
public function resolveForDisplay($resource, $attribute = null)
200200
{
201201
foreach ($this->fields as $field) {
202202
if ($field instanceof Field) {

src/Stubs/Field.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function fill($request, $model)
6565
return function () {};
6666
}
6767

68-
public function resolve($resource, ?string $attribute = null): void {}
68+
public function resolve($resource, $attribute = null) {}
6969

70-
public function resolveForDisplay($resource, ?string $attribute = null): void {}
70+
public function resolveForDisplay($resource, $attribute = null) {}
7171
}

tests/Mocks/MockField.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function fill($request, $model)
4949
return function () {};
5050
}
5151

52-
public function resolve($resource, ?string $attribute = null): void {}
52+
public function resolve($resource, $attribute = null) {}
5353

54-
public function resolveForDisplay($resource, ?string $attribute = null): void {}
54+
public function resolveForDisplay($resource, $attribute = null) {}
5555
}

tests/Unit/NovaDependencyContainerTest.php

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,85 @@ class Text extends MockField
169169

170170
expect($container->showOnDetail)->toBeFalse();
171171
});
172+
173+
it('has resolve method signature compatible with Nova Field class', function () {
174+
$reflection = new ReflectionMethod(NovaDependencyContainer::class, 'resolve');
175+
176+
// Method should have no return type (matches Nova Field parent class)
177+
expect($reflection->hasReturnType())->toBeFalse();
178+
179+
// Method should have two parameters
180+
$parameters = $reflection->getParameters();
181+
expect($parameters)->toHaveCount(2);
182+
183+
// First parameter: $resource (no type hint)
184+
expect($parameters[0]->getName())->toBe('resource');
185+
expect($parameters[0]->hasType())->toBeFalse();
186+
187+
// Second parameter: $attribute (no type hint, has default null)
188+
expect($parameters[1]->getName())->toBe('attribute');
189+
expect($parameters[1]->hasType())->toBeFalse();
190+
expect($parameters[1]->isDefaultValueAvailable())->toBeTrue();
191+
expect($parameters[1]->getDefaultValue())->toBeNull();
192+
});
193+
194+
it('has resolveForDisplay method signature compatible with Nova Field class', function () {
195+
$reflection = new ReflectionMethod(NovaDependencyContainer::class, 'resolveForDisplay');
196+
197+
// Method should have no return type (matches Nova Field parent class)
198+
expect($reflection->hasReturnType())->toBeFalse();
199+
200+
// Method should have two parameters
201+
$parameters = $reflection->getParameters();
202+
expect($parameters)->toHaveCount(2);
203+
204+
// First parameter: $resource (no type hint)
205+
expect($parameters[0]->getName())->toBe('resource');
206+
expect($parameters[0]->hasType())->toBeFalse();
207+
208+
// Second parameter: $attribute (no type hint, has default null)
209+
expect($parameters[1]->getName())->toBe('attribute');
210+
expect($parameters[1]->hasType())->toBeFalse();
211+
expect($parameters[1]->isDefaultValueAvailable())->toBeTrue();
212+
expect($parameters[1]->getDefaultValue())->toBeNull();
213+
});
214+
215+
it('can call resolve method with various argument types', function () {
216+
$container = NovaDependencyContainer::make([
217+
Text::make('Field 1'),
218+
]);
219+
220+
$resource = new stdClass;
221+
$resource->field_1 = 'test value';
222+
223+
// Should work with null attribute (default)
224+
$container->resolve($resource);
225+
226+
// Should work with string attribute
227+
$container->resolve($resource, 'field_1');
228+
229+
// Should work with null explicitly passed
230+
$container->resolve($resource, null);
231+
232+
expect(true)->toBeTrue();
233+
});
234+
235+
it('can call resolveForDisplay method with various argument types', function () {
236+
$container = NovaDependencyContainer::make([
237+
Text::make('Field 1'),
238+
]);
239+
240+
$resource = new stdClass;
241+
$resource->field_1 = 'test value';
242+
243+
// Should work with null attribute (default)
244+
$container->resolveForDisplay($resource);
245+
246+
// Should work with string attribute
247+
$container->resolveForDisplay($resource, 'field_1');
248+
249+
// Should work with null explicitly passed
250+
$container->resolveForDisplay($resource, null);
251+
252+
expect(true)->toBeTrue();
253+
});

0 commit comments

Comments
 (0)