DX: fix phpstan errors

This commit is contained in:
Julien Fastré 2023-02-04 00:50:58 +01:00
parent a01cc23c14
commit 856eea37ee
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB
16 changed files with 94 additions and 120 deletions

View File

@ -400,16 +400,6 @@ parameters:
count: 1 count: 1
path: src/Bundle/ChillTaskBundle/Timeline/TaskLifeCycleEventTimelineProvider.php path: src/Bundle/ChillTaskBundle/Timeline/TaskLifeCycleEventTimelineProvider.php
-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: src/Bundle/ChillThirdPartyBundle/Form/ChoiceLoader/ThirdPartyChoiceLoader.php
-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: src/Bundle/ChillThirdPartyBundle/Repository/ThirdPartyRepository.php
- -
message: "#^Method Chill\\\\ThirdPartyBundle\\\\Search\\\\ThirdPartySearch\\:\\:renderResult\\(\\) should return string but return statement is missing\\.$#" message: "#^Method Chill\\\\ThirdPartyBundle\\\\Search\\\\ThirdPartySearch\\:\\:renderResult\\(\\) should return string but return statement is missing\\.$#"
count: 1 count: 1

View File

@ -2,6 +2,7 @@ parameters:
level: 1 level: 1
paths: paths:
- src/ - src/
reportUnmatchedIgnoredErrors: false
excludePaths: excludePaths:
- .php_cs* - .php_cs*
- docs/ - docs/

View File

@ -11,12 +11,12 @@ declare(strict_types=1);
namespace Chill\AsideActivityBundle\Export\Export; namespace Chill\AsideActivityBundle\Export\Export;
use Chill\AsideActivityBundle\Export\Declarations;
use Chill\AsideActivityBundle\Repository\AsideActivityRepository; use Chill\AsideActivityBundle\Repository\AsideActivityRepository;
use Chill\AsideActivityBundle\Security\AsideActivityVoter; use Chill\AsideActivityBundle\Security\AsideActivityVoter;
use Chill\MainBundle\Export\ExportInterface; use Chill\MainBundle\Export\ExportInterface;
use Chill\MainBundle\Export\FormatterInterface; use Chill\MainBundle\Export\FormatterInterface;
use Chill\MainBundle\Export\GroupedExportInterface; use Chill\MainBundle\Export\GroupedExportInterface;
use ChillAsideActivityBundle\Export\Declarations;
use Doctrine\ORM\Query; use Doctrine\ORM\Query;
use LogicException; use LogicException;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;

View File

@ -145,6 +145,9 @@ class CalendarDocController
$returnParams = ['id' => $calendarDoc->getCalendar()->getPerson()->getId()]; $returnParams = ['id' => $calendarDoc->getCalendar()->getPerson()->getId()];
break; break;
default:
throw new \LogicException(sprintf("This context '%s' is not supported", $calendarDoc->getCalendar()->getContext()));
} }
$form = $this->formFactory->createBuilder() $form = $this->formFactory->createBuilder()

View File

