diff --git a/.github/workflows/back-end.yml b/.github/workflows/back-end.yml index 610035c4..d62804aa 100644 --- a/.github/workflows/back-end.yml +++ b/.github/workflows/back-end.yml @@ -76,6 +76,17 @@ jobs: uses: "ramsey/composer-install@v2" 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 3f8ab8b5..6cada8da 100644 --- a/src/Fields/Field.php +++ b/src/Fields/Field.php @@ -445,7 +445,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 dcefe43b..d82b0531 100644 --- a/src/Fields/Relation.php +++ b/src/Fields/Relation.php @@ -573,7 +573,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()); } /** diff --git a/src/Resources/Resource.php b/src/Resources/Resource.php index 8e82811a..83db6697 100644 --- a/src/Resources/Resource.php +++ b/src/Resources/Resource.php @@ -297,7 +297,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 f415e6dd..ff9e25e8 100644 --- a/tests/Http/RelationControllerTest.php +++ b/tests/Http/RelationControllerTest.php @@ -35,9 +35,11 @@ public function setUp(): void ); } + #[\PHPUnit\Framework\Attributes\WithoutErrorHandler] public function test_a_relation_controller_handles_index(): void { $this->actingAs($this->admin) + ->withoutExceptionHandling() ->get('/root/users/'.$this->admin->getKey().'/fields/uploads') ->assertOk() ->assertViewIs('root::resources.index')