mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-09-07 15:25:00 +00:00
apply more cs rules for php-cs
This commit is contained in:
@@ -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(
|
||||
|
Reference in New Issue
Block a user