Browse Source

fix phpstan errors

Olivier Massot 9 tháng trước cách đây
mục cha
commit
5fb1bf8380

+ 1 - 0
phpstan.neon.dist

@@ -10,4 +10,5 @@ parameters:
     ignoreErrors :
         - '#Attribute class JetBrains\\PhpStorm\\[a-zA-Z]+ does not exist.#'
         - identifier: 'missingType.generics'
+        - '#Property .+::\$id \(int\|null\) is never assigned int so it can be removed from the property type\.$#'
 

+ 5 - 7
src/Entity/Education/EducationNotation.php

@@ -46,9 +46,10 @@ class EducationNotation
     #[ORM\InverseJoinColumn(name: 'tag_id', referencedColumnName: 'id')]
     private Collection $tags;
 
+    // @see https://github.com/symfony/symfony/discussions/43599#discussioncomment-1514811
     #[ORM\Column(type: 'decimal', precision: 10, scale: 2, nullable: true)]
     #[Assert\Range(notInRangeMessage: 'between_{{ min }}_and_{{ max }}', min: 0, max: 100)]
-    private ?float $note = null;
+    private ?string $note = null;
 
     public function __construct()
     {
@@ -122,17 +123,14 @@ class EducationNotation
 
     public function setNote(?float $note): self
     {
-        $this->note = !is_null($note) ? (float) $note : $note;
+        $this->note = (string)$note;
 
         return $this;
     }
 
     public function getNote(): ?float
     {
-        if (is_null($this->note)) {
-            return $this->note;
-        }
-
-        return round($this->note, 2);
+        // TODO: pour moi le round il est pas à sa place ici? vaudrait pas mieux le mettre dans le setter?
+        return !is_null($this->note) ? round((float)$this->note, 2) : null;
     }
 }

+ 0 - 6
src/Entity/Organization/OnlineRegistrationOpeningPeriod.php

@@ -32,12 +32,6 @@ class OnlineRegistrationOpeningPeriod
         return $this->id;
     }
 
-    public function setId(?int $id): self
-    {
-        $this->id = $id;
-        return $this;
-    }
-
     public function getOnlineRegistrationSettings(): ?OnlineRegistrationSettings
     {
         return $this->onlineRegistrationSettings;

+ 1 - 0
src/EventListener/Helper.php

@@ -8,6 +8,7 @@ use Doctrine\ORM\EntityManagerInterface;
 
 /**
  * Trait Helper qui met à disposition des fonctions d'aide pour les EventListeners.
+ * @phpstan-ignore-next-line le fait que le trait ne soit utilisé nulle part lève une erreur (2025-02)
  */
 trait Helper
 {

+ 1 - 0
src/EventListener/JWT/AuthenticationSuccessListener.php

@@ -20,6 +20,7 @@ class AuthenticationSuccessListener
         $data = $event->getData();
         $user = $event->getUser();
 
+        // @phpstan-ignore-next-line c'est possible ce cas où $user ne serait pas une instance de UserInterface?
         if (!$user instanceof UserInterface) {
             return;
         }

+ 6 - 4
src/Repository/Person/PersonRepository.php

@@ -27,15 +27,17 @@ class PersonRepository extends ServiceEntityRepository implements PasswordUpgrad
     /**
      * Used to upgrade (rehash) the user's password automatically over time.
      */
-    public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newEncodedPassword): void
+    public function upgradePassword(PasswordAuthenticatedUserInterface $user, string $newHashedPassword): void
     {
         if (!$user instanceof Person) {
             throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', \get_class($user)));
         }
 
-        $user->setPassword($newEncodedPassword);
-        $this->_em->persist($user);
-        $this->_em->flush();
+        $em = $this->getEntityManager();
+
+        $user->setPassword($newHashedPassword);
+        $em->persist($user);
+        $em->flush();
     }
 
     public function findOneByUsername(string $username): ?Person

+ 1 - 0
src/Security/Voter/EntityVoter/AbstractEntityVoter.php

@@ -29,6 +29,7 @@ abstract class AbstractEntityVoter extends Voter
      * The current user if any; access it trough isUserLoggedIn or getUser methods
      * If the current user is null, it has not been fetched already
      * If it is false, there is no user logged in.
+     * @phpstan-ignore-next-line faux positif
      */
     private Access|false|null $user = null;
 

+ 0 - 3
src/Security/Voter/ModuleVoter.php

@@ -33,9 +33,6 @@ class ModuleVoter extends Voter
         return true;
     }
 
