diff --git a/.github/workflows/back-end.yml b/.github/workflows/back-end.yml index 8dce6a04..70188e06 100644 --- a/.github/workflows/back-end.yml +++ b/.github/workflows/back-end.yml @@ -76,6 +76,17 @@ jobs: uses: "ramsey/composer-install@v3" with: dependency-versions: "${{ matrix.dependencies }}" + - + name: "Declare strict types" + if: "${{ matrix.dependencies == 'highest' }}" + run: | + echo "::group::Install slevomat/coding-standard" + composer config --no-plugins allow-plugins.dealerdirect/phpcodesniffer-composer-installer false + composer require --no-scripts --dev slevomat/coding-standard + echo "::endgroup::" + composer exec -- phpcbf --standard=vendor/slevomat/coding-standard/SlevomatCodingStandard \ + --sniffs=SlevomatCodingStandard.TypeHints.DeclareStrictTypes src/ \ + || test "$?" = 1 && exit 0 - name: "Execute unit tests" run: "composer exec -- phpunit" diff --git a/src/Fields/Field.php b/src/Fields/Field.php index bd0bc370..6c63ed6f 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -519,7 +519,7 @@ public function resolveFormat(Request $request, Model $model): ?string $value = $this->resolveValue($request, $model); if (is_null($this->formatResolver)) { - return is_array($value) ? json_encode($value) : $value; + return is_array($value) ? json_encode($value) : (string) $value; } return call_user_func_array($this->formatResolver, [$request, $model, $value]); diff --git a/src/Fields/Relation.php b/src/Fields/Relation.php index 901ef458..520af659 100644 --- a/src/Fields/Relation.php +++ b/src/Fields/Relation.php @@ -679,7 +679,7 @@ public function mapRelated(Request $request, Model $model, Model $related): arra */ public function modelUrl(Model $model): string { - return str_replace('{resourceModel}', $model->exists ? $model->getKey() : 'create', $this->getUri()); + return str_replace('{resourceModel}', $model->exists ? (string) $model->getKey() : 'create', $this->getUri()); } /** @@ -906,7 +906,7 @@ public function parseQueryString(string $url): array { $query = parse_url($url, PHP_URL_QUERY); - parse_str($query, $result); + parse_str($query ?? '', $result); return array_filter($result, fn (string $key): bool => str_starts_with($key, $this->getRequestKey()), ARRAY_FILTER_USE_KEY); } diff --git a/src/Fields/Repeater.php b/src/Fields/Repeater.php index 876140c3..5130f811 100644 --- a/src/Fields/Repeater.php +++ b/src/Fields/Repeater.php @@ -207,7 +207,7 @@ public function buildOption(Request $request, Model $model): array */ public function modelUrl(Model $model): string { - return str_replace('{resourceModel}', $model->exists ? $model->getKey() : 'create', $this->getUri()); + return str_replace('{resourceModel}', $model->exists ? (string) $model->getKey() : 'create', $this->getUri()); } /** diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php index b13cde14..2317a2f0 100644 --- a/src/Resources/Resource.php +++ b/src/Resources/Resource.php @@ -315,7 +315,7 @@ public function modelUrl(Model $model): string */ public function modelTitle(Model $model): string { - return $model->getKey(); + return (string) $model->getKey(); } /** diff --git a/tests/Http/RelationControllerTest.php b/tests/Http/RelationControllerTest.php index 923eff0d..41706441 100644 --- a/tests/Http/RelationControllerTest.php +++ b/tests/Http/RelationControllerTest.php @@ -35,9 +35,11 @@ protected function setUp(): void ); } + #[\PHPUnit\Framework\Attributes\WithoutErrorHandler] public function test_relation_controller_handles_index(): void { $this->actingAs($this->admin) + ->withoutExceptionHandling() ->get('/root/resources/users/'.$this->admin->getKey().'/fields/uploads') ->assertOk() ->assertViewIs('root::resources.index')