fix misc phpstan issues

This commit is contained in:
2025-12-22 18:26:35 +01:00
parent 35d91762d3
commit 55c11c7f04
20 changed files with 62 additions and 78 deletions

View File

@@ -54,12 +54,6 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface
#[ORM\JoinColumn(nullable: false)]
private ?AsideActivityCategory $type = null;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $updatedAt = null;
#[ORM\ManyToOne(targetEntity: User::class)]
private User $updatedBy;
#[Assert\GreaterThanOrEqual(0)]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::INTEGER, nullable: true)]
private ?int $concernedPersonsCount = 0;
@@ -141,20 +135,6 @@ class AsideActivity implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
public function setUpdatedBy(?User $updatedBy): self
{
$this->updatedBy = $updatedBy;
return $this;
}
public function getConcernedPersonsCount(): ?int
{
return $this->concernedPersonsCount;

View File

@@ -32,8 +32,6 @@ interface ChillEntityRenderInterface
* ```
*
* @param T|null $entity
*
* @phpstan-pure
*/
public function renderBox(mixed $entity, array $options): string;
@@ -43,8 +41,6 @@ interface ChillEntityRenderInterface
* Example: returning the name of a person.
*
* @param T|null $entity
*
* @phpstan-pure
*/
public function renderString(mixed $entity, array $options): string;

View File

@@ -329,7 +329,7 @@ class AccompanyingPeriodWork implements AccompanyingPeriodLinkedWithSocialIssues
}
/**
* @return Collection|ThirdParty[]
* @return Collection<int, ThirdParty>
*/
public function getThirdParties(): Collection
{

View File

@@ -66,7 +66,7 @@ class ResidentialAddressRepository extends ServiceEntityRepository
}
/**
* @return array|ResidentialAddress[]|null
* @return list<ResidentialAddress>
*/
public function findCurrentResidentialAddressByPerson(Person $person, ?\DateTimeImmutable $at = null): array
{

View File

@@ -44,6 +44,10 @@ class PersonDocGenNormalizer implements
public function normalize($data, $format = null, array $context = []): string|int|float|bool|\ArrayObject|array|null
{
if (null !== $data && !$data instanceof Person) {
throw new UnexpectedValueException('Expected Person instance or null, got '.get_debug_type($data));
}
try {
$context = $this->addCircularToContext($data, $context);
} catch (CircularReferenceException) {
@@ -54,7 +58,6 @@ class PersonDocGenNormalizer implements
];
}
/** @var Person $data */
$dateContext = $context;
$dateContext['docgen:expects'] = \DateTimeInterface::class;
$addressContext = array_merge($context, ['docgen:expects' => Address::class]);
@@ -73,10 +76,6 @@ class PersonDocGenNormalizer implements
return $this->normalizeNullValue($format, $context);
}
if (!$data instanceof Person) {
throw new UnexpectedValueException();
}
$data = [
'type' => 'person',
'id' => $data->getId(),

View File

@@ -81,8 +81,8 @@ class PersonJsonNormalizer implements NormalizerAwareInterface, NormalizerInterf
...$normalizedData,
'centers' => $this->normalizer->normalize($this->centerResolverManager->resolveCenters($data), $format, $context),
'altNames' => $this->normalizeAltNames($data->getAltNames()),
'current_household_id' => $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
'current_residential_addresses' => $currentResidentialAddresses ? $this->normalizer->normalize($currentResidentialAddresses, $format, $context) : null,
'current_household_id' => null !== $household ? $this->normalizer->normalize($household->getId(), $format, $context) : null,
'current_residential_addresses' => $this->normalizer->normalize($currentResidentialAddresses, $format, $context),
];
}

View File

@@ -180,14 +180,16 @@ class AccompanyingPeriodContext implements
}
}
$thirdParties = [...array_values(array_filter([$entity->getRequestorThirdParty()])), ...array_values(array_filter(
array_map(
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getResources()->filter(
static fn (Resource $r): bool => null !== $r->getThirdParty()
)->toArray()
)
))];
$thirdParties = [
...array_values(array_filter([$entity->getRequestorThirdParty()])),
...array_values(array_filter(
array_map(
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getResources()->filter(
static fn (Resource $r): bool => null !== $r->getThirdParty()
)->toArray()
)
))];
if ($options['thirdParty'] ?? false) {
$builder->add('thirdParty', EntityType::class, [

View File

@@ -85,16 +85,23 @@ class AccompanyingPeriodWorkEvaluationContext implements
{
$this->accompanyingPeriodWorkContext->buildPublicForm($builder, $template, $entity->getAccompanyingPeriodWork());
$thirdParties = [...array_values(array_filter($entity->getAccompanyingPeriodWork()->getThirdParties()->toArray())), ...array_values(array_filter([$entity->getAccompanyingPeriodWork()->getHandlingThierParty()])), ...array_values(
array_filter(
array_map(
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getAccompanyingPeriodWork()->getAccompanyingPeriod()->getResources()->filter(
static fn (Resource $r): bool => null !== $r->getThirdParty()
)->toArray()
$thirdParties = [
...array_values(array_filter(
$entity->getAccompanyingPeriodWork()->getThirdParties()->toArray(),
static fn ($val) => null !== $val,
mode: 0
)),
...array_values(array_filter([$entity->getAccompanyingPeriodWork()->getHandlingThierParty()])),
...array_values(
array_filter(
array_map(
fn (Resource $r): ?ThirdParty => $r->getThirdParty(),
$entity->getAccompanyingPeriodWork()->getAccompanyingPeriod()->getResources()->filter(
static fn (Resource $r): bool => null !== $r->getThirdParty()
)->toArray()
)
)
)
)];
)];
$options = $template->getOptions();
if ($options['thirdParty'] ?? false) {

View File

@@ -11,6 +11,7 @@ declare(strict_types=1);
namespace Chill\ReportBundle\Controller;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\PersonBundle\Entity\Person;
@@ -113,10 +114,9 @@ class ReportController extends AbstractController
{
$em = $this->managerRegistry->getManager();
/** @var Report $report */
$report = $em->getRepository(Report::class)->find($report_id);
if (null == $report) {
if (null === $report) {
throw $this->createNotFoundException($this->translator->trans('Unable to find this report.'));
}
@@ -253,7 +253,11 @@ class ReportController extends AbstractController
}
$entity = new Report();
$entity->setUser($this->tokenStorage->getToken()->getUser());
$user = $this->tokenStorage->getToken()->getUser();
if (!$user instanceof User) {
throw $this->createAccessDeniedException();
}
$entity->setUser($user);
$entity->setDate(new \DateTime('now'));
$entity->setCFGroup($cFGroup);
@@ -312,7 +316,7 @@ class ReportController extends AbstractController
}
$form = $this->formFactory
->createNamedBuilder(null, FormType::class, null, [
->createNamedBuilder('', FormType::class, null, [
'method' => 'GET',
'csrf_protection' => false,
])
@@ -359,7 +363,7 @@ class ReportController extends AbstractController
}
$form = $this->formFactory
->createNamedBuilder(null, FormType::class, null, [
->createNamedBuilder('', FormType::class, null, [
'method' => 'GET',
'csrf_protection' => false,
])

View File

@@ -34,7 +34,7 @@ class Report implements HasCenterInterface, HasScopeInterface
#[ORM\ManyToOne(targetEntity: CustomFieldsGroup::class)]
private ?CustomFieldsGroup $cFGroup = null;
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE)]
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTime $date = null;
#[ORM\Id]

View File

@@ -331,7 +331,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
switch ($f) {
case 'person_countryOfBirth':
case 'person_nationality':
$suffix = substr((string) $f, 7);
$suffix = substr($f, 7);
$qb->addSelect(sprintf('IDENTITY(person.%s) as %s', $suffix, $f));
break;
@@ -344,7 +344,7 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
case 'person_address_country_name':
case 'person_address_country_code':
// remove 'person_'
$suffix = substr((string) $f, 7);
$suffix = substr($f, 7);
$qb->addSelect(sprintf(
'GET_PERSON_ADDRESS_%s(person.id, :address_date) AS %s',
@@ -367,8 +367,8 @@ class ReportList implements ExportElementValidatedInterface, ListInterface
break;
default:
$prefix = substr((string) $f, 0, 7);
$suffix = substr((string) $f, 7);
$prefix = substr($f, 0, 7);
$suffix = substr($f, 7);
match ($prefix) {
'person_' => $qb->addSelect(sprintf('person.%s as %s', $suffix, $f)),

View File

@@ -61,7 +61,7 @@ abstract class AbstractTask implements HasCenterInterface, HasScopeInterface
private string $title = '';
#[Serializer\Groups(['read'])]
#[ORM\Column(name: 'type', type: \Doctrine\DBAL\Types\Types::STRING, length: 255)]
#[ORM\Column(name: 'type', type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
private ?string $type = null;
public function getAssignee(): ?User

View File

@@ -22,7 +22,7 @@ use Doctrine\ORM\Mapping as ORM;
#[ORM\Table(name: 'chill_task.recurring_task')]
class RecurringTask extends AbstractTask
{
#[ORM\Column(name: 'first_occurence_end_date', type: \Doctrine\DBAL\Types\Types::DATE_MUTABLE)]
#[ORM\Column(name: 'first_occurence_end_date', type: \Doctrine\DBAL\Types\Types::DATE_MUTABLE, nullable: true)]
private ?\DateTime $firstOccurenceEndDate = null;
#[ORM\Column(name: 'id', type: \Doctrine\DBAL\Types\Types::INTEGER)]
@@ -30,10 +30,10 @@ class RecurringTask extends AbstractTask
#[ORM\GeneratedValue(strategy: 'AUTO')]
private ?int $id = null;
#[ORM\Column(name: 'last_occurence_end_date', type: \Doctrine\DBAL\Types\Types::DATE_MUTABLE)]
#[ORM\Column(name: 'last_occurence_end_date', type: \Doctrine\DBAL\Types\Types::DATE_MUTABLE, nullable: true)]
private ?\DateTime $lastOccurenceEndDate = null;
#[ORM\Column(name: 'occurence_frequency', type: \Doctrine\DBAL\Types\Types::STRING, length: 255)]
#[ORM\Column(name: 'occurence_frequency', type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
private ?string $occurenceFrequency = null;
#[ORM\Column(name: 'occurence_start_date', type: \Doctrine\DBAL\Types\Types::DATEINTERVAL)]

View File

@@ -112,7 +112,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
* This field is read-only, and is generated on database side.
*/
#[ORM\Column(name: 'canonicalized', type: Types::TEXT, nullable: false, options: ['default' => ''])]
private ?string $canonicalized = '';
private string $canonicalized = '';
/**
* @var Collection<int, ThirdPartyCategory>
@@ -166,7 +166,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
#[Groups(['read', 'write', 'docgen:read', 'docgen:read:3party:parent'])]
#[ORM\Column(name: 'firstname', type: Types::TEXT, nullable: false, options: ['default' => ''])]
private ?string $firstname = '';
private string $firstname = '';
#[Groups(['read', 'docgen:read', 'docgen:read:3party:parent'])]
#[ORM\Column(name: 'id', type: Types::INTEGER)]

View File

@@ -28,9 +28,6 @@ final readonly class ImportTicketMotiveConfigurationCommand
string $lang,
OutputInterface $output,
): int {
$directory = (string) $directory;
$lang = (string) $lang;
$this->importMotivesFromDirectory->import($directory, $lang);
$output->writeln('<info>Ticket motives import completed successfully.</info>');

View File

@@ -48,7 +48,5 @@ class MotiveController extends CRUDController
$dto->applyToMotive($entity);
}
}
parent::onFormValid($action, $entity, $form, $request);
}
}

View File

@@ -57,8 +57,8 @@ class Motive
#[ORM\OneToMany(mappedBy: 'parent', targetEntity: Motive::class)]
private Collection&Selectable $children;
#[ORM\Column(name: 'ordering', type: \Doctrine\DBAL\Types\Types::FLOAT, nullable: true, options: ['default' => '0.0'])]
private float $ordering = 0;
#[ORM\Column(name: 'ordering', type: \Doctrine\DBAL\Types\Types::FLOAT, nullable: false, options: ['default' => '0.0'])]
private float $ordering = 0.0;
public function __construct()
{

View File

@@ -16,7 +16,8 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Entity\User;
use Chill\PersonBundle\Entity\Person;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Doctrine\ORM\Mapping\JoinColumn;
use Symfony\Component\Serializer\Attribute as Serializer;
/**
* Represents a history entity associated with a person and a ticket.
@@ -46,6 +47,7 @@ class PersonHistory implements TrackCreationInterface
public function __construct(
#[ORM\ManyToOne(targetEntity: Person::class, fetch: 'EAGER')]
#[JoinColumn(nullable: false)]
#[Serializer\Groups(['read'])]
private Person $person,
#[ORM\ManyToOne(targetEntity: Ticket::class)]

View File

@@ -16,11 +16,10 @@ use Chill\TicketBundle\Messenger\PostTicketUpdateMessage;
use Chill\TicketBundle\Repository\TicketRepositoryInterface;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
use Symfony\Component\Messenger\Exception\UnrecoverableMessageHandlingException;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
#[AsMessageHandler]
final readonly class PostTicketUpdateMessageHandler implements MessageHandlerInterface
final readonly class PostTicketUpdateMessageHandler
{
public function __construct(
private EventDispatcherInterface $eventDispatcher,

View File

@@ -52,8 +52,8 @@ final class TicketNormalizer implements NormalizerInterface, NormalizerAwareInte
'currentAddressees' => $this->normalizer->normalize($object->getCurrentAddressee(), $format, ['groups' => 'read']),
'currentInputs' => $this->normalizer->normalize($object->getCurrentInputs(), $format, ['groups' => 'read']),
'currentMotive' => $this->normalizer->normalize($object->getMotive(), $format, ['groups' => ['read', MotiveNormalizer::GROUP_CHILDREN_TO_PARENT]]),
'currentState' => $object->getState()?->value ?? 'open',
'emergency' => $object->getEmergencyStatus()?->value ?? 'no',
'currentState' => $object->getState()->value ?? 'open',
'emergency' => $object->getEmergencyStatus()->value ?? 'no',
'caller' => $this->normalizer->normalize($object->getCaller(), $format, ['groups' => 'read']),
];