-    /**
-     * @throws \ApiPlatform\Exception\ResourceClassNotFoundException
-     */
     protected function voteOnAttribute(string $attribute, $subject, TokenInterface $token): bool
     {
         if (!$subject->attributes->get('_api_resource_class')) {

+ 2 - 2
src/Service/Dolibarr/DolibarrApiService.php

@@ -7,10 +7,10 @@ namespace App\Service\Dolibarr;
 use App\Entity\Organization\Organization;
 use App\Service\Rest\ApiRequestService;
 use JetBrains\PhpStorm\Pure;
-use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\HttpKernel\Exception\HttpException;
 use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
 use Symfony\Contracts\HttpClient\HttpClientInterface;
+use Symfony\Contracts\HttpClient\ResponseInterface;
 
 /**
  * Service d'appel à l'API dolibarr.
@@ -195,7 +195,7 @@ class DolibarrApiService extends ApiRequestService
             'array_options' => ['options_2iopen_organization_id' => $organization->getId()],
         ];
 
-        /** @var Response $response */
+        /** @var ResponseInterface $response */
         $response = $this->post('/thirdparties', $body);
 
         return json_decode($response->getContent(), true);

+ 2 - 2
src/Service/File/FileManager.php

@@ -4,9 +4,9 @@ declare(strict_types=1);
 
 namespace App\Service\File;
 
-use ApiPlatform\Api\IriConverterInterface;
-use ApiPlatform\Api\UrlGeneratorInterface as UrlGeneratorInterfaceApiPlatform;
+use ApiPlatform\Metadata\UrlGeneratorInterface as UrlGeneratorInterfaceApiPlatform;
 use ApiPlatform\Metadata\Get;
+use ApiPlatform\Metadata\IriConverterInterface;
 use App\Entity\Access\Access;
 use App\Entity\Core\File;
 use App\Entity\Organization\Organization;

+ 1 - 1
src/Service/File/Storage/LocalStorage.php

@@ -364,7 +364,7 @@ class LocalStorage implements FileStorageInterface
     /**
      * Return an array [$organization, $person] from a given owner.
      *
-     * @return list<Organization|Person>
+     * @return list<Organization|Person|null>
      */
     #[Pure]
     protected function getOrganizationAndPersonFromOwner(Organization|Access|Person $owner): array

+ 1 - 1
src/Service/MercureHub.php

@@ -4,7 +4,7 @@ declare(strict_types=1);
 
 namespace App\Service;
 
-use ApiPlatform\Api\IriConverterInterface;
+use ApiPlatform\Metadata\IriConverterInterface;
 use Symfony\Component\Mercure\HubInterface;
 use Symfony\Component\Mercure\Update;
 use Symfony\Component\Serializer\Encoder\EncoderInterface;

+ 1 - 1
src/State/Provider/Access/AccessProfileProvider.php

@@ -31,7 +31,7 @@ final class AccessProfileProvider implements ProviderInterface
      *
      * @throws \Exception
      */
-    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?AccessProfile
+    public function provide(Operation $operation, array $uriVariables = [], array $context = []): AccessProfile
     {
         if ($operation instanceof GetCollection) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);

+ 1 - 1
src/State/Provider/Cotisation/CotisationProvider.php

@@ -24,7 +24,7 @@ final class CotisationProvider implements ProviderInterface
      * @param mixed[] $uriVariables
      * @param mixed[] $context
      */
-    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Cotisation
+    public function provide(Operation $operation, array $uriVariables = [], array $context = []): Cotisation
     {
         if ($operation instanceof GetCollection) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);

+ 1 - 1
src/State/Provider/Dolibarr/DolibarrAccountProvider.php

@@ -25,7 +25,7 @@ final class DolibarrAccountProvider implements ProviderInterface
      * @param mixed[] $uriVariables
      * @param mixed[] $context
      */
-    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?DolibarrAccount
+    public function provide(Operation $operation, array $uriVariables = [], array $context = []): DolibarrAccount
     {
         if ($operation instanceof GetCollection) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);

+ 1 - 1
src/State/Provider/Enum/EnumProvider.php

@@ -26,7 +26,7 @@ final class EnumProvider implements ProviderInterface
      * @param mixed[] $uriVariables
      * @param mixed[] $context
      */
-    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Enum
+    public function provide(Operation $operation, array $uriVariables = [], array $context = []): Enum
     {
         if ($operation instanceof GetCollection) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);

+ 1 - 1
src/State/Provider/Mobyt/MobytUserStatusProvider.php

@@ -27,7 +27,7 @@ final class MobytUserStatusProvider implements ProviderInterface
      *
      * @throws \JsonException
      */
-    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?MobytUserStatus
+    public function provide(Operation $operation, array $uriVariables = [], array $context = []): MobytUserStatus
     {
         if ($operation instanceof GetCollection) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);

+ 1 - 1
src/State/Provider/Organization/Subdomain/SubdomainAvailabilityProvider.php

@@ -26,7 +26,7 @@ final class SubdomainAvailabilityProvider implements ProviderInterface
      *
      * @throws FileNotFoundException
      */
-    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?SubdomainAvailability
+    public function provide(Operation $operation, array $uriVariables = [], array $context = []): SubdomainAvailability
     {
         if ($operation instanceof GetCollection) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);

+ 1 - 1
src/State/Provider/Utils/SiretProvider.php

@@ -34,7 +34,7 @@ final class SiretProvider implements ProviderInterface
      * @throws ServerExceptionInterface
      * @throws TransportExceptionInterface
      */
-    public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?Siret
+    public function provide(Operation $operation, array $uriVariables = [], array $context = []): Siret
     {
         if ($operation instanceof GetCollection) {
             throw new \RuntimeException('not supported', Response::HTTP_METHOD_NOT_ALLOWED);