@ -197,7 +197,7 @@ class Participation implements ArrayAccess, HasCenterInterface, HasScopeInterfac
* *
* @return bool * @return bool
*/ */
public function offsetExists($offset) public function offsetExists($offset): bool
{ {
return in_array($offset, [ return in_array($offset, [
'person', 'role', 'status', 'event', 'person', 'role', 'status', 'event',
@ -207,30 +207,21 @@ class Participation implements ArrayAccess, HasCenterInterface, HasScopeInterfac
/** /**
* @param mixed $offset * @param mixed $offset
* *
* @return Event|mixed|Person|Role|Status * @return Event|Person|Role|Status
*/ */
public function offsetGet($offset) public function offsetGet($offset): mixed
{ {
switch ($offset) { switch ($offset) {
case 'person': case 'person':
return $this->getPerson(); return $this->getPerson();
break;
case 'role': case 'role':
return $this->getRole(); return $this->getRole();
break;
case 'status': case 'status':
return $this->getStatus(); return $this->getStatus();
break;
case 'event': case 'event':
return $this->getEvent(); return $this->getEvent();
default:
break; throw new \LogicException("this offset does not exists : " . $offset);
} }
} }
@ -238,28 +229,28 @@ class Participation implements ArrayAccess, HasCenterInterface, HasScopeInterfac
* @param mixed $offset * @param mixed $offset
* @param mixed $value * @param mixed $value
* *
* @return Participation|void * @return void
*/ */
public function offsetSet($offset, $value) public function offsetSet($offset, $value): void
{ {
switch ($offset) { switch ($offset) {
case 'person': case 'person':
return $this->setPerson($value); $this->setPerson($value);
break; break;
case 'role': case 'role':
return $this->setRole($value); $this->setRole($value);
break; break;
case 'status': case 'status':
return $this->setStatus($value); $this->setStatus($value);
break; break;
case 'event': case 'event':
return $this->setEvent($value); $this->setEvent($value);
break; break;
} }
@ -268,7 +259,7 @@ class Participation implements ArrayAccess, HasCenterInterface, HasScopeInterfac
/** /**
* @param mixed $offset * @param mixed $offset
*/ */
public function offsetUnset($offset) public function offsetUnset($offset): void
{ {
$this->offsetSet($offset, null); $this->offsetSet($offset, null);
} }

View File

@ -21,37 +21,36 @@ class Page implements PageInterface
/** /**
* the number of item per page. * the number of item per page.
* *
* @var int
*/ */
protected $itemPerPage; protected int $itemPerPage;
/** /**
* the number of the current page. * the number of the current page.
* *
* @var int * @var int
*/ */
protected $number; protected int $number;
/** /**
* The route for the current page. * The route for the current page.
* *
* @var string * @var string
*/ */
protected $route; protected string $route;
/** /**
* Parameters for the route to the current page. * Parameters for the route to the current page.
* *
* @var array * @var array
*/ */
protected $routeParameters; protected array $routeParameters;
/** /**
* The number of items in the whole iteration. * The number of items in the whole iteration.
* *
* @var int * @var int
*/ */
protected $totalItems; protected int $totalItems;
/** /**
* @var UrlGeneratorInterface * @var UrlGeneratorInterface
@ -59,12 +58,12 @@ class Page implements PageInterface
protected $urlGenerator; protected $urlGenerator;
public function __construct( public function __construct(
$number, int $number,
$itemPerPage, int $itemPerPage,
UrlGeneratorInterface $urlGenerator, UrlGeneratorInterface $urlGenerator,
$route, string $route,
array $routeParameters, array $routeParameters,
$totalItems int $totalItems
) { ) {
$this->urlGenerator = $urlGenerator; $this->urlGenerator = $urlGenerator;
$this->number = $number; $this->number = $number;
@ -74,24 +73,24 @@ class Page implements PageInterface
$this->totalItems = $totalItems; $this->totalItems = $totalItems;
} }
public function generateUrl() public function generateUrl(): string
{ {
return $this->urlGenerator->generate($this->route, $this->routeParameters); return $this->urlGenerator->generate($this->route, $this->routeParameters);
} }
public function getFirstItemNumber() public function getFirstItemNumber(): int
{ {
return ($this->number - 1) * $this->itemPerPage; return ($this->number - 1) * $this->itemPerPage;
} }
public function getLastItemNumber() public function getLastItemNumber(): int
{ {
$last = $this->number * $this->itemPerPage - 1; $last = $this->number * $this->itemPerPage - 1;
return $last < $this->totalItems ? $last : $this->totalItems; return $last < $this->totalItems ? $last : $this->totalItems;
} }
public function getNumber() public function getNumber(): int
{ {
return $this->number; return $this->number;
} }

View File

@ -27,27 +27,27 @@ class PageGenerator implements Iterator
$this->paginator = $paginator; $this->paginator = $paginator;
} }
public function current() public function current(): Page
{ {
return $this->paginator->getPage($current); return $this->paginator->getPage($this->current);
} }
public function key() public function key(): int
{ {
return $this->current; return $this->current;
} }
public function next() public function next(): void
{ {
++$this->current; ++$this->current;
} }
public function rewind() public function rewind(): void
{ {
$this->current = 1; $this->current = 1;
} }
public function valid() public function valid(): bool
{ {
return 0 < $this->current return 0 < $this->current
&& $this->paginator->countPages() >= $this->current; && $this->paginator->countPages() >= $this->current;

View File

@ -26,21 +26,21 @@ class Paginator implements PaginatorInterface
* *
* @var int * @var int
*/ */
protected $currentPageNumber; protected int $currentPageNumber;
/** /**
* the number of items on a single page. * the number of items on a single page.
* *
* @var int * @var int
*/ */
protected $itemPerPage; protected int $itemPerPage;
/** /**
* the key in the GET parameter to indicate the number of item per page. * the key in the GET parameter to indicate the number of item per page.
* *
* @var string * @var string
*/ */
protected $itemPerPageKey; protected string $itemPerPageKey;
/** /**
* the key in the GET parameter to indicate the page number in * the key in the GET parameter to indicate the page number in
@ -48,45 +48,45 @@ class Paginator implements PaginatorInterface
* *
* @var string * @var string
*/ */
protected $pageKey; protected string $pageKey;
/** /**
* the route of the pages. * the route of the pages.
* *
* @var string * @var string
*/ */
protected $route; protected string $route;
/** /**
* the parameters of the route. * the parameters of the route.
* *
* @var string[] * @var string[]
*/ */
protected $routeParameters; protected array $routeParameters;
/** /**
* The number of total items. * The number of total items.
* *
* @var int * @var int
*/ */
protected $totalItems; protected int $totalItems;
/** /**
* the generator for url. * the generator for url.
* *
* @var UrlGeneratorInterface * @var UrlGeneratorInterface
*/ */
protected $urlGenerator; protected UrlGeneratorInterface $urlGenerator;
public function __construct( public function __construct(
$totalItems, int $totalItems,
$itemPerPage, int $itemPerPage,
$currentPageNumber, int $currentPageNumber,
$route, string $route,
array $routeParameters, array $routeParameters,
UrlGeneratorInterface $urlGenerator, UrlGeneratorInterface $urlGenerator,
$pageKey, string $pageKey,
$itemPerPageKey string $itemPerPageKey
) { ) {
$this->totalItems = $totalItems; $this->totalItems = $totalItems;
$this->itemPerPage = $itemPerPage; $this->itemPerPage = $itemPerPage;
@ -98,12 +98,12 @@ class Paginator implements PaginatorInterface
$this->itemPerPageKey = $itemPerPageKey; $this->itemPerPageKey = $itemPerPageKey;
} }
public function count() public function count(): int
{ {
return $this->countPages(); return $this->countPages();
} }
public function countPages() public function countPages(): int
{ {
if (0 === $this->itemPerPage) { if (0 === $this->itemPerPage) {
return 1; return 1;
@ -122,20 +122,17 @@ class Paginator implements PaginatorInterface
return 0 === $nb ? 1 : (int) $nb; return 0 === $nb ? 1 : (int) $nb;
} }
/** public function getCurrentPage(): Page
* @return \Chill\MainBundle\Pagination\Page
*/
public function getCurrentPage()
{ {
return $this->getPage($this->currentPageNumber); return $this->getPage($this->currentPageNumber);
} }
public function getCurrentPageFirstItemNumber() public function getCurrentPageFirstItemNumber(): int
{ {
return $this->getCurrentPage()->getFirstItemNumber(); return $this->getCurrentPage()->getFirstItemNumber();
} }
public function getItemsPerPage() public function getItemsPerPage(): int
{ {
return $this->itemPerPage; return $this->itemPerPage;
} }
@ -145,7 +142,7 @@ class Paginator implements PaginatorInterface
* *
* @return \Chill\MainBundle\Pagination\Page * @return \Chill\MainBundle\Pagination\Page
*/ */
public function getNextPage() public function getNextPage(): Page
{ {
if (!$this->hasNextPage()) { if (!$this->hasNextPage()) {
throw new RuntimeException('this page has no next page'); throw new RuntimeException('this page has no next page');
@ -155,11 +152,10 @@ class Paginator implements PaginatorInterface
} }
/** /**
* @param type $number
* *
* @return \Chill\MainBundle\Pagination\Page * @return \Chill\MainBundle\Pagination\Page
*/ */
public function getPage($number) public function getPage(int $number): Page
{ {
if (!$this->hasPage($number)) { if (!$this->hasPage($number)) {
throw new RuntimeException("The page with number {$number} does not " throw new RuntimeException("The page with number {$number} does not "
@ -179,7 +175,7 @@ class Paginator implements PaginatorInterface
); );
} }
public function getPagesGenerator() public function getPagesGenerator(): iterable
{ {
for ($i = 1; $this->countPages() >= $i; ++$i) { for ($i = 1; $this->countPages() >= $i; ++$i) {
yield $this->getPage($i); yield $this->getPage($i);
@ -191,7 +187,7 @@ class Paginator implements PaginatorInterface
* *
* @return \Chill\MainBundle\Pagination\Page * @return \Chill\MainBundle\Pagination\Page
*/ */
public function getPreviousPage() public function getPreviousPage(): PageInterface
{ {
if (!$this->hasPreviousPage()) { if (!$this->hasPreviousPage()) {
throw new RuntimeException('this page has no previous page'); throw new RuntimeException('this page has no previous page');
@ -200,7 +196,7 @@ class Paginator implements PaginatorInterface
return $this->getPage($this->currentPageNumber - 1); return $this->getPage($this->currentPageNumber - 1);
} }
public function getTotalItems() public function getTotalItems(): int
{ {
return $this->totalItems; return $this->totalItems;
} }
@ -208,12 +204,12 @@ class Paginator implements PaginatorInterface
/** /**
* @return bool * @return bool
*/ */
public function hasNextPage() public function hasNextPage(): bool
{ {
return $this->hasPage($this->currentPageNumber + 1); return $this->hasPage($this->currentPageNumber + 1);
} }
public function hasPage($number) public function hasPage($number): bool
{ {
if (0 === $this->totalItems) { if (0 === $this->totalItems) {
return 1 === $number; return 1 === $number;
@ -226,18 +222,18 @@ class Paginator implements PaginatorInterface
/** /**
* @return bool * @return bool
*/ */
public function hasPreviousPage() public function hasPreviousPage(): bool
{ {
return $this->hasPage($this->currentPageNumber - 1); return $this->hasPage($this->currentPageNumber - 1);
} }
public function isCurrentPage(PageInterface $page) public function isCurrentPage(PageInterface $page): bool
{ {
return $page->getNumber() === $this->currentPageNumber; return $page->getNumber() === $this->currentPageNumber;
} }
public function setItemsPerPage($itemPerPage) public function setItemsPerPage(int $itemsPerPage)
{ {
$this->itemPerPage = $itemPerPage; $this->itemPerPage = $itemsPerPage;
} }
} }

View File

@ -32,26 +32,26 @@ interface PaginatorInterface extends Countable
* *
* @return int * @return int
*/ */
public function countPages(); public function countPages(): int;
/** /**
* get the current page. * get the current page.
* *
* @return PageInterface * @return PageInterface
*/ */
public function getCurrentPage(); public function getCurrentPage(): PageInterface;
/** /**
* get the first result for the current page. * get the first result for the current page.
* *
* @return int * @return int
*/ */
public function getCurrentPageFirstItemNumber(); public function getCurrentPageFirstItemNumber(): int;
/* /*
* get the number of items per page * get the number of items per page
*/ */
public function getItemsPerPage(); public function getItemsPerPage(): int;
/** /**
* get the next page. * get the next page.
@ -60,7 +60,7 @@ interface PaginatorInterface extends Countable
* *
* @return PageInterface * @return PageInterface
*/ */
public function getNextPage(); public function getNextPage(): PageInterface;
/** /**
* get page by his number. * get page by his number.
@ -69,14 +69,14 @@ interface PaginatorInterface extends Countable
* *
* @throws RuntimeException if the pagination has no page with specified number * @throws RuntimeException if the pagination has no page with specified number
*/ */
public function getPage($number); public function getPage(int $number): PageInterface;
/** /**
* get a generator to generate pages. * get a generator to generate pages.
* *
* @return Generator which return PageInterface elements * @return Generator which return PageInterface elements
*/ */
public function getPagesGenerator(); public function getPagesGenerator(): iterable;
/** /**
* get the previous page. * get the previous page.
@ -85,35 +85,34 @@ interface PaginatorInterface extends Countable
* *
* @return PageInterface * @return PageInterface
*/ */
public function getPreviousPage(); public function getPreviousPage(): PageInterface;
/** /**
* get the number of results for this paginator. * get the number of results for this paginator.
* *
* @return int * @return int
*/ */
public function getTotalItems(); public function getTotalItems(): int;
/** /**
* check if the current page has a next page. * check if the current page has a next page.
* *
* @return bool * @return bool
*/ */
public function hasNextPage(); public function hasNextPage(): bool;
/** /**
* check if the page with the given number exists. * check if the page with the given number exists.
* *
* @param int $number
*/ */
public function hasPage($number); public function hasPage($number): bool;
/** /**
* check if the current page has a page before. * check if the current page has a page before.
* *
* @return bool * @return bool
*/ */
public function hasPreviousPage(); public function hasPreviousPage(): bool;
/** /**
* check if the given page is the current page. * check if the given page is the current page.
@ -122,10 +121,10 @@ interface PaginatorInterface extends Countable
* *
* @return bool * @return bool
*/ */
public function isCurrentPage(PageInterface $page); public function isCurrentPage(PageInterface $page): bool;
/* /*
* set the number of items per page * set the number of items per page
*/ */
public function setItemsPerPage($itemsPerPage); public function setItemsPerPage(int $itemsPerPage);
} }

View File

@ -27,7 +27,7 @@ class Counter implements JsonSerializable
return $this->counter; return $this->counter;
} }
public function jsonSerialize() public function jsonSerialize(): array
{ {
return ['count' => $this->counter]; return ['count' => $this->counter];
} }

View File

@ -70,23 +70,23 @@ class DelegatedBlockRenderingEvent extends Event implements ArrayAccess
return $this->content; return $this->content;
} }
public function offsetExists($offset) public function offsetExists($offset): bool
{ {
return isset($this->context[$offset]); return isset($this->context[$offset]);
} }
public function offsetGet($offset) public function offsetGet($offset): mixed
{ {
return $this->context[$offset]; return $this->context[$offset];
} }
public function offsetSet($offset, $value) public function offsetSet($offset, $value): void
{ {
throw new RuntimeException('The event context is read-only, you are not ' throw new RuntimeException('The event context is read-only, you are not '
. 'allowed to update it.'); . 'allowed to update it.');
} }
public function offsetUnset($offset) public function offsetUnset($offset): void
{ {
throw new RuntimeException('The event context is read-only, you are not ' throw new RuntimeException('The event context is read-only, you are not '
. 'allowed to update it.'); . 'allowed to update it.');

View File

@ -26,6 +26,7 @@ use Chill\PersonBundle\Repository\PersonACLAwareRepositoryInterface;
use DateTime; use DateTime;
use Exception; use Exception;
use libphonenumber\PhoneNumber; use libphonenumber\PhoneNumber;
use libphonenumber\PhoneNumberUtil;
use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Templating\EngineInterface; use Symfony\Component\Templating\EngineInterface;
@ -162,11 +163,11 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
$phonenumber = new PhoneNumber(); $phonenumber = new PhoneNumber();
$phonenumber->setNationalNumber($terms['phonenumber']); $phonenumber->setNationalNumber($terms['phonenumber']);
} catch (Exception $ex) { } catch (Exception $ex) {
throw new ParsingException("The date for {$key} is " throw new ParsingException("The data for {$key} is "
. 'not parsable', 0, $ex); . 'not parsable', 0, $ex);
} }
$data['phonenumber'] = $phonenumber ?? null; $data['phonenumber'] = $phonenumber;
} }
return $data; return $data;

View File

@ -51,7 +51,7 @@ class AccompanyingPeriodWorkEvaluationVoter extends Voter implements ChillVoterI
{ {
switch ($attribute) { switch ($attribute) {
case self::STATS: case self::STATS:
return $this->security->isGranted(AccompanyingPeriodWorkVoter::STATS, $subject); return $this->security->isGranted(AccompanyingPeriodVoter::STATS, $subject);
case self::SEE: case self::SEE:
return $this->security->isGranted(AccompanyingPeriodWorkVoter::SEE, $subject->getAccompanyingPeriodWork()); return $this->security->isGranted(AccompanyingPeriodWorkVoter::SEE, $subject->getAccompanyingPeriodWork());

View File

@ -24,12 +24,12 @@ class AuthorizedCenterOnPersonCreation implements AuthorizedCenterOnPersonCreati
public function __construct(AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser, ParameterBagInterface $parameterBag) public function __construct(AuthorizationHelperForCurrentUserInterface $authorizationHelperForCurrentUser, ParameterBagInterface $parameterBag)
{ {
$this->authorizationHelperForCurrentUser = $authorizationHelperForCurrentUser; $this->authorizationHelperForCurrentUser = $authorizationHelperForCurrentUser;
$this->showCenter = $parameterBag->get('chill_main')['acl']['form_show_centers']; $this->showCenters = $parameterBag->get('chill_main')['acl']['form_show_centers'];
} }
public function getCenters(): array public function getCenters(): array
{ {
if (!$this->showCenter) { if (!$this->showCenters) {
return []; return [];
} }

View File

@ -69,7 +69,6 @@ class Convert
$content = $this->storedObjectManager->read($storedObject); $content = $this->storedObjectManager->read($storedObject);
try {
$url = sprintf('%s/cool/convert-to/pdf', $this->collaboraDomain); $url = sprintf('%s/cool/convert-to/pdf', $this->collaboraDomain);
$form = new FormDataPart([ $form = new FormDataPart([
'data' => new DataPart($content, $storedObject->getUuid()->toString(), $storedObject->getType()), 'data' => new DataPart($content, $storedObject->getUuid()->toString(), $storedObject->getType()),
@ -80,16 +79,11 @@ class Convert
'timeout' => 10, 'timeout' => 10,
]); ]);
try {
return new Response($response->getContent(), Response::HTTP_OK, [ return new Response($response->getContent(), Response::HTTP_OK, [
'Content-Type' => 'application/pdf', 'Content-Type' => 'application/pdf',
]); ]);
} catch (ClientExceptionInterface $exception) { } catch (ClientExceptionInterface|TransportExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface $exception) {
return $this->onConversionFailed($url, $response);
} catch (RedirectionExceptionInterface $e) {
return $this->onConversionFailed($url, $response);
} catch (ServerExceptionInterface $e) {
return $this->onConversionFailed($url, $response);
} catch (TransportExceptionInterface $e) {
return $this->onConversionFailed($url, $response); return $this->onConversionFailed($url, $response);
} }
} }

View File

@ -32,7 +32,7 @@ class UserManager implements \ChampsLibres\WopiBundle\Contracts\UserManagerInter
return null; return null;
} }
return (string) $user->getLabel(); return $user->getLabel();
} }
public function getUserId(string $accessToken, string $fileId, RequestInterface $request): ?string public function getUserId(string $accessToken, string $fileId, RequestInterface $request): ?string