From 84e01325df00e7623b9d4c0e06564d904fe48fa9 Mon Sep 17 00:00:00 2001 From: Mark Huot Date: Sat, 17 Feb 2024 23:05:59 +0000 Subject: [PATCH] phpstan fixes --- .github/workflows/php.yml | 2 ++ phpstan.neon | 1 + src/Pest.php | 4 ++-- src/factories/Field.php | 16 +++++++++++----- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 37ac272..0e1cf6a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -90,6 +90,8 @@ jobs: - name: Run pint run: ./vendor/bin/pint --test -vvv src/ + if: success() || failure() - name: Run test suite run: ./vendor/bin/pest --compact -vvv + if: success() || failure() diff --git a/phpstan.neon b/phpstan.neon index 9843abd..cdd9712 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -15,3 +15,4 @@ parameters: excludePaths: - src/craft/* - src/illuminate/* + - src/actions/RenderCompiledClasses.php diff --git a/src/Pest.php b/src/Pest.php index 29d3976..7880d28 100644 --- a/src/Pest.php +++ b/src/Pest.php @@ -56,8 +56,8 @@ function (DefineBehaviorsEvent $event) { Craft::$container->set(SectionsServiceInterface::class, function () { return version_compare(Craft::$app->version, '5.0.0', '>=') ? - Craft::$app->getEntries() : - Craft::$app->getSections(); + Craft::$app->getEntries() : // @phpstan-ignore-line + Craft::$app->getSections(); // @phpstan-ignore-line }); } } diff --git a/src/factories/Field.php b/src/factories/Field.php index 8212832..cb85339 100644 --- a/src/factories/Field.php +++ b/src/factories/Field.php @@ -2,6 +2,7 @@ namespace markhuot\craftpest\factories; +use Craft; use craft\helpers\StringHelper; /** @@ -23,7 +24,7 @@ public function type(string $type) public function group(string $groupName) { $this->attributes['groupId'] = function () use ($groupName) { - foreach (\Craft::$app->fields->getAllGroups() as $group) { + foreach (\Craft::$app->fields->getAllGroups() as $group) { //@phpstan-ignore-line if ($group->name === $groupName) { return $group->id; } @@ -55,12 +56,17 @@ public function newElement() public function definition(int $index = 0) { $name = $this->faker->words(2, true); -// $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; - - return [ + + $definition = [ 'name' => $name, -// 'groupId' => $firstFieldGroupId, ]; + + if (version_compare(Craft::$app->version, '5.0.0', '<')) { + $firstFieldGroupId = \Craft::$app->fields->getAllGroups()[0]->id; // @phpstan-ignore-line + $definition['groupId'] = $firstFieldGroupId; + } + + return $definition; } public function inferences(array $definition = [])