Merge branch 'fix-phpstan-issues-202303' into 'master'

DX: fix phpstan issues (2023-03)

See merge request Chill-Projet/chill-bundles!510
This commit is contained in:
Julien Fastré 2023-04-11 20:11:18 +00:00
commit d70a0fa08b
49 changed files with 164 additions and 1525 deletions

View File

@ -69,7 +69,7 @@ phpstan_tests:
stage: Tests
image: gitea.champs-libres.be/chill-project/chill-skeleton-basic/base-image:php82
script:
- bin/phpstan
- bin/phpstan analyze --memory-limit=2G
cache:
paths:
- .cache/
@ -79,21 +79,37 @@ phpstan_tests:
- bin
- tests/app/vendor/
psalm_tests:
rector_tests:
stage: Tests
image: gitea.champs-libres.be/chill-project/chill-skeleton-basic/base-image:php82
script:
- bin/psalm
allow_failure: true
- bin/rector --dry-run
cache:
paths:
- .cache/
artifacts:
expire_in: 30 min
paths:
- bin
- tests/app/vendor/
# psalm_tests:
# stage: Tests
# image: gitea.champs-libres.be/chill-project/chill-skeleton-basic/base-image:php82
# script:
# - bin/psalm
# allow_failure: true
# artifacts:
# expire_in: 30 min
# paths:
# - bin
# - tests/app/vendor/
unit_tests:
stage: Tests
image: gitea.champs-libres.be/chill-project/chill-skeleton-basic/base-image:php82
# until we fix testes
allow_failure: true
script:
- php tests/app/bin/console doctrine:migrations:migrate -n
- php -d memory_limit=2G tests/app/bin/console cache:clear --env=dev

View File

@ -75,6 +75,7 @@
"phpunit/phpunit": ">= 7.5",
"psalm/plugin-phpunit": "^0.18.4",
"psalm/plugin-symfony": "^4.0.2",
"rector/rector": "^0.15.23",
"symfony/debug-bundle": "^5.1",
"symfony/dotenv": "^4.4",
"symfony/maker-bundle": "^1.20",

View File

@ -442,11 +442,6 @@ parameters:
count: 2
path: src/Bundle/ChillMainBundle/Workflow/Validator/StepDestValidValidator.php
-
message: "#^Return type \\(int\\|void\\|null\\) of method Chill\\\\PersonBundle\\\\Command\\\\ImportPeopleFromCSVCommand\\:\\:execute\\(\\) should be covariant with return type \\(int\\) of method Symfony\\\\Component\\\\Console\\\\Command\\\\Command\\:\\:execute\\(\\)$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Parameter \\#3 \\$query \\(Doctrine\\\\ORM\\\\QueryBuilder\\) of method Chill\\\\PersonBundle\\\\Controller\\\\HouseholdCompositionTypeApiController\\:\\:customizeQuery\\(\\) should be contravariant with parameter \\$query \\(mixed\\) of method Chill\\\\MainBundle\\\\CRUD\\\\Controller\\\\AbstractCRUDController\\:\\:customizeQuery\\(\\)$#"
count: 1
@ -788,16 +783,6 @@ parameters:
count: 1
path: src/Bundle/ChillThirdPartyBundle/Security/Voter/ThirdPartyVoter.php
-
message: "#^Parameter \\#1 \\$thirdParty \\(Chill\\\\ThirdPartyBundle\\\\Entity\\\\ThirdParty\\) of method Chill\\\\ThirdPartyBundle\\\\Serializer\\\\Normalizer\\\\ThirdPartyNormalizer\\:\\:normalize\\(\\) should be contravariant with parameter \\$object \\(mixed\\) of method Symfony\\\\Component\\\\Serializer\\\\Normalizer\\\\NormalizerInterface\\:\\:normalize\\(\\)$#"
count: 1
path: src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php
-
message: "#^Parameter \\#2 \\$format \\(string\\) of method Chill\\\\ThirdPartyBundle\\\\Serializer\\\\Normalizer\\\\ThirdPartyNormalizer\\:\\:supportsNormalization\\(\\) should be contravariant with parameter \\$format \\(string\\|null\\) of method Symfony\\\\Component\\\\Serializer\\\\Normalizer\\\\NormalizerInterface\\:\\:supportsNormalization\\(\\)$#"
count: 1
path: src/Bundle/ChillThirdPartyBundle/Serializer/Normalizer/ThirdPartyNormalizer.php
-
message: "#^Parameter \\#1 \\$document \\(Chill\\\\DocStoreBundle\\\\Entity\\\\StoredObject\\) of method Chill\\\\WopiBundle\\\\Service\\\\Wopi\\\\ChillDocumentManager\\:\\:getBasename\\(\\) should be contravariant with parameter \\$document \\(ChampsLibres\\\\WopiLib\\\\Contract\\\\Entity\\\\Document\\) of method ChampsLibres\\\\WopiLib\\\\Contract\\\\Service\\\\DocumentManagerInterface\\:\\:getBasename\\(\\)$#"
count: 1

