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

@@ -19,8 +19,6 @@ use Chill\MainBundle\Entity\Civility;
use Chill\MainBundle\Entity\User;
use Chill\MainBundle\Validation\Constraint\PhonenumberConstraint;
use DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ReadableCollection;
@@ -30,15 +28,6 @@ use Symfony\Component\Serializer\Annotation\Context;
use Symfony\Component\Serializer\Annotation\DiscriminatorMap;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use UnexpectedValueException;
use function array_filter;
use function array_map;
use function array_merge;
use function array_values;
use function in_array;
use function is_string;
use function spl_object_hash;
/**
* ThirdParty is a party recorded in the database.
@@ -76,6 +65,7 @@ use function spl_object_hash;
* database by a Php array, mapped by a jsonb into the database. This has one advantage: it is easily searchable.
*
* As the list of type is hardcoded into database, it is more easily searchable. (for chill 2.0, the
*
* @see{Chill\ThirdPartyBundle\Form\Type\PickThirdPartyDynamicType} does not support it yet, but
* the legacy @see{Chill\ThirdPartyBundle\Form\Type\PickThirdPartyType} does.
*
@@ -83,7 +73,9 @@ use function spl_object_hash;
* noticing a difference.
*
* @ORM\Entity
*
* @ORM\Table(name="chill_3party.third_party")
*
* @DiscriminatorMap(typeProperty="type", mapping={
* "thirdparty": ThirdParty::class
* })
@@ -99,9 +91,10 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* [fr] Sigle.
*
* @var string
* @ORM\Column(name="acronym", type="string", length=64, nullable=true)
*
* @Assert\Length(min="2")
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/
private ?string $acronym = '';
@@ -116,8 +109,11 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* @ORM\ManyToOne(targetEntity="\Chill\MainBundle\Entity\Address",
* cascade={"persist", "remove"})
*
* @ORM\JoinColumn(nullable=true, onDelete="SET NULL")
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/
private ?Address $address = null;
@@ -133,18 +129,24 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* @var Collection<ThirdPartyCategory>
*
* @ORM\ManyToMany(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdPartyCategory")
*
* @ORM\JoinTable(name="chill_3party.thirdparty_category",
* joinColumns={@ORM\JoinColumn(name="thirdparty_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="category_id", referencedColumnName="id")})
*
* @Groups({"docgen:read", "docgen:read:3party:parent"})
*
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/
private Collection $categories;
/**
* @var Collection<Center>
*
* @ORM\ManyToMany(targetEntity="\Chill\MainBundle\Entity\Center")
*
* @ORM\JoinTable(name="chill_3party.party_center")
*/
private Collection $centers;
@@ -156,27 +158,31 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
* cascade={"persist"}, orphanRemoval=true)
*
* @var Collection<ThirdParty>
*
* @Assert\Valid(traverse=true)
*/
private Collection $children;
/**
* @var Civility
* @ORM\ManyToOne(targetEntity=Civility::class)
* ORM\JoinColumn(name="civility", referencedColumnName="id", nullable=true)
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/
private ?Civility $civility = null;
/**
* @ORM\Column(name="comment", type="text", nullable=true)
*
* @Groups({"read", "write"})
*/
private ?string $comment = null;
/**
* @ORM\Column(name="contact_data_anonymous", type="boolean", options={"default": false})
*
* @Groups({"read", "docgen:read", "docgen:read:3party:parent"})
*/
private bool $contactDataAnonymous = false;
@@ -184,48 +190,58 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* @ORM\Column(name="created_at", type="datetime_immutable", nullable=false)
*/
private DateTimeImmutable $createdAt;
private \DateTimeImmutable $createdAt;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
*
* @ORM\JoinColumn(name="created_by", referencedColumnName="id")
*/
private ?User $createdBy = null;
/**
* @ORM\Column(name="email", type="string", length=255, nullable=true)
*
* @Assert\Email()
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/
private ?string $email = null;
/**
* @ORM\Column(name="firstname", type="text", options={"default": ""})
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/
private string $firstname = '';
/**
* @var int
* @ORM\Column(name="id", type="integer")
*
* @ORM\Id
*
* @ORM\GeneratedValue(strategy="AUTO")
*
* @Groups({"read", "docgen:read", "docgen:read:3party:parent"})
*/
private ?int $id = null;
/**
* @ORM\Column(name="kind", type="string", length="20", options={"default": ""})
*
* @Groups({"write", "docgen:read", "docgen:read:3party:parent"})
*/
private ?string $kind = '';
/**
* @var string
* @ORM\Column(name="name", type="string", length=255)
*
* @Assert\Length(min="2")
*
* @Assert\NotNull
*
* @Assert\NotBlank
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/
private ?string $name = '';
@@ -233,9 +249,10 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* [fr] Raison sociale.
*
* @var string
* @ORM\Column(name="name_company", type="string", length=255, nullable=true)
*
* @Assert\Length(min="3")
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/
private ?string $nameCompany = '';
@@ -244,23 +261,31 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
* Institutional ThirdParty: Many Contact Persons have One Institutional ThirdParty.
*
* @ORM\ManyToOne(targetEntity="Chill\ThirdPartyBundle\Entity\ThirdParty", inversedBy="children")
*
* @ORM\JoinColumn(name="parent_id", referencedColumnName="id")
*
* @Groups({"read", "write", "docgen:read"})
*
* @Context(normalizationContext={"groups": "docgen:read:3party:parent"}, groups={"docgen:read"})
*/
private ?ThirdParty $parent = null;
/**
* [fr] Qualité.
*
* @ORM\Column(name="profession", type="text", nullable=false)
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*
* @Context(normalizationContext={"groups": "docgen:read"}, groups={"docgen:read:3party:parent"})
*/
private string $profession = '';
/**
* @ORM\Column(name="telephone", type="phone_number", nullable=true)
*
* @PhonenumberConstraint(type="any")
*
* @Groups({"read", "write", "docgen:read", "docgen:read:3party:parent"})
*/
private ?PhoneNumber $telephone = null;
@@ -273,10 +298,11 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* @ORM\Column(name="updated_at", type="datetime_immutable", nullable=true)
*/
private ?DateTimeImmutable $updatedAt = null;
private ?\DateTimeImmutable $updatedAt = null;
/**
* @ORM\ManyToOne(targetEntity="Chill\MainBundle\Entity\User")
*
* @ORM\JoinColumn(name="updated_by", referencedColumnName="id")
*/
private ?User $updatedBy = null;
@@ -291,9 +317,6 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
$this->children = new ArrayCollection();
}
/**
* @return string
*/
public function __toString(): string
{
return $this->getName();
@@ -355,7 +378,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
return $this;
}
if (!in_array($type, $this->thirdPartyTypes ?? [], true)) {
if (!\in_array($type, $this->thirdPartyTypes ?? [], true)) {
$this->thirdPartyTypes[] = $type;
}
@@ -374,21 +397,15 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
return $this;
}
if (is_string($typeAndCategory)) {
if (\is_string($typeAndCategory)) {
$this->addThirdPartyTypes($typeAndCategory);
return $this;
}
throw new UnexpectedValueException(sprintf(
'typeAndCategory should be a string or a %s',
ThirdPartyCategory::class
));
throw new \UnexpectedValueException(sprintf('typeAndCategory should be a string or a %s', ThirdPartyCategory::class));
}
/**
* @return string
*/
public function getAcronym(): ?string
{
return $this->acronym;
@@ -444,7 +461,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
return $this->comment;
}
public function getCreatedAt(): DateTimeImmutable
public function getCreatedAt(): \DateTimeImmutable
{
return $this->createdAt;
}
@@ -510,16 +527,16 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
public function getTypesAndCategories(): array
{
return array_merge(
return \array_merge(
$this->getCategories()->toArray(),
$this->getThirdPartyTypes() ?? []
);
}
/**
* @return DateTime|null
* @return \DateTime|null
*/
public function getUpdatedAt(): ?DateTimeImmutable
public function getUpdatedAt(): ?\DateTimeImmutable
{
return $this->updatedAt;
}
@@ -547,7 +564,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
*/
public function isLeaf(): bool
{
return $this->children->count() !== 0;
return 0 !== $this->children->count();
}
public function isParent(): bool
@@ -610,8 +627,8 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
return $this;
}
if (in_array($type, $this->thirdPartyTypes ?? [], true)) {
$this->thirdPartyTypes = array_filter($this->thirdPartyTypes, fn ($e) => !in_array($e, $this->thirdPartyTypes, true));
if (\in_array($type, $this->thirdPartyTypes ?? [], true)) {
$this->thirdPartyTypes = \array_filter($this->thirdPartyTypes, fn ($e) => !\in_array($e, $this->thirdPartyTypes, true));
}
foreach ($this->children as $child) {
@@ -629,22 +646,16 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
return $this;
}
if (is_string($typeAndCategory)) {
if (\is_string($typeAndCategory)) {
$this->removeThirdPartyTypes($typeAndCategory);
return $this;
}
throw new UnexpectedValueException(sprintf(
'typeAndCategory should be a string or a %s',
ThirdPartyCategory::class
));
throw new \UnexpectedValueException(sprintf('typeAndCategory should be a string or a %s', ThirdPartyCategory::class));
}
/**
* @param string $acronym
*/
public function setAcronym(?string $acronym = null): ThirdParty
public function setAcronym(string $acronym = null): ThirdParty
{
$this->acronym = (string) $acronym;
@@ -668,7 +679,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* @return $this
*/
public function setAddress(?Address $address = null)
public function setAddress(Address $address = null)
{
$this->address = $address;
@@ -703,10 +714,9 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* Set comment.
*
*
* @return ThirdParty
*/
public function setComment(?string $comment = null)
public function setComment(string $comment = null)
{
$this->comment = $comment;
@@ -721,11 +731,11 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
}
/**
* @param DateTimeImmutable $createdAt
* @param \DateTimeImmutable $createdAt
*
* @return $this
*/
public function setCreatedAt(DateTimeInterface $createdAt): ThirdParty
public function setCreatedAt(\DateTimeInterface $createdAt): ThirdParty
{
$this->createdAt = $createdAt;
@@ -742,10 +752,9 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* Set email.
*
*
* @return ThirdParty
*/
public function setEmail(?string $email = null)
public function setEmail(string $email = null)
{
$this->email = trim((string) $email);
@@ -773,9 +782,6 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
return $this;
}
/**
* @param string $nameCompany
*/
public function setNameCompany(?string $nameCompany): ThirdParty
{
$this->nameCompany = (string) $nameCompany;
@@ -800,7 +806,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
/**
* Set telephone.
*/
public function setTelephone(?PhoneNumber $telephone = null): self
public function setTelephone(PhoneNumber $telephone = null): self
{
$this->telephone = $telephone;
@@ -815,7 +821,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
public function setThirdPartyTypes(?array $type = [])
{
// remove all keys from the input data
$this->thirdPartyTypes = array_values($type);
$this->thirdPartyTypes = \array_values($type);
foreach ($this->children as $child) {
$child->setThirdPartyTypes($type);
@@ -826,7 +832,7 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
public function setTypesAndCategories(array $typesAndCategories): self
{
$types = array_filter($typesAndCategories, static fn ($item) => !$item instanceof ThirdPartyCategory);
$types = \array_filter($typesAndCategories, static fn ($item) => !$item instanceof ThirdPartyCategory);
$this->setThirdPartyTypes($types);
// handle categories
@@ -834,15 +840,15 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
$this->addTypesAndCategories($t);
}
$categories = array_filter($typesAndCategories, static fn ($item) => $item instanceof ThirdPartyCategory);
$categoriesHashes = array_map(static fn (ThirdPartyCategory $c) => spl_object_hash($c), $categories);
$categories = \array_filter($typesAndCategories, static fn ($item) => $item instanceof ThirdPartyCategory);
$categoriesHashes = \array_map(static fn (ThirdPartyCategory $c) => \spl_object_hash($c), $categories);
foreach ($categories as $c) {
$this->addCategory($c);
}
foreach ($this->getCategories() as $t) {
if (!in_array(spl_object_hash($t), $categoriesHashes, true)) {
if (!\in_array(\spl_object_hash($t), $categoriesHashes, true)) {
$this->removeCategory($t);
}
}
@@ -851,11 +857,11 @@ class ThirdParty implements TrackCreationInterface, TrackUpdateInterface, \Strin
}
/**
* @param DateTimeImmutable $updatedAt
* @param \DateTimeImmutable $updatedAt
*
* @return $this
*/
public function setUpdatedAt(DateTimeInterface $updatedAt): ThirdParty
public function setUpdatedAt(\DateTimeInterface $updatedAt): ThirdParty
{
$this->updatedAt = $updatedAt;

View File

@@ -17,6 +17,7 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_3party.party_category")
*
* @ORM\Entity(repositoryClass=ThirdPartyCategoryRepository::class)
*/
class ThirdPartyCategory
@@ -28,14 +29,18 @@ class ThirdPartyCategory
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"docgen:read"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"docgen:read"})
*/
private array $name = [];

View File

@@ -17,7 +17,9 @@ use Symfony\Component\Serializer\Annotation as Serializer;
/**
* @ORM\Table(name="chill_3party.party_profession")
*
* @ORM\Entity(repositoryClass=ThirdPartyProfessionRepository::class)
*
* @Serializer\DiscriminatorMap(typeProperty="type", mapping={
* "third_party_profession": ThirdPartyProfession::class})
*/
@@ -25,20 +27,25 @@ class ThirdPartyProfession
{
/**
* @ORM\Column(type="boolean")
*
* @Serializer\Groups({"read"})
*/
private bool $active = true;
/**
* @ORM\Id
*
* @ORM\GeneratedValue
*
* @ORM\Column(type="integer")
*
* @Serializer\Groups({"docgen:read", "read", "write"})
*/
private ?int $id = null;
/**
* @ORM\Column(type="json")
*
* @Serializer\Groups({"docgen:read", "read"})
*/
private array $name = [];