Skip to content

Commit 9eadcdf

Browse files
committed
Various PHPStan fix
1 parent a9686b0 commit 9eadcdf

File tree

5 files changed

+18
-7
lines changed

5 files changed

+18
-7
lines changed

src/Codeception/Module/Symfony/ConsoleAssertionsTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ private function configureOptions(array $parameters): array
101101

102102
protected function grabKernelService(): KernelInterface
103103
{
104-
return $this->grabService('kernel');
104+
/** @var KernelInterface $kernel */
105+
$kernel = $this->grabService(KernelInterface::class);
106+
return $kernel;
105107
}
106108
}

src/Codeception/Module/Symfony/MailerAssertionsTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Codeception\Module\Symfony;
66

7+
use PHPUnit\Framework\Assert;
78
use PHPUnit\Framework\Constraint\LogicalNot;
89
use Symfony\Component\Mailer\Event\MessageEvent;
910
use Symfony\Component\Mailer\Event\MessageEvents;
@@ -117,7 +118,7 @@ public function grabLastSentEmail(): ?Email
117118
* $emails = $I->grabSentEmails();
118119
* ```
119120
*
120-
* @return \Symfony\Component\Mime\Email[]
121+
* @return \Symfony\Component\Mime\RawMessage[]
121122
*/
122123
public function grabSentEmails(): array
123124
{
@@ -171,6 +172,6 @@ protected function getMessageMailerEvents(): MessageEvents
171172
/** @var MessageLoggerListener $mailer */
172173
return $mailer->getEvents();
173174
}
174-
$this->fail("Emails can't be tested without Symfony Mailer service.");
175+
Assert::fail("Emails can't be tested without Symfony Mailer service.");
175176
}
176177
}

src/Codeception/Module/Symfony/ParameterAssertionsTrait.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ trait ParameterAssertionsTrait
1717
* $I->grabParameter('app.business_name');
1818
* ```
1919
* This only works for explicitly set parameters (just using `bind` for Symfony's dependency injection is not enough).
20+
*
21+
* @return array<array-key, mixed>|bool|string|int|float|UnitEnum|null
2022
*/
2123
public function grabParameter(string $parameterName): array|bool|string|int|float|UnitEnum|null
2224
{
@@ -26,6 +28,8 @@ public function grabParameter(string $parameterName): array|bool|string|int|floa
2628

2729
protected function grabParameterBagService(): ParameterBagInterface
2830
{
29-
return $this->grabService('parameter_bag');
31+
/** @var ParameterBagInterface $parameterBag */
32+
$parameterBag = $this->grabService(ParameterBagInterface::class);
33+
return $parameterBag;
3034
}
3135
}

src/Codeception/Module/Symfony/ServicesAssertionsTrait.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ trait ServicesAssertionsTrait
2525
public function grabService(string $serviceId): object
2626
{
2727
if (!$service = $this->getService($serviceId)) {
28-
Assert::fail("Service `{$serviceId}` is required by Codeception, but not loaded by Symfony. Possible solutions:\n
28+
Assert::fail(
29+
"Service `{$serviceId}` is required by Codeception, but not loaded by Symfony. Possible solutions:\n
2930
In your `config/packages/framework.php`/`.yaml`, set `test` to `true` (when in test environment), see https://symfony.com/doc/current/reference/configuration/framework.html#test\n
3031
If you're still getting this message, you're not using that service in your app, so Symfony isn't loading it at all.\n
31-
Solution: Set it to `public` in your `config/services.php`/`.yaml`, see https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private\n");
32+
Solution: Set it to `public` in your `config/services.php`/`.yaml`, see https://symfony.com/doc/current/service_container/alias_private.html#marking-services-as-public-private\n"
33+
);
3234
}
3335

3436
return $service;

src/Codeception/Module/Symfony/ValidatorAssertionsTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ protected function getViolationsForSubject(object $subject, ?string $propertyPat
101101

102102
protected function getValidatorService(): ValidatorInterface
103103
{
104-
return $this->grabService(ValidatorInterface::class);
104+
/** @var ValidatorInterface $validator */
105+
$validator = $this->grabService(ValidatorInterface::class);
106+
return $validator;
105107
}
106108
}

0 commit comments

Comments
 (0)