View File

@ -3026,111 +3026,6 @@ parameters:
count: 2
path: src/Bundle/ChillPersonBundle/Command/ChillPersonMoveCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$force\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$headers\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$helperSet\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$input\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$output\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$person\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$rawHeaders\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$row\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Access to an undefined property Symfony\\\\Component\\\\EventDispatcher\\\\Event\\:\\:\\$skipPerson\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Call to an undefined method Doctrine\\\\Persistence\\\\ObjectManager\\:\\:createQuery\\(\\)\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Call to method buildForm\\(\\) on an unknown class Chill\\\\CustomFieldsBundle\\\\Service\\\\CustomFieldInterface\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Else branch is unreachable because previous condition is always true\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Elseif branch is unreachable because previous condition is always true\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Instanceof between \\*NEVER\\* and Symfony\\\\Component\\\\Form\\\\ChoiceList\\\\View\\\\ChoiceGroupView will always evaluate to false\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Instanceof between Symfony\\\\Component\\\\Form\\\\ChoiceList\\\\View\\\\ChoiceView and Symfony\\\\Component\\\\Form\\\\ChoiceList\\\\View\\\\ChoiceView will always evaluate to true\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Method Chill\\\\PersonBundle\\\\Command\\\\ImportPeopleFromCSVCommand\\:\\:processTextType\\(\\) has invalid return type Chill\\\\PersonBundle\\\\Command\\\\type\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Method Symfony\\\\Component\\\\Console\\\\Helper\\\\Table\\:\\:render\\(\\) invoked with 1 parameter, 0 required\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) invoked with 2 parameters, 1 required\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^PHPDoc tag @var above foreach loop does not specify variable name\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Parameter \\$value of method Chill\\\\PersonBundle\\\\Command\\\\ImportPeopleFromCSVCommand\\:\\:processTextType\\(\\) has invalid type Chill\\\\PersonBundle\\\\Command\\\\type\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Strict comparison using \\=\\=\\= between false and false will always evaluate to true\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^PHPDoc tag @var for property Chill\\\\PersonBundle\\\\Command\\\\ImportSocialWorkMetadata\\:\\:\\$importer with type Psr\\\\Log\\\\LoggerInterface is not subtype of native type Chill\\\\PersonBundle\\\\Service\\\\Import\\\\ChillImporter\\.$#"
count: 1

View File

@ -425,21 +425,6 @@ parameters:
count: 2
path: src/Bundle/ChillPersonBundle/Actions/Remove/PersonMove.php
-
message: "#^Parameter \\#1 \\$event of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects object, string given\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Parameter \\#1 \\$mobilenumber of method Chill\\\\PersonBundle\\\\Entity\\\\Person\\:\\:setMobilenumber\\(\\) expects libphonenumber\\\\PhoneNumber\\|null, string given\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Parameter \\#1 \\$phonenumber of method Chill\\\\PersonBundle\\\\Entity\\\\Person\\:\\:setPhonenumber\\(\\) expects libphonenumber\\\\PhoneNumber\\|null, string given\\.$#"
count: 1
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Parameter \\#1 \\$event of method Symfony\\\\Contracts\\\\EventDispatcher\\\\EventDispatcherInterface\\:\\:dispatch\\(\\) expects object, string given\\.$#"
count: 1

View File

@ -310,11 +310,6 @@ parameters:
count: 1
path: src/Bundle/ChillPersonBundle/Command/ChillPersonMoveCommand.php
-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 6
path: src/Bundle/ChillPersonBundle/Command/ImportPeopleFromCSVCommand.php
-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1

View File

@ -3,7 +3,7 @@ parameters:
paths:
- src/
tmpDir: .cache/
reportUnmatchedIgnoredErrors: true
reportUnmatchedIgnoredErrors: false
excludePaths:
- .php_cs*
- docs/

25
rector.php Normal file
View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Rector\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->paths([
__DIR__ . '/docs',
__DIR__ . '/src',
]);
$rectorConfig->cacheClass(\Rector\Caching\ValueObject\Storage\FileCacheStorage::class);
$rectorConfig->cacheDirectory(__DIR__.'/.cache/rector');
// register a single rule
$rectorConfig->rule(InlineConstructorDefaultToPropertyRector::class);
// define sets of rules
// $rectorConfig->sets([
// LevelSetList::UP_TO_PHP_74
// ]);
};

