Skip to content

Commit

Permalink
Passage au niveau 2 de PHPStan
Browse files Browse the repository at this point in the history
  • Loading branch information
Mopolo committed Jan 9, 2025
1 parent 6fde26f commit 292b8e9
Show file tree
Hide file tree
Showing 19 changed files with 76 additions and 39 deletions.
6 changes: 5 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
parameters:
phpVersion: 70400 # PHP 7.4
level: 1
level: 2
paths:
- sources
scanFiles:
Expand All @@ -15,6 +15,10 @@ parameters:
- sources/AppBundle/Twig/AssetsExtension.php
- sources/AppBundle/Twig/TwigExtension.php

stubFiles:
- tests/stubs/Ting/Repository/Repository.php.stub
- tests/stubs/Ting/Repository/RepositoryFactory.php.stub

ignoreErrors:
-
message: '#^Method AppBundle\\Controller\\SiteBaseController\:\:render\(\) overrides @final method Symfony\\Bundle\\FrameworkBundle\\Controller\\Controller\:\:render\(\)\.$#'
Expand Down
2 changes: 1 addition & 1 deletion sources/Afup/Association/Cotisations.php
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ function obtenirDateDebut($type_personne, $id_personne)

/**
* @param array $cotisation from Afup_Personnes_Physiques::obtenirDerniereCotisation
* @return DateTime: Date of end of next subscription
* @return DateTime Date of end of next subscription
*/
public function finProchaineCotisation($cotisation)
{
Expand Down
4 changes: 2 additions & 2 deletions sources/Afup/Forum/Forum.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ function dureeSeance($heures)
$aHeures = explode("-", $heures);
$aDebut = explode(":", $aHeures[0]);
$aFin = explode(":", $aHeures[1]);
$iDebut = ($aDebut[0] * 60) + $aDebut[1];
$iFin = ($aFin[0] * 60) + $aFin[1];
$iDebut = ((int)$aDebut[0] * 60) + (int)$aDebut[1];
$iFin = ((int)$aFin[0] * 60) + (int)$aFin[1];
$duree = ($iFin - $iDebut) / 5;
return $duree;
}
Expand Down
4 changes: 2 additions & 2 deletions sources/AppBundle/Association/Form/UserEditFormData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class UserEditFormData
{
public $companyId;
/**
* @var Assert\NotBlank()
* @var Assert\Choice(choices={"M.", "Mme"}, strict=true)
* @Assert\NotBlank()
* @Assert\Choice(choices={"M.", "Mme"}, strict=true)
*/
public $civility = 'M.';
/**
Expand Down
16 changes: 8 additions & 8 deletions sources/AppBundle/Association/Model/GeneralMeetingQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,7 @@ public function setCreatedAt(\DateTime $createdAt)
return $this;
}

/**
* @return string
*/
public function getStatus()
public function getStatus(): string
{
if (null !== $this->getClosedAt()) {
return self::STATUS_CLOSED;
Expand All @@ -179,22 +176,25 @@ public function getStatus()
return self::STATUS_WAITING;
}

public function hasStatusWaiting()
public function hasStatusWaiting(): bool
{
return self::STATUS_WAITING === $this->getStatus();
}

public function hasStatusOpened()
public function hasStatusOpened(): bool
{
return self::STATUS_OPENED === $this->getStatus();
}

public function hasStatusClosed()
public function hasStatusClosed(): bool
{
return self::STATUS_CLOSED === $this->getStatus();
}

public function hasVotes($results)
/**
* @param array<string, int> $results
*/
public function hasVotes(array $results): bool
{
return 0 > $results[GeneralMeetingVote::VALUE_YES] + $results[GeneralMeetingVote::VALUE_NO] + $results[GeneralMeetingVote::VALUE_ABSTENTION];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public function loadNextOpenedQuestion(\DateTimeInterface $generalMeetingDate)
return $collection->first();
}

/**
* @return iterable<GeneralMeetingQuestion>
*/
public function loadClosedQuestions(\DateTimeInterface $generalMeetingDate)
{
$sql = <<<SQL
Expand All @@ -61,14 +64,16 @@ public function loadClosedQuestions(\DateTimeInterface $generalMeetingDate)
'general_meeting_date' => $generalMeetingDate->format('U'),
];

/** @var iterable<GeneralMeetingQuestion> */
return $this->getPreparedQuery($sql)->setParams($params)->query($this->getCollection(new HydratorSingleObject()));
}

/**
* @return \CCMBenchmark\Ting\Repository\CollectionInterface
* @return iterable<GeneralMeetingQuestion>
*/
public function loadByDate(\DateTimeInterface $generalMeetingDate)
{
/** @var iterable<GeneralMeetingQuestion> */
return $this->getBy([
'date' => $generalMeetingDate->format('U'),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ public function loadByQuestionIdAndUserId($questionId, $userId)
]);
}

public function getResultsForQuestionId($questionId)
/**
* @return array<string, int>
*/
public function getResultsForQuestionId(int $questionId): array
{
$results = [
GeneralMeetingVote::VALUE_YES => 0,
Expand Down
7 changes: 5 additions & 2 deletions sources/AppBundle/Command/QrCodesGeneratorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

$io->progressStart(count($tickets));
foreach ($tickets as $ticket) {
if (null !== ($inscriptionIdMin = $input->getOption('inscription-id-min')) && $inscriptionIdMin > $ticket->getId()) {
$inscriptionIdMin = (int) $input->getOption('inscription-id-min');
$inscriptionIdMax = (int) $input->getOption('inscription-id-max');

if ($inscriptionIdMin > $ticket->getId()) {
continue;
}

if (null !== ($inscriptionIdMax = $input->getOption('inscription-id-max')) && $inscriptionIdMax < $ticket->getId()) {
if ($inscriptionIdMax < $ticket->getId()) {
continue;
}

Expand Down
3 changes: 2 additions & 1 deletion sources/AppBundle/Controller/Admin/Event/ListAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AppBundle\Event\Model\Repository\EventRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Twig\Environment;

Expand All @@ -19,7 +20,7 @@ class ListAction
*/
private $twig;
/**
* @var SessionInterface
* @var SessionInterface&Session
*/
private $session;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function __invoke(Request $request): Response
// add
$form = $this->buildForm();
if ($form->handleRequest($request) && $form->isValid()) {
/** @var UploadedFile $uploadedFile */
/** @var UploadedFile $reportFile */
$reportFile = $form->get('file')->getData();
if ($reportFile->move($basePath, $reportFile->getClientOriginalName())) {
$this->flashBag->add('notice', 'Le compte rendu a correctement été ajouté.');
Expand Down
6 changes: 4 additions & 2 deletions sources/AppBundle/Controller/MemberShipController.php
Original file line number Diff line number Diff line change
Expand Up @@ -651,8 +651,10 @@ public function generalMeetingVoteAction(Request $request)
throw $this->createNotFoundException('Vote manquant');
}

/** @var $question GeneralMeetingQuestion */
if (null === ($question = $generalMeetingQuestionRepository->get($questionId))) {
/** @var GeneralMeetingQuestion $question */
$question = $generalMeetingQuestionRepository->get($questionId);

if (null === $question) {
throw $this->createNotFoundException('QuestionId missing');
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use CCMBenchmark\Ting\Repository\Repository;
use CCMBenchmark\Ting\Serializer\SerializerFactoryInterface;

/**
* @extends Repository<Speaker>
*/
class SpeakerRepository extends Repository implements MetadataInitializer
{
/**
Expand Down
2 changes: 1 addition & 1 deletion sources/AppBundle/Event/Model/Speaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public function getPhotoFile()
* @param UploadedFile|null $photoFile
* @return Speaker
*/
public function setPhotoFile(UploadedFile $photoFile)
public function setPhotoFile(?UploadedFile $photoFile)
{
$this->photoFile = $photoFile;
return $this;
Expand Down
6 changes: 5 additions & 1 deletion sources/AppBundle/Security/LegacyAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use AppBundle\Association\Model\User;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down Expand Up @@ -74,7 +76,9 @@ public function checkCredentials($credentials, UserInterface $user)
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$request->getSession()->getFlashBag()->add('error', "Utilisateur et/ou mot de passe incorrect");
/** @var SessionInterface&Session $session */
$session = $request->getSession();
$session->getFlashBag()->add('error', "Utilisateur et/ou mot de passe incorrect");

return null;
}
Expand Down
6 changes: 5 additions & 1 deletion sources/AppBundle/Security/LegacyHashAuthenticator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down Expand Up @@ -66,7 +68,9 @@ public function checkCredentials($credentials, UserInterface $user)
*/
public function onAuthenticationFailure(Request $request, AuthenticationException $exception)
{
$request->getSession()->getFlashBag()->add('error', "Utilisateur et/ou mot de passe incorrect");
/** @var SessionInterface&Session $session */
$session = $request->getSession();
$session->getFlashBag()->add('error', "Utilisateur et/ou mot de passe incorrect");

return null;
}
Expand Down
4 changes: 0 additions & 4 deletions sources/AppBundle/Security/TalkVoter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

use AppBundle\Event\Model\GithubUser;
use AppBundle\Event\Model\Repository\SpeakerRepository;
use AppBundle\Event\Model\Speaker;
use AppBundle\Event\Model\Talk;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Authorization\Voter\Voter;
Expand Down Expand Up @@ -48,9 +47,6 @@ protected function voteOnAttribute($attribute, $subject, TokenInterface $token)

// All speakers associated to a talk can edit the talk
foreach ($speakers as $speaker) {
/**
* @var $speaker Speaker
*/
if ($speaker->getUser() === $user->getId()) {
return true;
}
Expand Down
11 changes: 1 addition & 10 deletions sources/AppBundle/TechLetter/HtmlParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class HtmlParser
private $dom;

/**
* @var \DOMNodeList
* @var \DOMNodeList&iterable<\DOMElement>
*/
private $meta;

Expand Down Expand Up @@ -57,9 +57,6 @@ private function getSocialMeta($meta)
private function getOpenGraphMeta($property)
{
foreach ($this->meta as $meta) {
/**
* @var $meta \DOMElement
*/
if ($meta->hasAttribute('property') === true) {
if ($meta->getAttribute('property') === self::OPEN_GRAPH_PREFIX . ':' . $property) {
return $meta->getAttribute('content');
Expand All @@ -72,9 +69,6 @@ private function getOpenGraphMeta($property)
private function getTwitterMeta($name)
{
foreach ($this->meta as $meta) {
/**
* @var $meta \DOMElement
*/
if ($meta->hasAttribute('name') === true) {
if ($meta->getAttribute('name') === self::TWITTER_PREFIX . ':' . $name) {
return $meta->getAttribute('content');
Expand All @@ -91,9 +85,6 @@ private function getTwitterMeta($name)
private function getStandardMeta($name)
{
foreach ($this->meta as $meta) {
/**
* @var $meta \DOMElement
*/
if ($meta->hasAttribute('name') === true) {
if ($meta->getAttribute('name') === $name) {
return $meta->getAttribute('content');
Expand Down
7 changes: 7 additions & 0 deletions tests/stubs/Ting/Repository/Repository.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?php
namespace CCMBenchmark\Ting\Repository;

/**
* @template T
*/
abstract class Repository {}
14 changes: 14 additions & 0 deletions tests/stubs/Ting/Repository/RepositoryFactory.php.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace CCMBenchmark\Ting\Repository;

class RepositoryFactory
{
/**
* @param class-string<R> $repositoryName
* @return R
* @template T of object
* @template R of Repository<T>
*/
public function get($repositoryName) {}
}

0 comments on commit 292b8e9

Please sign in to comment.