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 all 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
21 changes: 21 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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
-
message: '#Call to an undefined method Laminas\\Authentication\\AuthenticationServiceInterface::getStorage\(\)#'
path: src/App/src/Middleware/RememberMeMiddleware.php

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.

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;
}
4 changes: 2 additions & 2 deletions src/User/src/Service/UserService.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public function sendActivationMail(User $user): bool
return $this->mailService->send()->isValid();
}

public function findOneBy(array $params = []): ?UserInterface
public function findOneBy(array $params = []): ?User
{
if (empty($params)) {
return null;
Expand Down Expand Up @@ -344,7 +344,7 @@ public function getRepository(): UserRepository
/**
* @throws Exception
*/
public function addRememberMeToken(UserInterface|User $user, string $userAgent, array $cookies = []): void
public function addRememberMeToken(User $user, string $userAgent, array $cookies = []): void
{
$this->deleteExpiredRememberMeTokens();

Expand Down
4 changes: 2 additions & 2 deletions src/User/src/Service/UserServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public function createUser(array $data): UserInterface;
*/
public function sendActivationMail(User $user): bool;

public function findOneBy(array $params = []): ?UserInterface;
public function findOneBy(array $params = []): ?User;

public function activateUser(User $user): User;

public function findByUuid(string $uuid): ?User;

public function getRepository(): UserRepository;

public function addRememberMeToken(UserInterface|User $user, string $userAgent, array $cookies = []): void;
public function addRememberMeToken(User $user, string $userAgent, array $cookies = []): void;

public function deleteRememberMeToken(array $cookies = []): void;

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