View File

@ -20,13 +20,6 @@ use Symfony\Component\Form\FormBuilderInterface;
class LocationFilter implements FilterInterface
{
private TranslatableStringHelper $translatableStringHelper;
public function __construct(TranslatableStringHelper $translatableStringHelper)
{
$this->translatableStringHelper = $translatableStringHelper;
}
public function addRole(): ?string
{
return null;

View File

@ -112,9 +112,9 @@ final class ActivityTypeTest extends KernelTestCase
'attendee' => true,
]]);
// var_dump($form->getErrors()->count()); var_dump($form->isValid());
// foreach($form->getErrors() as $e) { fwrite(STDOUT, var_dump($e->getMessage())); }
// var_dump($form->getErrors());
// var_dump($form->getErrors()->count()); var_dump($form->isValid());
// foreach($form->getErrors() as $e) { fwrite(STDOUT, var_dump($e->getMessage())); }
// var_dump($form->getErrors());
$this->assertTrue($form->isSynchronized(), 'Test the form is synchronized');
$this->assertTrue($form->isValid(), 'test the form is valid');

View File

@ -160,8 +160,8 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
return 'export.aside_activity.main_center';
}
/** @var Center $c */
if (null === $value || '' === $value || null === $c = $this->centerRepository->find($value)) {
/** @var Center $c */
return '';
}
@ -190,10 +190,6 @@ final class ListAsideActivity implements ListInterface, GroupedExportInterface
];
}
/**
* @param QueryBuilder $query
* @param array $data
*/
public function getResult($query, $data): array
{
return $query->getQuery()->getResult(AbstractQuery::HYDRATE_ARRAY);

View File

@ -28,22 +28,17 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
use Symfony\Component\Form\FormEvents;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use function in_array;
final class AsideActivityFormType extends AbstractType
{
private TokenStorageInterface $storage;
private array $timeChoices;
public function __construct(
ParameterBagInterface $parameterBag,
TokenStorageInterface $storage
) {
$this->timeChoices = $parameterBag->get('chill_aside_activity.form.time_duration');
$this->storage = $storage;
}
public function buildForm(FormBuilderInterface $builder, array $options)

View File

@ -33,27 +33,15 @@ class ElementController extends AbstractController
{
private CalculatorManager $calculator;
private LoggerInterface $chillMainLogger;
private EntityManagerInterface $em;
private ResourceRepository $resourceRepository;
private ChargeRepository $chargeRepository;
private TranslatorInterface $translator;
public function __construct(
EntityManagerInterface $em,
TranslatorInterface $translator,
LoggerInterface $chillMainLogger,
CalculatorManager $calculator,
ResourceRepository $resourceRepository,
ChargeRepository $chargeRepository,
) {
$this->em = $em;
$this->translator = $translator;
$this->chillMainLogger = $chillMainLogger;
$this->calculator = $calculator;
$this->resourceRepository = $resourceRepository;
$this->chargeRepository = $chargeRepository;

View File

@ -30,7 +30,7 @@ final class ChargeKindRepository implements ChargeKindRepositoryInterface
}
/**
* @return ChargeType[]
* @return array<ChargeKind>
*/
public function findAll(): array
{
@ -38,7 +38,7 @@ final class ChargeKindRepository implements ChargeKindRepositoryInterface
}
/**
* @return ChargeType[]
* @return array<ChargeKind>
*/
public function findAllActive(): array
{
@ -53,7 +53,7 @@ final class ChargeKindRepository implements ChargeKindRepositoryInterface
}
/**
* @return ChargeType[]
* @return array<ChargeKind>
*/
public function findAllByType(string $type): array
{
@ -64,7 +64,7 @@ final class ChargeKindRepository implements ChargeKindRepositoryInterface
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return ChargeType[]
* @return array<ChargeKind>
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
{

View File

@ -19,25 +19,25 @@ interface ChargeKindRepositoryInterface extends ObjectRepository
public function find($id): ?ChargeKind;
/**
* @return ChargeType[]
* @return array<ChargeKind>
*/
public function findAll(): array;
/**
* @return ChargeType[]
* @return array<ChargeKind>
*/
public function findAllActive(): array;
/**
* @return ChargeType[]
* @return array<ChargeKind>
*/
public function findAllByType(string $type): array;
/**
* @param mixed|null $limit
* @param mixed|null $offset
* @param int|null $limit
* @param int|null $offset
*
* @return ChargeType[]
* @return array<ChargeKind>
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;

View File

@ -30,7 +30,7 @@ final class ResourceKindRepository implements ResourceKindRepositoryInterface
}
/**
* @return ResourceType[]
* @return list<ResourceKind>
*/
public function findAll(): array
{
@ -38,7 +38,7 @@ final class ResourceKindRepository implements ResourceKindRepositoryInterface
}
/**
* @return ResourceType[]
* @return list<ResourceKind>
*/
public function findAllActive(): array
{
@ -58,7 +58,7 @@ final class ResourceKindRepository implements ResourceKindRepositoryInterface
}
/**
* @return ResourceType[]
* @return list<ResourceKind>
*/
public function findAllByType(string $type): array
{
@ -69,7 +69,7 @@ final class ResourceKindRepository implements ResourceKindRepositoryInterface
* @param mixed|null $limit
* @param mixed|null $offset
*
* @return ResourceType[]
* @return list<ResourceKind>
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array
{

View File

@ -19,25 +19,25 @@ interface ResourceKindRepositoryInterface extends ObjectRepository
public function find($id): ?ResourceKind;
/**
* @return ResourceType[]
* @return list<ResourceKind>
*/
public function findAll(): array;
/**
* @return ResourceType[]
* @return list<ResourceKind>
*/
public function findAllActive(): array;
/**
* @return ResourceType[]
* @return list<ResourceKind>
*/
public function findAllByType(string $type): array;
/**
* @param mixed|null $limit
* @param mixed|null $offset
* @param int|null $limit
* @param int|null $offset
*
* @return ResourceType[]
* @return list<ResourceKind>
*/
public function findBy(array $criteria, ?array $orderBy = null, ?int $limit = null, ?int $offset = null): array;

View File

@ -554,21 +554,6 @@ class CalendarController extends AbstractController
return $filterOrder->build();
}
private function buildParamsToUrl(?User $user, ?AccompanyingPeriod $accompanyingPeriod): array
{
$params = [];
if (null !== $user) {
$params['user_id'] = $user->getId();
}
if (null !== $accompanyingPeriod) {
$params['id'] = $accompanyingPeriod->getId();
}
return $params;
}
/**
* Creates a form to delete a Calendar entity by id.
*/

View File

@ -29,6 +29,7 @@ use DateTimeImmutable;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\ORM\Mapping as ORM;
use LogicException;
use Symfony\Component\Serializer\Annotation as Serializer;
@ -508,10 +509,10 @@ class Calendar implements TrackCreationInterface, TrackUpdateInterface, HasCente
}
/**
* @return Collection|User[]
* @return ReadableCollection<(int|string), User>
* @Serializer\Groups({"calendar:read", "read"})
*/
public function getUsers(): Collection
public function getUsers(): ReadableCollection
{
return $this->getInvites()->map(static function (Invite $i) {
return $i->getUser();

View File

@ -52,7 +52,7 @@ class CountCalendars implements ExportInterface, GroupedExportInterface
return 'Exports of calendar';
}
public function getLabels($key, array $values, $data): Closure
public function getLabels($key, array $values, $data)
{
if ('export_result' !== $key) {
throw new LogicException("the key {$key} is not used by this export");

View File

@ -113,27 +113,23 @@ class EventSearch extends AbstractSearch
]
);
}
// format is "json"
$results = [];
$search = $this->search($terms, $start, $limit, $options);
if ('json' === $format) {
$results = [];
$search = $this->search($terms, $start, $limit, $options);
foreach ($search as $item) {
$results[] = [
'id' => $item->getId(),
'text' => $item->getDate()->format('d/m/Y, H:i') . ' → ' .
// $item->getType()->getName()['fr'] . ': ' . // display the type of event
$item->getName(),
];
}
return [
'results' => $results,
'pagination' => [
'more' => $paginator->hasNextPage(),
],
foreach ($search as $item) {
$results[] = [
'id' => $item->getId(),
'text' => $item->getDate()->format('d/m/Y, H:i') . ' → ' .
// $item->getType()->getName()['fr'] . ': ' . // display the type of event
$item->getName(),
];
}
return [
'results' => $results,
'more' => $paginator->hasNextPage(),
];
}
public function supports($domain, $format)

View File

@ -101,7 +101,7 @@ class CRUDRoutesLoader extends Loader
$singleCollection = $action['single_collection'] ?? '_entity' === $name ? 'single' : null;
if ('collection' === $singleCollection) {
// continue;
// continue;
}
// compute default action

View File

@ -211,7 +211,7 @@ trait AddWidgetConfigurationTrait
*
* @throws InvalidConfigurationException if a service's tag does not have the "alias" key
*
* @return type
* @return array
*/
protected function getWidgetAliasesbyPlace($place, ContainerBuilder $containerBuilder)
{

View File

@ -31,9 +31,6 @@ class NativeDateIntervalType extends DateIntervalType
{
public const FORMAT = '%rP%YY%MM%DDT%HH%IM%SS';
/**
* @param DateInterval|null $value
*/
public function convertToDatabaseValue($value, AbstractPlatform $platform)
{
if (null === $value) {

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Export;
use Doctrine\ORM\NativeQuery;
use Doctrine\ORM\QueryBuilder;
/**
@ -23,6 +24,7 @@ use Doctrine\ORM\QueryBuilder;
* aggregation, use `ListInterface`.
*
* @example Chill\PersonBundle\Export\CountPerson an example of implementation
* @template Q of QueryBuilder|NativeQuery
*/
interface ExportInterface extends ExportElementInterface
{
@ -84,7 +86,7 @@ interface ExportInterface extends ExportElementInterface
* @param mixed[] $values The values from the result. if there are duplicates, those might be given twice. Example: array('FR', 'BE', 'CZ', 'FR', 'BE', 'FR')
* @param mixed $data The data from the export's form (as defined in `buildForm`)
*
* @return pure-callable(null|string|int|float|'_header' $value):string|int|\DateTimeInterface where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }`
* @return callable(null|string|int|float|'_header' $value): string|int|\DateTimeInterface where the first argument is the value, and the function should return the label to show in the formatted file. Example : `function($countryCode) use ($countries) { return $countries[$countryCode]->getName(); }`
*/
public function getLabels($key, array $values, $data);
@ -102,7 +104,7 @@ interface ExportInterface extends ExportElementInterface
/**
* Return the results of the query builder.
*
* @param \Doctrine\ORM\NativeQuery|QueryBuilder $query
* @param Q $query
* @param mixed[] $data the data from the export's fomr (added by self::buildForm)
*
* @return mixed[] an array of results
@ -132,7 +134,7 @@ interface ExportInterface extends ExportElementInterface
* @param array $acl an array where each row has a `center` key containing the Chill\MainBundle\Entity\Center, and `circles` keys containing the reachable circles. Example: `array( array('center' => $centerA, 'circles' => array($circleA, $circleB) ) )`
* @param array $data the data from the form, if any
*
* @return \Doctrine\ORM\NativeQuery|QueryBuilder the query to execute.
* @return Q the query to execute.
*/
public function initiateQuery(array $requiredModifiers, array $acl, array $data = []);

View File

@ -24,15 +24,7 @@ class ExportPickCenterDataMapper implements DataMapperInterface
{
protected RegroupmentRepository $regroupmentRepository;
/**
* @param array|Center[] $data
* @param $forms
*
* @throws Exception
*
* @return void
*/
public function mapDataToForms($data, $forms)
public function mapDataToForms($data, $forms): void
{
if (null === $data) {
return;
@ -44,7 +36,9 @@ class ExportPickCenterDataMapper implements DataMapperInterface
$pickedRegroupment = [];
foreach ($this->regroupmentRepository->findAll() as $regroupment) {
[$contained, $notContained] = $regroupment->getCenters()->partition(static function (Center $center) {
/** @phpstan-ignore-next-line */
[$contained, $notContained] = $regroupment->getCenters()->partition(static function (Center $center): bool {
return false;
});
if (0 === count($notContained)) {
@ -56,13 +50,7 @@ class ExportPickCenterDataMapper implements DataMapperInterface
$form['centers']->setData($data);
}
/**
* @param iterable $forms
* @param array $data
*
* @return void
*/
public function mapFormsToData($forms, &$data)
public function mapFormsToData($forms, &$data): void
{
/** @var array<string, FormInterface> $forms */
$forms = iterator_to_array($forms);
@ -74,8 +62,8 @@ class ExportPickCenterDataMapper implements DataMapperInterface
}
if (array_key_exists('regroupment', $forms)) {
/** @var Regroupment $regroupment */
foreach ($forms['regroupment']->getData() as $regroupment) {
/** @var Regroupment $regroupment */
foreach ($regroupment->getCenters() as $center) {
$centers[spl_object_hash($center)] = $center;
}

View File

@ -31,8 +31,6 @@ class MultipleObjectsToIdTransformer implements DataTransformerInterface
* Transforms a string (id) to an object (item).
*
* @param mixed $array
*
* @return ArrayCollection
*/
public function reverseTransform($array)
{
@ -53,10 +51,8 @@ class MultipleObjectsToIdTransformer implements DataTransformerInterface
* Transforms an object (use) to a string (id).
*
* @param array $array
*
* @return ArrayCollection
*/
public function transform($array)
public function transform($array): array
{
$ret = [];

View File

@ -11,8 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Search;
use Chill\MainBundle\Pagination\Paginator;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Pagination\PaginatorInterface;
use Chill\MainBundle\Serializer\Model\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
@ -100,7 +100,7 @@ class SearchApi
return $items;
}
private function buildUnionQuery(array $queries, Paginator $paginator): array
private function buildUnionQuery(array $queries, PaginatorInterface $paginator): array
{
$query = '{unions} ORDER BY pertinence DESC LIMIT ? OFFSET ?';
$unions = [];
@ -134,7 +134,7 @@ class SearchApi
return (int) $countNq->getSingleScalarResult();
}
private function fetchRawResult($queries, $types, Paginator $paginator): array
private function fetchRawResult($queries, $types, PaginatorInterface $paginator): array
{
[$union, $parameters] = $this->buildUnionQuery($queries, $paginator);
$rsm = new ResultSetMappingBuilder($this->em);

View File

@ -71,9 +71,9 @@ interface SearchInterface
* @param array $terms the string to search
* @param int $start the first result (for pagination)
* @param int $limit the number of result (for pagination)
* @param string $format The format for result
* @param "html"|"json" $format The format for result
*
* @return string, an HTML string
* @return string|array a string if format is html, an array if format is json
*/
public function renderResult(array $terms, $start = 0, $limit = 50, array $options = [], $format = 'html');

View File

@ -63,7 +63,7 @@ class AuthorizationHelper implements AuthorizationHelperInterface
*
* @param User $user The user
* @param array $centers a list of centers which are going to be filtered
* @param string $role
* @param mixed $role
*/
public function filterReachableCenters(User $user, array $centers, $role): array
{
@ -197,10 +197,6 @@ class AuthorizationHelper implements AuthorizationHelperInterface
*/
public function getReachableScopes(UserInterface $user, string $role, Center|array $center): array
{
if ($role instanceof Role) {
$role = $role->getRole();
}
return $this->getReachableCircles($user, $role, $center);
}

View File

@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\MainBundle\Workflow;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Entity\Workflow\EntityWorkflow;
interface EntityWorkflowHandlerInterface

View File

@ -82,7 +82,7 @@ class HouseholdController extends AbstractController
}
usort($accompanyingPeriods, static function ($a, $b) {
return $b->getOpeningDate() > $a->getOpeningDate();
return $b->getOpeningDate() <=> $a->getOpeningDate();
});
$oldMembers = $household->getNonCurrentMembers();

View File

@ -64,8 +64,6 @@ final class PersonController extends AbstractController
*/
protected $personRepository;
private Security $security;
/**
* @var SimilarPersonMatcher
*/
@ -101,7 +99,6 @@ final class PersonController extends AbstractController
LoggerInterface $logger,
ValidatorInterface $validator,
EntityManagerInterface $em,
Security $security
) {
$this->authorizationHelper = $authorizationHelper;
$this->similarPersonMatcher = $similarPersonMatcher;
@ -112,7 +109,6 @@ final class PersonController extends AbstractController
$this->logger = $logger;
$this->validator = $validator;
$this->em = $em;
$this->security = $security;
}
public function editAction($person_id, Request $request)

View File

@ -98,6 +98,7 @@ class ReassignAccompanyingPeriodController extends AbstractController
$total = $this->accompanyingPeriodACLAwareRepository->countByUserOpenedAccompanyingPeriod($userFrom);
$paginator = $this->paginatorFactory->create($total);
$paginator->setItemsPerPage(50);
$periods = $this->accompanyingPeriodACLAwareRepository
->findByUserAndPostalCodesOpenedAccompanyingPeriod(
$userFrom,

View File

@ -42,6 +42,7 @@ use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\ORM\Mapping as ORM;
use Iterator;
use LogicException;
@ -615,9 +616,9 @@ class AccompanyingPeriod implements
/**
* Get a list of person which have an adresse available for a valid location.
*
* @return Collection|Person[]
* @return ReadableCollection<(int|string), Person>
*/
public function getAvailablePersonLocation(): Collection
public function getAvailablePersonLocation(): ReadableCollection
{
return $this->getOpenParticipations()
->filter(
@ -675,8 +676,9 @@ class AccompanyingPeriod implements
/**
* @Groups({"read"})
* @return ReadableCollection<(int|string), Comment>
*/
public function getComments(): Collection
public function getComments(): ReadableCollection
{
$pinnedComment = $this->pinnedComment;
@ -700,7 +702,7 @@ class AccompanyingPeriod implements
/**
* @Groups({"docgen:read"})
*/
public function getCurrentParticipations(): Collection
public function getCurrentParticipations(): ReadableCollection
{
return $this->getOpenParticipations();
}
@ -834,7 +836,10 @@ class AccompanyingPeriod implements
return $collection->count() > 0 ? $collection->first() : null;
}
public function getOpenParticipations(): Collection
/**
* @return ReadableCollection<(int|string), AccompanyingPeriodParticipation>
*/
public function getOpenParticipations(): ReadableCollection
{
return $this
->getParticipations()
@ -860,8 +865,9 @@ class AccompanyingPeriod implements
/**
* Get the participation containing a person.
* @return ReadableCollection<(int|string), AccompanyingPeriodParticipation>
*/
public function getParticipationsContainsPerson(Person $person): Collection
public function getParticipationsContainsPerson(Person $person): ReadableCollection
{
return $this
->getParticipations()

View File

@ -22,6 +22,7 @@ use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
@ -265,7 +266,7 @@ class Household
* @Serializer\Groups({"read"})
* @Serializer\SerializedName("current_members_id")
*/
public function getCurrentMembersIds(?DateTimeImmutable $now = null): Collection
public function getCurrentMembersIds(?DateTimeImmutable $now = null): ReadableCollection
{
return $this->getCurrentMembers($now)->map(
static fn (HouseholdMember $m) => $m->getId()
@ -332,9 +333,9 @@ class Household
*
* Return a list of Person, instead of a list of HouseholdMembers
*
* @return Person[]
* @return ReadableCollection<(int|string), Person>
*/
public function getCurrentPersons(?DateTimeImmutable $now = null): Collection
public function getCurrentPersons(?DateTimeImmutable $now = null): ReadableCollection
{
return $this->getCurrentMembers($now)
->map(static function (HouseholdMember $m) {
@ -358,9 +359,9 @@ class Household
/**
* get all the members during a given membership.
*
* @return Collection|HouseholdMember[]
* @return ReadableCollection<(int|string), HouseholdMember>
*/
public function getMembersDuringMembership(HouseholdMember $membership): Collection
public function getMembersDuringMembership(HouseholdMember $membership): ReadableCollection
{
return $this->getMembersOnRange(
$membership->getStartDate(),
@ -384,7 +385,7 @@ class Household
return $this->getMembers()->matching($criteria);
}
public function getMembersOnRange(DateTimeImmutable $from, ?DateTimeImmutable $to): Collection
public function getMembersOnRange(DateTimeImmutable $from, ?DateTimeImmutable $to): ReadableCollection
{
return $this->getMembers()->filter(static function (HouseholdMember $m) use ($from, $to) {
if (null === $m->getEndDate() && null !== $to) {

View File

@ -28,12 +28,15 @@ class PickPersonDynamicType extends AbstractType
{
private DenormalizerInterface $denormalizer;
private DenormalizerInterface $normalizer;
private NormalizerInterface $normalizer;
private SerializerInterface $serializer;
public function __construct(DenormalizerInterface $denormalizer, SerializerInterface $serializer, NormalizerInterface $normalizer)
{
public function __construct(
DenormalizerInterface $denormalizer,
SerializerInterface $serializer,
NormalizerInterface $normalizer
) {
$this->denormalizer = $denormalizer;
$this->serializer = $serializer;
$this->normalizer = $normalizer;

View File

@ -59,7 +59,7 @@ class PrivacyEvent extends Event
/**
* @var array
*/
private $persons;
private $persons = [];
/**
* PrivacyEvent constructor.
@ -68,7 +68,6 @@ class PrivacyEvent extends Event
{
$this->person = $person;
$this->args = $args;
$this->persons = [];
}
public function addPerson(Person $person)

View File

@ -203,15 +203,6 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
return true;
}
/**
* (non-PHPdoc).
*
* @see \Chill\MainBundle\Search\SearchInterface::renderResult()
*
* @param mixed $start
* @param mixed $limit
* @param mixed $format
*/
public function renderResult(array $terms, $start = 0, $limit = 50, array $options = [], $format = 'html')
{
$terms = $this->findAdditionnalInDefault($terms);
@ -236,15 +227,13 @@ class PersonSearch extends AbstractSearch implements HasAdvancedSearchFormInterf
]
);
}
if ('json' === $format) {
return [
'results' => $this->search($terms, $start, $limit, array_merge($options, ['simplify' => true])),
'pagination' => [
'more' => $paginator->hasNextPage(),
],
];
}
// format is "json"
return [
'results' => $this->search($terms, $start, $limit, array_merge($options, ['simplify' => true])),
'pagination' => [
'more' => $paginator->hasNextPage(),
],
];
}
public function supports($domain, $format)

View File

@ -27,6 +27,7 @@ use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Repository\PersonRepository;
use Chill\PersonBundle\Templating\Entity\PersonRenderInterface;
use DateTime;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\EntityRepository;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
@ -159,9 +160,9 @@ class AccompanyingPeriodContext implements
public function buildPublicForm(FormBuilderInterface $builder, DocGeneratorTemplate $template, mixed $entity): void
{
$options = $template->getOptions();
$persons = $entity->getCurrentParticipations()->map(static function (AccompanyingPeriodParticipation $p) {
$persons = new ArrayCollection($entity->getCurrentParticipations()->map(static function (AccompanyingPeriodParticipation $p) {
return $p->getPerson();
});
})->toArray());
foreach ($entity->getCurrentParticipations() as $p) {
foreach ($p->getPerson()->getResources() as $r) {

View File

@ -102,7 +102,9 @@ class AccompanyingPeriodWorkWorkflowHandler implements EntityWorkflowHandlerInte
->getAccompanyingPeriod()
->getUser();
$suggestedUsers[spl_object_hash($referrer)] = $referrer;
if (null !== $referrer) {
$suggestedUsers[spl_object_hash($referrer)] = $referrer;
}
return $suggestedUsers;
}

View File

@ -158,7 +158,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
);
}
public function getLabels($key, array $values, $data): Closure
public function getLabels($key, array $values, $data)
{
switch ($key) {
case 'person_birthdate':

View File

@ -66,22 +66,6 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
$manager->flush();
}
private function createAddress(): ObjectSet
{
$loader = new NativeLoader();
return $loader->loadData([
Address::class => [
'address1' => [
'name' => '<fr_FR:company()>',
'telephone' => $this->phoneNumberUtil->getExampleNumber('FR'),
'email' => '<email()>',
'comment' => '<fr_FR:realTextBetween(10, 500)>',
],
],
]);
}
private function getCenters(): Iterator
{
$references = array_map(

View File

@ -23,6 +23,7 @@ use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection;
use Doctrine\ORM\Mapping as ORM;
use libphonenumber\PhoneNumber;
use Symfony\Component\Serializer\Annotation\Context;
@ -153,7 +154,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
* @ORM\OneToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", mappedBy="parent",
* cascade={"persist"}, orphanRemoval=true)
*
* @var Collection|ThirdParty[]
* @var Collection<(int|string), ThirdParty>
* @Assert\Valid(traverse=true)
*/
private Collection $children;
@ -400,7 +401,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface
/**
* Get the children where active = true.
*/
public function getActiveChildren(): Collection
public function getActiveChildren(): ReadableCollection
{
return $this->children->filter(static fn (ThirdParty $tp) => $tp->getActive());
}

View File

@ -100,6 +100,8 @@ class ThirdPartySearch implements SearchInterface
'more' => $paginator->hasNextPage(),
];
}
// format "html"
throw new \UnexpectedValueException("format html not supported");
}
public function supports($domain, $format): bool

View File

@ -15,6 +15,7 @@ use Chill\MainBundle\Templating\TranslatableStringHelperInterface;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use Symfony\Component\Serializer\Exception\UnexpectedValueException;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerAwareTrait;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
@ -35,12 +36,12 @@ class ThirdPartyNormalizer implements NormalizerAwareInterface, NormalizerInterf
$this->translatableStringHelper = $translatableStringHelper;
}
/**
* @param ThirdParty $thirdParty
* @param string|null $format
*/
public function normalize($thirdParty, $format = null, array $context = [])
{
if (!$thirdParty instanceof ThirdParty) {
throw new UnexpectedValueException();
}
return [
'type' => 'thirdparty',
'firstname' => $thirdParty->getFirstname(),

View File

@ -25,7 +25,7 @@ final class Version20230215175150 extends AbstractMigration implements Container
public function down(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_3party.third_party DROP profession');
// $this->addSql('ALTER TABLE chill_3party.third_party ADD profession_id INT DEFAULT NULL');
// $this->addSql('ALTER TABLE chill_3party.third_party ADD profession_id INT DEFAULT NULL');
}
public function getDescription(): string

View File

@ -94,7 +94,7 @@ class Convert
'Content-Type' => 'application/pdf',
]);
} catch (ClientExceptionInterface|TransportExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface $exception) {
return $this->onConversionFailed($url, $response);
return $this->onConversionFailed($url, $exception->getResponse());
}
}