apply more cs rules for php-cs

This commit is contained in:
2023-10-17 13:27:03 +02:00
parent 0b0cbed9db
commit bc2041cbdd
1485 changed files with 8169 additions and 9620 deletions

View File

@@ -11,14 +11,10 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity\Household;
use ArrayIterator;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use Chill\PersonBundle\Entity\Person;
use Chill\PersonBundle\Validator\Constraints\Household\MaxHolder;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\Criteria;
@@ -27,18 +23,19 @@ use Doctrine\Common\Collections\Selectable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
use function count;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_household"
* )
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "household": Household::class
* })
*
* @MaxHolder(groups={"household_memberships"})
*/
class Household
@@ -47,11 +44,15 @@ class Household
* Addresses.
*
* @var Collection<Address>
*
* @ORM\ManyToMany(
* targetEntity="Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove", "merge", "detach"})
*
* @ORM\JoinTable(name="chill_person_household_to_addresses")
*
* @ORM\OrderBy({"validFrom": "DESC", "id": "DESC"})
*
* @Serializer\Groups({"write"})
*/
private Collection $addresses;
@@ -63,46 +64,56 @@ class Household
/**
* @var Collection&Selectable<int, HouseholdComposition>
*
* @ORM\OneToMany(
* targetEntity=HouseholdComposition::class,
* mappedBy="household",
* orphanRemoval=true,
* cascade={"persist"}
* )
*
* @ORM\OrderBy({"startDate": "DESC"})
*
* @Assert\Valid(traverse=true, groups={"household_composition"})
*/
private Collection&Selectable $compositions;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @var Collection<HouseholdMember>
*
* @ORM\OneToMany(
* targetEntity=HouseholdMember::class,
* mappedBy="household"
* )
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private Collection $members;
/**
* @ORM\Column(type="boolean", name="waiting_for_birth", options={"default": false})
*
* @Serializer\Groups({"docgen:read"})
*/
private bool $waitingForBirth = false;
/**
* @ORM\Column(type="date_immutable", name="waiting_for_birth_date", nullable=true, options={"default": null})
*
* @Serializer\Groups({"docgen:read"})
*/
private ?DateTimeImmutable $waitingForBirthDate = null;
private ?\DateTimeImmutable $waitingForBirthDate = null;
public function __construct()
{
@@ -200,11 +211,12 @@ class Household
/**
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\SerializedName("current_address")
*/
public function getCurrentAddress(?DateTime $at = null): ?Address
public function getCurrentAddress(\DateTime $at = null): ?Address
{
$at ??= new DateTime('today');
$at ??= new \DateTime('today');
$addrs = $this->getAddresses()->filter(static fn (Address $a) => $a->getValidFrom() <= $at && (
null === $a->getValidTo() || $a->getValidTo() > $at
@@ -219,11 +231,12 @@ class Household
/**
* @Serializer\Groups({"docgen:read"})
*
* @Serializer\SerializedName("current_composition")
*/
public function getCurrentComposition(?DateTimeImmutable $at = null): ?HouseholdComposition
public function getCurrentComposition(\DateTimeImmutable $at = null): ?HouseholdComposition
{
$at ??= new DateTimeImmutable('today');
$at ??= new \DateTimeImmutable('today');
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -249,12 +262,12 @@ class Household
/**
* @Serializer\Groups({"docgen:read"})
*/
public function getCurrentMembers(?DateTimeImmutable $now = null): Collection
public function getCurrentMembers(\DateTimeImmutable $now = null): Collection
{
return $this->getMembers()->matching($this->buildCriteriaCurrentMembers($now));
}
public function getCurrentMembersByPosition(Position $position, ?DateTimeInterface $now = null)
public function getCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -270,9 +283,10 @@ class Household
* Used in serialization
*
* @Serializer\Groups({"read"})
*
* @Serializer\SerializedName("current_members_id")
*/
public function getCurrentMembersIds(?DateTimeImmutable $now = null): ReadableCollection
public function getCurrentMembersIds(\DateTimeImmutable $now = null): ReadableCollection
{
return $this->getCurrentMembers($now)->map(
static fn (HouseholdMember $m) => $m->getId()
@@ -282,22 +296,22 @@ class Household
/**
* @return HouseholdMember[]
*/
public function getCurrentMembersOrdered(?DateTimeImmutable $now = null): Collection
public function getCurrentMembersOrdered(\DateTimeImmutable $now = null): Collection
{
$members = $this->getCurrentMembers($now);
$members->getIterator()
->uasort(
static function (HouseholdMember $a, HouseholdMember $b) {
if ($a->getPosition() === null) {
if ($b->getPosition() === null) {
if (null === $a->getPosition()) {
if (null === $b->getPosition()) {
return 0;
}
return -1;
}
if ($b->getPosition() === null) {
if (null === $b->getPosition()) {
return 1;
}
@@ -324,7 +338,7 @@ class Household
return $members;
}
public function getCurrentMembersWithoutPosition(?DateTimeInterface $now = null)
public function getCurrentMembersWithoutPosition(\DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -341,7 +355,7 @@ class Household
*
* @return ReadableCollection<(int|string), Person>
*/
public function getCurrentPersons(?DateTimeImmutable $now = null): ReadableCollection
public function getCurrentPersons(\DateTimeImmutable $now = null): ReadableCollection
{
return $this->getCurrentMembers($now)
->map(static fn (HouseholdMember $m) => $m->getPerson());
@@ -387,7 +401,7 @@ class Household
return $this->getMembers()->matching($criteria);
}
public function getMembersOnRange(DateTimeImmutable $from, ?DateTimeImmutable $to): ReadableCollection
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) {
@@ -410,11 +424,11 @@ class Household
});
}
public function getNonCurrentMembers(?DateTimeImmutable $now = null): Collection
public function getNonCurrentMembers(\DateTimeImmutable $now = null): Collection
{
$criteria = new Criteria();
$expr = Criteria::expr();
$date = $now ?? new DateTimeImmutable('today');
$date = $now ?? new \DateTimeImmutable('today');
$criteria
->where(
@@ -430,7 +444,7 @@ class Household
return $this->getMembers()->matching($criteria);
}
public function getNonCurrentMembersByPosition(Position $position, ?DateTimeInterface $now = null)
public function getNonCurrentMembersByPosition(Position $position, \DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -440,7 +454,7 @@ class Household
return $this->getNonCurrentMembers($now)->matching($criteria);
}
public function getNonCurrentMembersWithoutPosition(?DateTimeInterface $now = null)
public function getNonCurrentMembersWithoutPosition(\DateTimeInterface $now = null)
{
$criteria = new Criteria();
$expr = Criteria::expr();
@@ -474,7 +488,7 @@ class Household
public function getPreviousAddressOf(Address $address): ?Address
{
$iterator = new ArrayIterator($this->getAddressesOrdered());
$iterator = new \ArrayIterator($this->getAddressesOrdered());
$iterator->rewind();
while ($iterator->valid()) {
@@ -496,7 +510,7 @@ class Household
return $this->waitingForBirth;
}
public function getWaitingForBirthDate(): ?DateTimeImmutable
public function getWaitingForBirthDate(): ?\DateTimeImmutable
{
return $this->waitingForBirthDate;
}
@@ -513,7 +527,7 @@ class Household
static fn (HouseholdComposition $a, HouseholdComposition $b) => $a->getStartDate() <=> $b->getStartDate()
);
$iterator = new ArrayIterator($compositionOrdered);
$iterator = new \ArrayIterator($compositionOrdered);
$iterator->rewind();
/** @var ?HouseholdComposition $previous */
@@ -535,7 +549,7 @@ class Household
public function makeAddressConsistent(): void
{
$iterator = new ArrayIterator($this->getAddressesOrdered());
$iterator = new \ArrayIterator($this->getAddressesOrdered());
$iterator->rewind();
@@ -597,7 +611,7 @@ class Household
*/
public function setForceAddress(Address $address)
{
$address->setValidFrom(new DateTime('today'));
$address->setValidFrom(new \DateTime('today'));
$this->addAddress($address);
}
@@ -608,7 +622,7 @@ class Household
return $this;
}
public function setWaitingForBirthDate(?DateTimeImmutable $waitingForBirthDate): self
public function setWaitingForBirthDate(?\DateTimeImmutable $waitingForBirthDate): self
{
$this->waitingForBirthDate = $waitingForBirthDate;
@@ -620,7 +634,7 @@ class Household
$addresses = $this->getAddresses();
$cond = true;
for ($i = 0; count($addresses) - 1 > $i; ++$i) {
for ($i = 0; \count($addresses) - 1 > $i; ++$i) {
if ($addresses[$i]->getValidFrom() !== $addresses[$i + 1]->getValidTo()) {
$cond = false;
$context->buildViolation('The address are not sequentials. The validFrom date of one address should be equal to the validTo date of the previous address.')
@@ -630,11 +644,11 @@ class Household
}
}
private function buildCriteriaCurrentMembers(?DateTimeImmutable $now = null): Criteria
private function buildCriteriaCurrentMembers(\DateTimeImmutable $now = null): Criteria
{
$criteria = new Criteria();
$expr = Criteria::expr();
$date = $now ?? new DateTimeImmutable('today');
$date = $now ?? new \DateTimeImmutable('today');
$criteria
->where($expr->orX(

View File

@@ -16,16 +16,17 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\Embeddable\CommentEmbeddable;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_household_composition"
* )
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "household_composition_type": HouseholdCompositionType::class
* })
@@ -43,46 +44,59 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Assert\GreaterThanOrEqual(propertyPath="startDate", groups={"Default", "household_composition"})
*
* @Serializer\Groups({"docgen:read"})
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\ManyToOne(targetEntity=Household::class, inversedBy="compositions")
*
* @ORM\JoinColumn(nullable=false)
*/
private ?Household $household = null;
/**
* @ORM\ManyToOne(targetEntity=HouseholdCompositionType::class)
*
* @ORM\JoinColumn(nullable=false)
*
* @Serializer\Groups({"docgen:read"})
*/
private ?HouseholdCompositionType $householdCompositionType = null;
private ?HouseholdCompositionType $householdCompositionType = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="integer", nullable=true, options={"default": null})
*
* @Assert\NotNull
*
* @Assert\GreaterThanOrEqual(0, groups={"Default", "household_composition"})
*
* @Serializer\Groups({"docgen:read"})
*/
private ?int $numberOfChildren = null;
/**
* @ORM\Column(type="date_immutable", nullable=false)
*
* @Assert\NotNull(groups={"Default", "household_composition"})
*
* @Serializer\Groups({"docgen:read"})
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
public function __construct()
{
@@ -94,7 +108,7 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
return $this->comment;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -119,7 +133,7 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
return $this->numberOfChildren;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
@@ -131,7 +145,7 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
return $this;
}
public function setEndDate(?DateTimeImmutable $endDate): HouseholdComposition
public function setEndDate(?\DateTimeImmutable $endDate): HouseholdComposition
{
$this->endDate = $endDate;
@@ -163,7 +177,7 @@ class HouseholdComposition implements TrackCreationInterface, TrackUpdateInterfa
return $this;
}
public function setStartDate(?DateTimeImmutable $startDate): HouseholdComposition
public function setStartDate(?\DateTimeImmutable $startDate): HouseholdComposition
{
$this->startDate = $startDate;

View File

@@ -16,9 +16,11 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_household_composition_type"
* )
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "household_composition_type": HouseholdCompositionType::class
* })
@@ -32,15 +34,20 @@ class HouseholdCompositionType
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $label = [];

View File

@@ -12,14 +12,13 @@ declare(strict_types=1);
namespace Chill\PersonBundle\Entity\Household;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use Doctrine\ORM\Mapping as ORM;
use LogicException;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
*
* @ORM\Table(
* name="chill_person_household_members"
* )
@@ -28,59 +27,71 @@ class HouseholdMember
{
/**
* @ORM\Column(type="string", length=255, nullable=true)
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?string $comment = null;
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Assert\GreaterThanOrEqual(
* propertyPath="startDate",
* message="household_membership.The end date must be after start date",
* groups={"household_memberships"}
* )
*/
private ?DateTimeImmutable $endDate = null;
private ?\DateTimeImmutable $endDate = null;
/**
* @ORM\Column(type="boolean", options={"default": false})
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private bool $holder = false;
/**
* @var Household
* @ORM\ManyToOne(
* targetEntity="\Chill\PersonBundle\Entity\Household\Household"
* )
*
* @Assert\Valid(groups={"household_memberships"})
*
* @Assert\NotNull(groups={"household_memberships"})
*/
private ?Household $household = null;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @var Person
* @ORM\ManyToOne(
* targetEntity="\Chill\PersonBundle\Entity\Person"
* )
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"docgen:person:with-household": false})
*
* @Assert\Valid(groups={"household_memberships"})
*
* @Assert\NotNull(groups={"household_memberships"})
*/
private ?Person $person = null;
/**
* @ORM\ManyToOne(targetEntity=Position::class)
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?Position $position = null;
@@ -92,17 +103,19 @@ class HouseholdMember
/**
* @ORM\Column(type="date_immutable", nullable=true, options={"default": null})
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Assert\NotNull(groups={"household_memberships"})
*/
private ?DateTimeImmutable $startDate = null;
private ?\DateTimeImmutable $startDate = null;
public function getComment(): ?string
{
return $this->comment;
}
public function getEndDate(): ?DateTimeImmutable
public function getEndDate(): ?\DateTimeImmutable
{
return $this->endDate;
}
@@ -135,14 +148,14 @@ class HouseholdMember
return $this->shareHousehold;
}
public function getStartDate(): ?DateTimeImmutable
public function getStartDate(): ?\DateTimeImmutable
{
return $this->startDate;
}
public function isCurrent(?DateTimeImmutable $at = null): bool
public function isCurrent(\DateTimeImmutable $at = null): bool
{
$at ??= new DateTimeImmutable('now');
$at ??= new \DateTimeImmutable('now');
return $this->getStartDate() < $at && (
null === $this->getEndDate() || $this->getEndDate() > $at
@@ -161,7 +174,7 @@ class HouseholdMember
return $this;
}
public function setEndDate(?DateTimeImmutable $endDate = null): self
public function setEndDate(\DateTimeImmutable $endDate = null): self
{
$this->endDate = $endDate;
@@ -178,8 +191,7 @@ class HouseholdMember
public function setHousehold(?Household $household): self
{
if ($this->household instanceof Household) {
throw new LogicException('You cannot change household ' .
'on a membership');
throw new \LogicException('You cannot change household on a membership');
}
$this->household = $household;
@@ -190,8 +202,7 @@ class HouseholdMember
public function setPerson(?Person $person): self
{
if ($this->person instanceof Person) {
throw new LogicException('You cannot change person ' .
'on a membership');
throw new \LogicException('You cannot change person on a membership');
}
$this->person = $person;
@@ -203,8 +214,7 @@ class HouseholdMember
public function setPosition(?Position $position): self
{
if ($this->position instanceof Position && $this->position !== $position) {
throw new LogicException('The position is already set. You cannot change ' .
'a position of a membership');
throw new \LogicException('The position is already set. You cannot change a position of a membership');
}
$this->position = $position;
@@ -223,7 +233,7 @@ class HouseholdMember
return $this;
}
public function setStartDate(DateTimeImmutable $startDate): self
public function setStartDate(\DateTimeImmutable $startDate): self
{
$this->startDate = $startDate;

View File

@@ -13,8 +13,6 @@ namespace Chill\PersonBundle\Entity\Household;
use Chill\MainBundle\Entity\Address;
use Chill\PersonBundle\Entity\Person;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\ORM\Mapping as ORM;
/**
@@ -42,27 +40,34 @@ use Doctrine\ORM\Mapping as ORM;
* 3. 3st entity: from 2021-12-01 to NULL, household V, address T;
*
* @ORM\Entity(readOnly=true)
*
* @ORM\Table(name="view_chill_person_household_address")
*/
class PersonHouseholdAddress
{
/**
* @ORM\Id
*
* @ORM\ManyToOne(targetEntity=Address::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private ?\Chill\MainBundle\Entity\Address $address = null;
/**
* @ORM\Id
*
* @ORM\ManyToOne(targetEntity=Household::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private ?\Chill\PersonBundle\Entity\Household\Household $household = null;
/**
* @ORM\Id
*
* @ORM\ManyToOne(targetEntity=Person::class)
*
* @ORM\JoinColumn(nullable=false)
*/
private ?\Chill\PersonBundle\Entity\Person $person = null;
@@ -98,7 +103,7 @@ class PersonHouseholdAddress
* (this is not the startdate of the household, not
* the startdate of the address)
*/
public function getValidFrom(): ?DateTimeInterface
public function getValidFrom(): ?\DateTimeInterface
{
return $this->validFrom;
}
@@ -109,7 +114,7 @@ class PersonHouseholdAddress
* (this is not the enddate of the household, not
* the enddate of the address)
*/
public function getValidTo(): ?DateTimeImmutable
public function getValidTo(): ?\DateTimeImmutable
{
return $this->validTo;
}

View File

@@ -16,7 +16,9 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Entity
*
* @ORM\Table(name="chill_person_household_position")
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "household_position": Position::class
* })
@@ -25,33 +27,41 @@ class Position
{
/**
* @ORM\Column(type="boolean")
*
* @Serializer\Groups({ "read" })
*/
private bool $allowHolder = false;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"read", "docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"read", "docgen:read"})
*
* @Serializer\Context({"is-translatable": true}, groups={"docgen:read"})
*/
private array $label = [];
/**
* @ORM\Column(type="float")
*
* @Serializer\Groups({"read"})
*/
private float $ordering = 0.00;
/**
* @ORM\Column(type="boolean")
*
* @Serializer\Groups({"read"})
*/
private bool $shareHouseHold = true;