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
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\\.$#"
count: 1

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -27,27 +27,27 @@ class PageGenerator implements Iterator
$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;
}
public function next()
public function next(): void
{
++$this->current;
}
public function rewind()
public function rewind(): void
{
$this->current = 1;
}
public function valid()
public function valid(): bool
{
return 0 < $this->current
&& $this->paginator->countPages() >= $this->current;

View File

@ -26,21 +26,21 @@ class Paginator implements PaginatorInterface
*
* @var int
*/
protected $currentPageNumber;
protected int $currentPageNumber;
/**
* the number of items on a single page.
*
* @var int
*/
protected $itemPerPage;
protected int $itemPerPage;
/**
* the key in the GET parameter to indicate the number of item per page.
*
* @var string
*/
protected $itemPerPageKey;
protected string $itemPerPageKey;
/**
* the key in the GET parameter to indicate the page number in
@ -48,45 +48,45 @@ class Paginator implements PaginatorInterface
*
* @var string
*/
protected $pageKey;
protected string $pageKey;
/**
* the route of the pages.
*
* @var string
*/
protected $route;
protected string $route;
/**
* the parameters of the route.
*
* @var string[]
*/
protected $routeParameters;
protected array $routeParameters;
/**
* The number of total items.
*
* @var int
*/
protected $totalItems;
protected int $totalItems;
/**
* the generator for url.
*
* @var UrlGeneratorInterface
*/
protected $urlGenerator;
protected UrlGeneratorInterface $urlGenerator;
public function __construct(
$totalItems,
$itemPerPage,
$currentPageNumber,
$route,
int $totalItems,
int $itemPerPage,
int $currentPageNumber,
string $route,
array $routeParameters,
UrlGeneratorInterface $urlGenerator,
$pageKey,
$itemPerPageKey
string $pageKey,
string $itemPerPageKey
) {
$this->totalItems = $totalItems;
$this->itemPerPage = $itemPerPage;
@ -98,12 +98,12 @@ class Paginator implements PaginatorInterface
$this->itemPerPageKey = $itemPerPageKey;
}
public function count()
public function count(): int
{
return $this->countPages();
}
public function countPages()
public function countPages(): int
{
if (0 === $this->itemPerPage) {
return 1;
@ -122,20 +122,17 @@ class Paginator implements PaginatorInterface
return 0 === $nb ? 1 : (int) $nb;
}
/**
* @return \Chill\MainBundle\Pagination\Page
*/
public function getCurrentPage()
public function getCurrentPage(): Page
{
return $this->getPage($this->currentPageNumber);
}
public function getCurrentPageFirstItemNumber()
public function getCurrentPageFirstItemNumber(): int
{
return $this->getCurrentPage()->getFirstItemNumber();
}
public function getItemsPerPage()
public function getItemsPerPage(): int
{
return $this->itemPerPage;
}
@ -145,7 +142,7 @@ class Paginator implements PaginatorInterface
*
* @return \Chill\MainBundle\Pagination\Page
*/
public function getNextPage()
public function getNextPage(): Page
{
if (!$this->hasNextPage()) {
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
*/
public function getPage($number)
public function getPage(int $number): Page
{
if (!$this->hasPage($number)) {
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) {
yield $this->getPage($i);
@ -191,7 +187,7 @@ class Paginator implements PaginatorInterface
*
* @return \Chill\MainBundle\Pagination\Page
*/
public function getPreviousPage()
public function getPreviousPage(): PageInterface
{
if (!$this->hasPreviousPage()) {
throw new RuntimeException('this page has no previous page');
@ -200,7 +196,7 @@ class Paginator implements PaginatorInterface
return $this->getPage($this->currentPageNumber - 1);
}
public function getTotalItems()
public function getTotalItems(): int
{
return $this->totalItems;
}
@ -208,12 +204,12 @@ class Paginator implements PaginatorInterface
/**
* @return bool
*/
public function hasNextPage()
public function hasNextPage(): bool
{
return $this->hasPage($this->currentPageNumber + 1);
}
public function hasPage($number)
public function hasPage($number): bool
{
if (0 === $this->totalItems) {
return 1 === $number;
@ -226,18 +222,18 @@ class Paginator implements PaginatorInterface
/**
* @return bool
*/
public function hasPreviousPage()
public function hasPreviousPage(): bool
{
return $this->hasPage($this->currentPageNumber - 1);
}
public function isCurrentPage(PageInterface $page)
public function isCurrentPage(PageInterface $page): bool
{
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
*/
public function countPages();
public function countPages(): int;
/**
* get the current page.
*
* @return PageInterface
*/
public function getCurrentPage();
public function getCurrentPage(): PageInterface;
/**
* get the first result for the current page.
*
* @return int
*/
public function getCurrentPageFirstItemNumber();
public function getCurrentPageFirstItemNumber(): int;
/*
* get the number of items per page
*/
public function getItemsPerPage();
public function getItemsPerPage(): int;
/**
* get the next page.
@ -60,7 +60,7 @@ interface PaginatorInterface extends Countable
*
* @return PageInterface
*/
public function getNextPage();
public function getNextPage(): PageInterface;
/**
* get page by his number.
@ -69,14 +69,14 @@ interface PaginatorInterface extends Countable
*
* @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.
*
* @return Generator which return PageInterface elements
*/
public function getPagesGenerator();
public function getPagesGenerator(): iterable;
/**
* get the previous page.
@ -85,35 +85,34 @@ interface PaginatorInterface extends Countable
*
* @return PageInterface
*/
public function getPreviousPage();
public function getPreviousPage(): PageInterface;
/**
* get the number of results for this paginator.
*
* @return int
*/
public function getTotalItems();
public function getTotalItems(): int;
/**
* check if the current page has a next page.
*
* @return bool
*/
public function hasNextPage();
public function hasNextPage(): bool;
/**
* 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.
*
* @return bool
*/
public function hasPreviousPage();
public function hasPreviousPage(): bool;
/**
* check if the given page is the current page.
@ -122,10 +121,10 @@ interface PaginatorInterface extends Countable
*
* @return bool
*/
public function isCurrentPage(PageInterface $page);
public function isCurrentPage(PageInterface $page): bool;
/*
* 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;
}
public function jsonSerialize()
public function jsonSerialize(): array
{
return ['count' => $this->counter];
}

View File

@ -70,23 +70,23 @@ class DelegatedBlockRenderingEvent extends Event implements ArrayAccess
return $this->content;
}
public function offsetExists($offset)
public function offsetExists($offset): bool
{
return isset($this->context[$offset]);
}
public function offsetGet($offset)
public function offsetGet($offset): mixed
{
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 '
. '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 '
. 'allowed to update it.');

View File

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

View File

@ -51,7 +51,7 @@ class AccompanyingPeriodWorkEvaluationVoter extends Voter implements ChillVoterI
{
switch ($attribute) {
case self::STATS:
return $this->security->isGranted(AccompanyingPeriodWorkVoter::STATS, $subject);
return $this->security->isGranted(AccompanyingPeriodVoter::STATS, $subject);
case self::SEE:
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)
{
$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
{
if (!$this->showCenter) {
if (!$this->showCenters) {
return [];
}

View File

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

View File

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