From b7899cc8a5b754176ef7dfd1ca91c256212e21be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gangloff?= Date: Sat, 3 Aug 2024 00:06:38 +0200 Subject: [PATCH] ci: add phpstan --- .gitignore | 4 ++ composer.json | 1 + composer.lock | 60 +++++++++++++++++++++- phpstan.dist.neon | 8 +++ src/Controller/ConnectorController.php | 4 +- src/Controller/DomainRefreshController.php | 2 +- src/Controller/HomeController.php | 2 +- src/Controller/WatchListController.php | 15 +++--- src/Entity/User.php | 3 -- src/Service/RDAPService.php | 2 +- symfony.lock | 12 +++++ 11 files changed, 99 insertions(+), 14 deletions(-) create mode 100644 phpstan.dist.neon diff --git a/.gitignore b/.gitignore index b58eda7..adf08f4 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,7 @@ yarn-error.log /.php-cs-fixer.php /.php-cs-fixer.cache ###< friendsofphp/php-cs-fixer ### + +###> phpstan/phpstan ### +phpstan.neon +###< phpstan/phpstan ### diff --git a/composer.json b/composer.json index 9a58638..20fe884 100644 --- a/composer.json +++ b/composer.json @@ -127,6 +127,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.61", + "phpstan/phpstan": "^1.11", "phpunit/phpunit": "^9.5", "symfony/browser-kit": "7.1.*", "symfony/css-selector": "7.1.*", diff --git a/composer.lock b/composer.lock index 3a64fb3..757bae3 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "94a201d97ed1f0ed40eda7bdc44e6e36", + "content-hash": "6b52bd3ad92da490e7a206500d0c0348", "packages": [ { "name": "api-platform/core", @@ -10390,6 +10390,64 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "phpstan/phpstan", + "version": "1.11.9", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan.git", + "reference": "e370bcddadaede0c1716338b262346f40d296f82" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e370bcddadaede0c1716338b262346f40d296f82", + "reference": "e370bcddadaede0c1716338b262346f40d296f82", + "shasum": "" + }, + "require": { + "php": "^7.2|^8.0" + }, + "conflict": { + "phpstan/phpstan-shim": "*" + }, + "bin": [ + "phpstan", + "phpstan.phar" + ], + "type": "library", + "autoload": { + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPStan - PHP Static Analysis Tool", + "keywords": [ + "dev", + "static analysis" + ], + "support": { + "docs": "https://phpstan.org/user-guide/getting-started", + "forum": "https://github.com/phpstan/phpstan/discussions", + "issues": "https://github.com/phpstan/phpstan/issues", + "security": "https://github.com/phpstan/phpstan/security/policy", + "source": "https://github.com/phpstan/phpstan-src" + }, + "funding": [ + { + "url": "https://github.com/ondrejmirtes", + "type": "github" + }, + { + "url": "https://github.com/phpstan", + "type": "github" + } + ], + "time": "2024-08-01T16:25:18+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "9.2.31", diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 0000000..77a0da7 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,8 @@ +parameters: + level: 5 + paths: + - bin/ + - config/ + - public/ + - src/ + - tests/ diff --git a/src/Controller/ConnectorController.php b/src/Controller/ConnectorController.php index 36b492c..6d2c3dd 100644 --- a/src/Controller/ConnectorController.php +++ b/src/Controller/ConnectorController.php @@ -52,7 +52,9 @@ class ConnectorController extends AbstractController public function createConnector(Request $request): Connector { $connector = $this->serializer->deserialize($request->getContent(), Connector::class, 'json', ['groups' => 'connector:create']); - $connector->setUser($this->getUser()); + /** @var User $user */ + $user = $this->getUser(); + $connector->setUser($user); if (ConnectorProvider::OVH === $connector->getProvider()) { $authData = OvhConnector::verifyAuthData($connector->getAuthData()); diff --git a/src/Controller/DomainRefreshController.php b/src/Controller/DomainRefreshController.php index eeb104f..1e2eed1 100644 --- a/src/Controller/DomainRefreshController.php +++ b/src/Controller/DomainRefreshController.php @@ -54,7 +54,7 @@ class DomainRefreshController extends AbstractController } } - $updatedAt = null === $domain ? new \DateTimeImmutable('now') : $domain->getUpdatedAt(); + $updatedAt = null === $domain->getUpdatedAt() ? new \DateTimeImmutable('now') : $domain->getUpdatedAt(); $domain = $this->RDAPService->registerDomain($ldhName); /** @var WatchList $watchList */ diff --git a/src/Controller/HomeController.php b/src/Controller/HomeController.php index 2c7e7d8..022d62f 100644 --- a/src/Controller/HomeController.php +++ b/src/Controller/HomeController.php @@ -25,7 +25,7 @@ class HomeController extends AbstractController #[Route(path: '/login/oauth', name: 'oauth_connect')] public function connectAction(ClientRegistry $clientRegistry): Response { - return $clientRegistry->getClient('oauth')->redirect(); + return $clientRegistry->getClient('oauth')->redirect([], []); } #[Route(path: '/logout', name: 'logout')] diff --git a/src/Controller/WatchListController.php b/src/Controller/WatchListController.php index d93d63d..6fab102 100644 --- a/src/Controller/WatchListController.php +++ b/src/Controller/WatchListController.php @@ -51,7 +51,9 @@ class WatchListController extends AbstractController public function createWatchList(Request $request): WatchList { $watchList = $this->serializer->deserialize($request->getContent(), WatchList::class, 'json', ['groups' => 'watchlist:create']); - $watchList->setUser($this->getUser()); + /** @var User $user */ + $user = $this->getUser(); + $watchList->setUser($user); $this->em->persist($watchList); $this->em->flush(); @@ -86,12 +88,13 @@ class WatchListController extends AbstractController /** @var DomainEntity $entity */ foreach ($domain->getDomainEntities()->toArray() as $entity) { $vCard = Reader::readJson($entity->getEntity()->getJCard()); - $email = (string) $vCard->EMAIL; - if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { - continue; + if (isset($vCard->EMAIL) && isset($vCard->FN)) { + $email = (string) $vCard->EMAIL; + if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { + continue; + } + $attendees[] = (new Attendee(new EmailAddress($email)))->setDisplayName((string) $vCard->FN); } - - $attendees[] = (new Attendee(new EmailAddress($email)))->setDisplayName((string) $vCard->FN); } /** @var DomainEvent $event */ diff --git a/src/Entity/User.php b/src/Entity/User.php index 489cf34..79acc08 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -111,9 +111,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return array_unique($roles); } - /** - * @return User - */ public function setRoles(array $roles): static { $this->roles = $roles; diff --git a/src/Service/RDAPService.php b/src/Service/RDAPService.php index 4e64602..fda5376 100644 --- a/src/Service/RDAPService.php +++ b/src/Service/RDAPService.php @@ -102,7 +102,7 @@ readonly class RDAPService ->filter(fn (DomainEvent $e) => $e->getDate() <= new \DateTimeImmutable('now')) ->toArray(); - usort($events, fn (DomainEvent $e1, DomainEvent $e2) => $e2->getDate() > $e1->getDate()); + usort($events, fn (DomainEvent $e1, DomainEvent $e2) => $e2->getDate() <=> $e1->getDate()); return !empty($events) && in_array($events[0]->getAction(), self::IMPORTANT_EVENTS); } diff --git a/symfony.lock b/symfony.lock index 7978ecc..e266829 100644 --- a/symfony.lock +++ b/symfony.lock @@ -88,6 +88,18 @@ "config/packages/nelmio_cors.yaml" ] }, + "phpstan/phpstan": { + "version": "1.11", + "recipe": { + "repo": "github.com/symfony/recipes-contrib", + "branch": "main", + "version": "1.0", + "ref": "5e490cc197fb6bb1ae22e5abbc531ddc633b6767" + }, + "files": [ + "phpstan.dist.neon" + ] + }, "phpunit/phpunit": { "version": "9.6", "recipe": {