Merge remote-tracking branch 'origin/master' into refactor-using-rector-202303

This commit is contained in:
2023-04-15 00:07:09 +02:00
143 changed files with 3395 additions and 1300 deletions

View File

@@ -12,6 +12,10 @@ declare(strict_types=1);
namespace Chill\MainBundle\Entity;
use Chill\MainBundle\Doctrine\Model\Point;
use Chill\MainBundle\Doctrine\Model\TrackCreationInterface;
use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTime;
use DateTimeInterface;
@@ -28,8 +32,28 @@ use Symfony\Component\Validator\Context\ExecutionContextInterface;
* @ORM\Table(name="chill_main_address")
* @ORM\HasLifecycleCallbacks
*/
class Address
class Address implements TrackCreationInterface, TrackUpdateInterface
{
use TrackCreationTrait;
use TrackUpdateTrait;
/**
* When an Address does match with the AddressReference
*/
public const ADDR_REFERENCE_STATUS_MATCH = 'match';
/**
* When an Address does not match with the AddressReference, and
* is pending for a review
*/
public const ADDR_REFERENCE_STATUS_TO_REVIEW = 'to_review';
/**
* When an Address does not match with the AddressReference, but
* is reviewed
*/
public const ADDR_REFERENCE_STATUS_REVIEWED = 'reviewed';
/**
* @ORM\ManyToOne(targetEntity=AddressReference::class)
* @Groups({"write"})
@@ -37,67 +61,48 @@ class Address
private ?AddressReference $addressReference = null;
/**
* @var string|null
*
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private $buildingName;
private string $buildingName = '';
/**
* @ORM\Column(type="boolean")
* @ORM\Column(type="boolean", options={"default": false})
* @Groups({"write"})
*/
private bool $confidential = false;
/**
* @var string|null
*
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private $corridor;
private string $corridor = '';
/**
* A list of metadata, added by customizable fields.
*
* @var array
*/
private $customs = [];
/**
* @var string|null
*
* used for the CEDEX information
*
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private $distribution;
private string $distribution = '';
/**
* @var string|null
*
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private $extra;
private string $extra = '';
/**
* @var string|null
*
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private $flat;
private string $flat = '';
/**
* @var string|null
*
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private $floor;
private string $floor = '';
/**
* List of geographical units and addresses.
@@ -131,11 +136,9 @@ class Address
* True if the address is a "no address", aka homeless person, ...
*
* @Groups({"write"})
* @ORM\Column(type="boolean")
*
* @var bool
* @ORM\Column(type="boolean", options={"default": false})
*/
private $isNoAddress = false;
private bool $isNoAddress = false;
/**
* A ThirdParty reference for person's addresses that are linked to a third party.
@@ -146,7 +149,7 @@ class Address
* @Groups({"write"})
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*/
private $linkedToThirdParty;
private ?ThirdParty $linkedToThirdParty;
/**
* A geospatial field storing the coordinates of the Address.
@@ -156,7 +159,7 @@ class Address
* @ORM\Column(type="point", nullable=true)
* @Groups({"write"})
*/
private $point;
private ?Point $point = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode")
@@ -166,28 +169,36 @@ class Address
private ?PostalCode $postcode = null;
/**
* @var string|null
*
* @ORM\Column(type="string", length=255, nullable=true)
* @Groups({"write"})
* @var self::ADDR_REFERENCE_STATUS_*
* @ORM\Column(type="text", nullable=false, options={"default": self::ADDR_REFERENCE_STATUS_MATCH})
*/
private $steps;
private string $refStatus = self::ADDR_REFERENCE_STATUS_MATCH;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
* @Groups({"write"})
* @ORM\Column(type="datetime_immutable", nullable=false, options={"default": "CURRENT_TIMESTAMP"})
*/
private $street = '';
private \DateTimeImmutable $refStatusLastUpdate;
/**
* @var string
*
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private $streetNumber = '';
private string $steps = '';
/**
*
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private string $street = '';
/**
*
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Groups({"write"})
*/
private string $streetNumber = '';
/**
* Indicates when the address starts validation. Used to build an history
@@ -210,6 +221,7 @@ class Address
public function __construct()
{
$this->validFrom = new DateTime();
$this->refStatusLastUpdate = new \DateTimeImmutable('now');
$this->geographicalUnits = new ArrayCollection();
}
@@ -220,7 +232,6 @@ class Address
->setBuildingName($original->getBuildingName())
->setConfidential($original->getConfidential())
->setCorridor($original->getCorridor())
->setCustoms($original->getCustoms())
->setDistribution($original->getDistribution())
->setExtra($original->getExtra())
->setFlat($original->getFlat())
@@ -239,11 +250,20 @@ class Address
public static function createFromAddressReference(AddressReference $original): Address
{
return (new Address())
->setPoint($original->getPoint())
->setPostcode($original->getPostcode())
->setStreet($original->getStreet())
->setStreetNumber($original->getStreetNumber())
->setAddressReference($original);
->syncWithReference($original);
}
public function syncWithReference(AddressReference $addressReference): Address
{
$this
->setPoint($addressReference->getPoint())
->setPostcode($addressReference->getPostcode())
->setStreet($addressReference->getStreet())
->setStreetNumber($addressReference->getStreetNumber())
->setRefStatus(self::ADDR_REFERENCE_STATUS_MATCH)
->setAddressReference($addressReference);
return $this;
}
public function getAddressReference(): ?AddressReference
@@ -251,7 +271,7 @@ class Address
return $this->addressReference;
}
public function getBuildingName(): ?string
public function getBuildingName(): string
{
return $this->buildingName;
}
@@ -261,35 +281,27 @@ class Address
return $this->confidential;
}
public function getCorridor(): ?string
public function getCorridor(): string
{
return $this->corridor;
}
/**
* Get customs informations in the address.
*/
public function getCustoms(): array
{
return $this->customs;
}
public function getDistribution(): ?string
public function getDistribution(): string
{
return $this->distribution;
}
public function getExtra(): ?string
public function getExtra(): string
{
return $this->extra;
}
public function getFlat(): ?string
public function getFlat(): string
{
return $this->flat;
}
public function getFloor(): ?string
public function getFloor(): string
{
return $this->floor;
}
@@ -340,12 +352,22 @@ class Address
return $this->postcode;
}
public function getSteps(): ?string
public function getRefStatus(): string
{
return $this->refStatus;
}
public function getRefStatusLastUpdate(): \DateTimeImmutable
{
return $this->refStatusLastUpdate;
}
public function getSteps(): string
{
return $this->steps;
}
public function getStreet(): ?string
public function getStreet(): string
{
return $this->street;
}
@@ -354,6 +376,7 @@ class Address
* Get streetAddress1 (legacy function).
*
* @return string
* @deprecated
*/
public function getStreetAddress1()
{
@@ -364,13 +387,14 @@ class Address
* Get streetAddress2 (legacy function).
*
* @return string
* @deprecated
*/
public function getStreetAddress2()
{
return $this->streetNumber;
}
public function getStreetNumber(): ?string
public function getStreetNumber(): string
{
return $this->streetNumber;
}
@@ -378,7 +402,7 @@ class Address
/**
* @return DateTime
*/
public function getValidFrom()
public function getValidFrom(): DateTime
{
return $this->validFrom;
}
@@ -407,7 +431,7 @@ class Address
public function setBuildingName(?string $buildingName): self
{
$this->buildingName = $buildingName;
$this->buildingName = (string) $buildingName;
return $this;
}
@@ -421,47 +445,35 @@ class Address
public function setCorridor(?string $corridor): self
{
$this->corridor = $corridor;
return $this;
}
/**
* Store custom informations in the address.
*
* @return $this
*/
public function setCustoms(array $customs): self
{
$this->customs = $customs;
$this->corridor = (string) $corridor;
return $this;
}
public function setDistribution(?string $distribution): self
{
$this->distribution = $distribution;
$this->distribution = (string) $distribution;
return $this;
}
public function setExtra(?string $extra): self
{
$this->extra = $extra;
$this->extra = (string) $extra;
return $this;
}
public function setFlat(?string $flat): self
{
$this->flat = $flat;
$this->flat = (string) $flat;
return $this;
}
public function setFloor(?string $floor): self
{
$this->floor = $floor;
$this->floor = (string) $floor;
return $this;
}
@@ -508,25 +520,55 @@ class Address
return $this;
}
/**
* Update the ref status
*
* <<<<<<< HEAD
* @param Address::ADDR_REFERENCE_STATUS_* $refStatus
* @param bool|null $updateLastUpdate Also update the "refStatusLastUpdate"
* =======
* The refstatuslast update is also updated
* >>>>>>> 31152616d (Feature: Provide api endpoint for reviewing addresses)
*/
public function setRefStatus(string $refStatus, ?bool $updateLastUpdate = true): self
{
$this->refStatus = $refStatus;
if ($updateLastUpdate) {
$this->setRefStatusLastUpdate(new \DateTimeImmutable('now'));
}
return $this;
}
public function setRefStatusLastUpdate(\DateTimeImmutable $refStatusLastUpdate): self
{
$this->refStatusLastUpdate = $refStatusLastUpdate;
return $this;
}
public function setSteps(?string $steps): self
{
$this->steps = $steps;
$this->steps = (string) $steps;
return $this;
}
public function setStreet(?string $street): self
{
if (null === $street) {
$street = '';
}
$this->street = $street;
$this->street = (string) $street;
return $this;
}
/**
* Set streetAddress1 (legacy function).
*
* @param string $streetAddress1
*
* @return Address
* @deprecated
*/
public function setStreetAddress1(?string $streetAddress1): self
{
@@ -537,6 +579,10 @@ class Address
/**
* Set streetAddress2 (legacy function).
*
* @param string $streetAddress2
* @deprecated
* @return Address
*/
public function setStreetAddress2(?string $streetAddress2): self
{
@@ -547,10 +593,7 @@ class Address
public function setStreetNumber(?string $streetNumber): self
{
if (null === $streetNumber) {
$streetNumber = '';
}
$this->streetNumber = $streetNumber;
$this->streetNumber = (string) $streetNumber;
return $this;
}
@@ -597,7 +640,7 @@ class Address
return;
}
if (empty($this->getStreetAddress1())) {
if ('' === $this->getStreet()) {
$context
->buildViolation('address.street1-should-be-set')
->atPath('streetAddress1')

View File

@@ -55,13 +55,13 @@ class AddressReference
* @ORM\Column(type="integer")
* @groups({"read"})
*/
private $id;
private ?int $id;
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @groups({"read"})
*/
private $municipalityCode;
private string $municipalityCode = '';
/**
* A geospatial field storing the coordinates of the Address.
@@ -71,7 +71,7 @@ class AddressReference
* @ORM\Column(type="point")
* @groups({"read"})
*/
private $point;
private ?Point $point = null;
/**
* @var PostalCode
@@ -79,31 +79,31 @@ class AddressReference
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\PostalCode")
* @groups({"read"})
*/
private $postcode;
private ?PostalCode $postcode;
/**
* @ORM\Column(type="string", length=255)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @groups({"read"})
*/
private $refId;
private string $refId = '';
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @groups({"read"})
*/
private $source;
private string $source = '';
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @groups({"read"})
*/
private $street;
private string $street = '';
/**
* @ORM\Column(type="string", length=255, nullable=true)
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @groups({"read"})
*/
private $streetNumber;
private string $streetNumber = '';
/**
* @ORM\Column(type="datetime_immutable", nullable=true)
@@ -126,7 +126,7 @@ class AddressReference
return $this->id;
}
public function getMunicipalityCode(): ?string
public function getMunicipalityCode(): string
{
return $this->municipalityCode;
}
@@ -141,27 +141,27 @@ class AddressReference
*
* @return PostalCode
*/
public function getPostcode()
public function getPostcode(): ?PostalCode
{
return $this->postcode;
}
public function getRefId(): ?string
public function getRefId(): string
{
return $this->refId;
}
public function getSource(): ?string
public function getSource(): string
{
return $this->source;
}
public function getStreet(): ?string
public function getStreet(): string
{
return $this->street;
}
public function getStreetNumber(): ?string
public function getStreetNumber(): string
{
return $this->streetNumber;
}
@@ -192,7 +192,7 @@ class AddressReference
public function setMunicipalityCode(?string $municipalityCode): self
{
$this->municipalityCode = $municipalityCode;
$this->municipalityCode = (string) $municipalityCode;
return $this;
}
@@ -227,21 +227,21 @@ class AddressReference
public function setSource(?string $source): self
{
$this->source = $source;
$this->source = (string) $source;
return $this;
}
public function setStreet(?string $street): self
{
$this->street = $street;
$this->street = (string) $street;
return $this;
}
public function setStreetNumber(?string $streetNumber): self
{
$this->streetNumber = $streetNumber;
$this->streetNumber = (string) $streetNumber;
return $this;
}

View File

@@ -11,6 +11,8 @@ declare(strict_types=1);
namespace Chill\MainBundle\Entity\GeographicalUnit;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* Simple GeographialUnit Data Transfer Object.
*
@@ -21,24 +23,28 @@ class SimpleGeographicalUnitDTO
/**
* @readonly
* @psalm-readonly
* @Serializer\Groups({"read"})
*/
public int $id;
/**
* @readonly
* @psalm-readonly
* @Serializer\Groups({"read"})
*/
public int $layerId;
/**
* @readonly
* @psalm-readonly
* @Serializer\Groups({"read"})
*/
public string $unitName;
/**
* @readonly
* @psalm-readonly
* @Serializer\Groups({"read"})
*/
public string $unitRefId;

View File

@@ -14,6 +14,7 @@ namespace Chill\MainBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_main_geographical_unit_layer", uniqueConstraints={
@@ -27,16 +28,19 @@ class GeographicalUnitLayer
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Serializer\Groups({"read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json", nullable=false, options={"default": "[]"})
* @Serializer\Groups({"read"})
*/
private array $name = [];
/**
* @ORM\Column(type="text", nullable=false, options={"default": ""})
* @Serializer\Groups({"read"})
*/
private string $refId = '';

View File

@@ -16,6 +16,7 @@ use Chill\MainBundle\Doctrine\Model\TrackCreationTrait;
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
use Chill\MainBundle\Doctrine\Model\TrackUpdateTrait;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Validator\Constraints\Entity\WorkflowStepUsersOnTransition;
use Chill\MainBundle\Workflow\Validator\EntityWorkflowCreation;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
@@ -24,6 +25,7 @@ use Doctrine\ORM\Mapping as ORM;
use Iterator;
use RuntimeException;
use Symfony\Component\Serializer\Annotation as Serializer;
use Symfony\Component\Validator\Constraints as Assert;
use function count;
use function is_array;
@@ -41,6 +43,13 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
use TrackUpdateTrait;
/**
* a list of future cc users for the next steps.
*
* @var array|User[]
*/
public array $futureCcUsers = [];
/**
* a list of future dest emails for the next steps.
*
@@ -90,7 +99,7 @@ class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
/**
* @ORM\OneToMany(targetEntity=EntityWorkflowStep::class, mappedBy="entityWorkflow", orphanRemoval=true, cascade={"persist"})
* @ORM\OrderBy({"transitionAt": "ASC", "id": "ASC"})
*
* @Assert\Valid(traverse=true)
* @var Collection|EntityWorkflowStep[]
*/
private Collection $steps;

View File

@@ -32,6 +32,12 @@ class EntityWorkflowStep
*/
private string $accessKey;
/**
* @ORM\ManyToMany(targetEntity=User::class)
* @ORM\JoinTable(name="chill_main_workflow_entity_step_cc_user")
*/
private Collection $ccUser;
/**
* @ORM\Column(type="text", options={"default": ""})
*/
@@ -114,11 +120,21 @@ class EntityWorkflowStep
public function __construct()
{
$this->ccUser = new ArrayCollection();
$this->destUser = new ArrayCollection();
$this->destUserByAccessKey = new ArrayCollection();
$this->accessKey = bin2hex(openssl_random_pseudo_bytes(32));
}
public function addCcUser(User $user): self
{
if (!$this->ccUser->contains($user)) {
$this->ccUser[] = $user;
}
return $this;
}
public function addDestEmail(string $email): self
{
if (!in_array($email, $this->destEmail, true)) {
@@ -167,6 +183,11 @@ class EntityWorkflowStep
);
}
public function getCcUser(): Collection
{
return $this->ccUser;
}
public function getComment(): string
{
return $this->comment;
@@ -261,6 +282,13 @@ class EntityWorkflowStep
return true;
}
public function removeCcUser(User $user): self
{
$this->ccUser->removeElement($user);
return $this;
}
public function removeDestEmail(string $email): self
{
$this->destEmail = array_filter($this->destEmail, static function (string $existing) use ($email) {