Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced Psalm with PHPStan #506

Merged
merged 4 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ Dotkernel web starter package suitable for frontend applications.
[![Continuous Integration](https://github.com/dotkernel/frontend/actions/workflows/continuous-integration.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/frontend/actions/workflows/continuous-integration.yml)
[![codecov](https://codecov.io/gh/dotkernel/frontend/graph/badge.svg?token=BQS43UWAM4)](https://codecov.io/gh/dotkernel/frontend)
[![Qodana](https://github.com/dotkernel/frontend/actions/workflows/qodana_code_quality.yml/badge.svg)](https://github.com/dotkernel/frontend/actions/workflows/qodana_code_quality.yml)

[![SymfonyInsight](https://insight.symfony.com/projects/a28dac55-3366-4020-9a49-53f6fcbeda4e/big.svg)](https://insight.symfony.com/projects/a28dac55-3366-4020-9a49-53f6fcbeda4e)
[![PHPStan](https://github.com/dotkernel/frontend/actions/workflows/static-analysis.yml/badge.svg?branch=5.0)](https://github.com/dotkernel/frontend/actions/workflows/static-analysis.yml)

## Installing DotKernel `frontend`

Expand Down
12 changes: 8 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@
"mezzio/mezzio-tooling": "^2.9.0",
"phpunit/phpunit": "^10.5",
"roave/security-advisories": "dev-master",
"vimeo/psalm": "^5.21.1",
"vincentlanglet/twig-cs-fixer": "^2.12"
"vincentlanglet/twig-cs-fixer": "^2.12",
"phpstan/phpstan": "^2.0",
"phpstan/phpstan-doctrine": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"symfony/var-dumper": "^7.1"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -107,13 +110,14 @@
"mezzio": "mezzio --ansi",
"check": [
"@cs-check",
"@test"
"@test",
"@static-analysis"
],
"clear-config-cache": "php bin/clear-config-cache.php",
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"serve": "php -S 0.0.0.0:8080 -t public/",
"static-analysis": "psalm --shepherd --stats",
"static-analysis": "phpstan analyse",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"twig-cs-check": "vendor/bin/twig-cs-fixer lint --config=config/twig-cs-fixer.php",
Expand Down
18 changes: 18 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
includes:
- vendor/phpstan/phpstan-doctrine/extension.neon
- vendor/phpstan/phpstan-phpunit/extension.neon
parameters:
level: 5
paths:
- src
- test
treatPhpDocTypesAsCertain: false
ignoreErrors:
- '/Parameter #1 \$expected of method PHPUnit\\Framework\\Assert::assertSame\(\) contains unresolvable type\./'
-
message: '#Call to method PHPUnit\\Framework\\Assert::assertInstanceOf\(\) with .* will always evaluate to true.#'
path: test
-
message: '#Call to an undefined method Laminas\\InputFilter\\InputFilterInterface::getInputs\(\)#'
path: test

19 changes: 0 additions & 19 deletions psalm-baseline.xml

This file was deleted.

17 changes: 0 additions & 17 deletions psalm.xml

This file was deleted.

6 changes: 3 additions & 3 deletions src/App/src/Middleware/RememberMeMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Dot\DependencyInjection\Attribute\Inject;
use Frontend\User\Entity\UserIdentity;
use Frontend\User\Service\UserServiceInterface;
use Laminas\Authentication\AuthenticationServiceInterface;
use Laminas\Authentication\AuthenticationService;
use Laminas\Authentication\Exception\ExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
Expand All @@ -20,12 +20,12 @@ class RememberMeMiddleware implements MiddlewareInterface
{
#[Inject(
UserServiceInterface::class,
AuthenticationServiceInterface::class,
AuthenticationService::class,
MarioRadu marked this conversation as resolved.
Show resolved Hide resolved
"config.rememberMe",
)]
public function __construct(
protected UserServiceInterface $userService,
protected AuthenticationServiceInterface $authenticationService,
protected AuthenticationService $authenticationService,
protected array $rememberConfig
) {
}
Expand Down
3 changes: 2 additions & 1 deletion src/App/src/Service/CookieService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@

use Dot\DependencyInjection\Attribute\Inject;
use Laminas\Session\Config\ConfigInterface;
use Laminas\Session\Config\SameSiteCookieCapableInterface;
use Laminas\Session\SessionManager;

use function setcookie;
use function time;

class CookieService implements CookieServiceInterface
{
private ConfigInterface $sessionConfig;
private ConfigInterface|SameSiteCookieCapableInterface $sessionConfig;

#[Inject(SessionManager::class)]
public function __construct(SessionManager $sessionManager)
Expand Down
3 changes: 1 addition & 2 deletions src/Contact/src/Service/MessageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Frontend\Contact\Service;

use Doctrine\ORM\EntityRepository;
use Dot\DependencyInjection\Attribute\Inject;
use Dot\Mail\Service\MailServiceInterface;
use Frontend\Contact\Entity\Message;
Expand All @@ -28,7 +27,7 @@ public function __construct(
) {
}

public function getRepository(): MessageRepository|EntityRepository
public function getRepository(): MessageRepository
{
return $this->repository;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Plugin/src/PluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@
*/
class PluginManager extends AbstractPluginManager
{
/** @var string $instanceOf */
/** @var class-string<mixed>|null $instanceOf */
protected $instanceOf = PluginInterface::class;
}
6 changes: 3 additions & 3 deletions src/User/src/Entity/UserRememberMe.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class UserRememberMe extends AbstractEntity

#[ORM\ManyToOne(targetEntity: User::class)]
#[ORM\JoinColumn(name: 'userUuid', referencedColumnName: 'uuid', nullable: false)]
protected User $user;
protected User|UserInterface $user;
MarioRadu marked this conversation as resolved.
Show resolved Hide resolved

#[ORM\Column(name: 'rememberMeToken', type: 'string', length: 100, unique: true, nullable: false)]
protected string $rememberMeToken = '';
Expand All @@ -29,12 +29,12 @@ class UserRememberMe extends AbstractEntity
#[ORM\Column(name: 'expireDate', type: 'datetime_immutable')]
protected DateTimeImmutable $expireDate;

public function getUser(): User
public function getUser(): User|UserInterface
{
return $this->user;
}

public function setUser(User $user): self
public function setUser(User|UserInterface $user): self
{
$this->user = $user;

Expand Down
3 changes: 2 additions & 1 deletion src/User/src/Repository/UserRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Dot\DependencyInjection\Attribute\Entity;
use Exception;
use Frontend\User\Entity\User;
use Frontend\User\Entity\UserInterface;
use Frontend\User\Entity\UserRememberMe;
use Ramsey\Uuid\Uuid;

Expand Down Expand Up @@ -103,7 +104,7 @@ public function getRememberUser(string $token): ?UserRememberMe
/**
* @throws NonUniqueResultException
*/
public function findRememberMeUser(User $user, string $userAgent): ?UserRememberMe
public function findRememberMeUser(User|UserInterface $user, string $userAgent): ?UserRememberMe
MarioRadu marked this conversation as resolved.
Show resolved Hide resolved
{
$qb = $this->getEntityManager()->createQueryBuilder();
$qb->select('user_remember_me')
Expand Down
5 changes: 3 additions & 2 deletions test/Unit/App/Middleware/RememberMeMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
use Laminas\Authentication\AuthenticationService;
use Laminas\Authentication\Exception\ExceptionInterface;
use PHPUnit\Framework\MockObject\Exception;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\RequestHandlerInterface;

class RememberMeMiddlewareTest extends TestCase
{
private ServerRequestInterface $request;
private ServerRequestInterface|MockObject $request;

private RequestHandlerInterface $handler;
private RequestHandlerInterface|MockObject $handler;

/**
* @throws Exception
Expand Down
3 changes: 2 additions & 1 deletion test/Unit/Plugin/FormsPluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function testWillRestoreState(): void
{
$hash = (new Csrf(['session' => new Container()]))->getHash();

/** @var array<string, string> $oldData */
$oldData = [
'identity' => 'old@identity.com',
'password' => 'old-password',
Expand Down Expand Up @@ -155,7 +156,7 @@ public function testWillGetMessages(): void
$this->assertNotEmpty($messagesAsString);
}

private function getDummyFlashMessenger(): FlashMessengerInterface
private function getDummyFlashMessenger(): object
{
return new class implements FlashMessengerInterface {
private array $data = [];
Expand Down