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,7 +19,6 @@ use Chill\MainBundle\Templating\Listing\FilterOrderHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Repository\ThirdPartyACLAwareRepositoryInterface;
use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter;
use LogicException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -28,8 +27,6 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_merge;
final class ThirdPartyController extends CRUDController
{
private readonly bool $askCenter;
@@ -57,15 +54,15 @@ final class ThirdPartyController extends CRUDController
return $this->getFilterOrderHelperFactory()
->create(self::class)
->addSearchBox(['name', 'company_name', 'acronym'])
//->addToggle('only-active', [])
// ->addToggle('only-active', [])
// ->addOrderBy()
->build();
}
protected function countEntities(string $action, Request $request, ?FilterOrderHelper $filterOrder = null): int
protected function countEntities(string $action, Request $request, FilterOrderHelper $filterOrder = null): int
{
if (null === $filterOrder) {
throw new LogicException('filterOrder should not be null');
throw new \LogicException('filterOrder should not be null');
}
return $this->thirdPartyACLAwareRepository->countThirdParties(
@@ -74,17 +71,17 @@ final class ThirdPartyController extends CRUDController
);
}
protected function createFormFor(string $action, $entity, ?string $formClass = null, array $formOptions = []): FormInterface
protected function createFormFor(string $action, $entity, string $formClass = null, array $formOptions = []): FormInterface
{
if ('new' === $action) {
return parent::createFormFor($action, $entity, $formClass, array_merge(
return parent::createFormFor($action, $entity, $formClass, \array_merge(
$formOptions,
['kind' => $this->requestStack->getCurrentRequest()->query->getAlpha('kind')]
));
}
if ('edit' === $action) {
return parent::createFormFor($action, $entity, $formClass, array_merge(
return parent::createFormFor($action, $entity, $formClass, \array_merge(
$formOptions,
['kind' => $entity->getKind()]
));
@@ -93,7 +90,7 @@ final class ThirdPartyController extends CRUDController
return parent::createFormFor($action, $entity, $formClass, $formOptions);
}
protected function getQueryResult(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, ?FilterOrderHelper $filterOrder = null)
protected function getQueryResult(string $action, Request $request, int $totalItems, PaginatorInterface $paginator, FilterOrderHelper $filterOrder = null)
{
return $this->thirdPartyACLAwareRepository
->listThirdParties(
@@ -120,7 +117,7 @@ final class ThirdPartyController extends CRUDController
$kind = $request->query->getAlpha('kind', '');
if (!(ThirdParty::KIND_COMPANY === $kind || ThirdParty::KIND_CONTACT === $kind)) {
throw new BadRequestHttpException('This kind is not supported: ' . $kind);
throw new BadRequestHttpException('This kind is not supported: '.$kind);
}
$entity->setKind($kind);
@@ -130,7 +127,6 @@ final class ThirdPartyController extends CRUDController
}
/**
* @param $action
* @param ThirdParty $entity
*/
protected function onPostFetchEntity($action, Request $request, $entity): ?Response

View File

@@ -16,18 +16,13 @@ use Chill\MainBundle\DataFixtures\ORM\LoadPostalCodes;
use Chill\MainBundle\Entity\Address;
use Chill\MainBundle\Entity\PostalCode;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use DateTimeImmutable;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
use Iterator;
use libphonenumber\PhoneNumberUtil;
use Nelmio\Alice\Loader\NativeLoader;
use Nelmio\Alice\ObjectSet;
use function array_map;
use function count;
class LoadThirdParty extends Fixture implements DependentFixtureInterface
{
private readonly PhoneNumberUtil $phoneNumberUtil;
@@ -54,7 +49,7 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
// this is an address
continue;
}
$thirdParty->setCreatedAt(new DateTimeImmutable('today'));
$thirdParty->setCreatedAt(new \DateTimeImmutable('today'));
foreach ($this->getCenters() as $center) {
$thirdParty->addCenter($center);
@@ -66,13 +61,13 @@ class LoadThirdParty extends Fixture implements DependentFixtureInterface
$manager->flush();
}
private function getCenters(): Iterator
private function getCenters(): \Iterator
{
$references = array_map(
$references = \array_map(
static fn ($a) => $a['ref'],
LoadCenters::$centers
);
$number = random_int(1, count($references));
$number = random_int(1, \count($references));
if (1 === $number) {
yield $this->getReference($references[array_rand($references)]);

View File

@@ -41,7 +41,7 @@ class LoadThirdPartyCategory extends Fixture implements FixtureGroupInterface
];
foreach ($categories as $val) {
echo 'Creating thirdparty category : ' . $val['name']['fr'] . "\n";
echo 'Creating thirdparty category : '.$val['name']['fr']."\n";
$category = (new ThirdPartyCategory())
->setName($val['name'])
->setActive(true);

View File

@@ -39,7 +39,7 @@ class LoadThirdPartyProfession extends Fixture implements FixtureGroupInterface
];
foreach ($professions as $val) {
echo 'Creating thirdparty professions : ' . $val['name']['fr'] . "\n";
echo 'Creating thirdparty professions : '.$val['name']['fr']."\n";
$profession = (new ThirdPartyProfession())
->setName($val['name'])
->setActive(true);

View File

@@ -37,7 +37,7 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../config'));
$loader->load('services.yaml');
$loader->load('services/controller.yaml');
$loader->load('services/form.yaml');
@@ -70,7 +70,7 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
protected function preprendRoutes(ContainerBuilder $container)
{
//declare routes for 3party bundle
// declare routes for 3party bundle
$container->prependExtensionConfig('chill_main', [
'routing' => [
'resources' => [
@@ -130,8 +130,8 @@ class ChillThirdPartyExtension extends Extension implements PrependExtensionInte
'class' => \Chill\ThirdPartyBundle\Entity\ThirdParty::class,
'name' => 'thirdparty',
'base_path' => '/api/1.0/thirdparty/thirdparty',
//'base_role' => \Chill\ThirdPartyBundle\Security\Authorization\ThirdPartyVoter::SHOW,
//'controller' => \Chill\ThirdPartyBundle\Controller\ThirdPartyApiController::class,
// 'base_role' => \Chill\ThirdPartyBundle\Security\Authorization\ThirdPartyVoter::SHOW,
// 'controller' => \Chill\ThirdPartyBundle\Controller\ThirdPartyApiController::class,
'actions' => [
'_entity' => [
'methods' => [

View File

@@ -12,13 +12,10 @@ declare(strict_types=1);
namespace Chill\ThirdPartyBundle\DependencyInjection\CompilerPass;
use Chill\ThirdPartyBundle\ThirdPartyType\ThirdPartyTypeManager;
use LogicException;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Reference;
use function in_array;
/**
* Load services tagged chill_3party.provider and add them to the service
* definition of manager.
@@ -37,11 +34,8 @@ class ThirdPartyTypeCompilerPass implements CompilerPassInterface
// check forr keys already in use :
$key = $taggedService->getClass()::getKey();
if (in_array($key, $usedKeys, true)) {
throw new LogicException(sprintf(
'Tag with key "%s" is already in used',
$key
));
if (\in_array($key, $usedKeys, true)) {
throw new \LogicException(sprintf('Tag with key "%s" is already in used', $key));
}
$usedKeys[] = $key;
// alter the service definition of manager

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 = [];

View File

@@ -13,14 +13,12 @@ namespace Chill\ThirdPartyBundle\EventListener;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use const MB_CASE_TITLE;
class ThirdPartyEventListener
{
public function prePersistThirdParty(ThirdParty $thirdparty): void
{
if ($thirdparty->getKind() !== 'company') {
$firstnameCaps = mb_convert_case(mb_strtolower($thirdparty->getFirstname()), MB_CASE_TITLE, 'UTF-8');
if ('company' !== $thirdparty->getKind()) {
$firstnameCaps = mb_convert_case(mb_strtolower($thirdparty->getFirstname()), \MB_CASE_TITLE, 'UTF-8');
$firstnameCaps = ucwords(strtolower($firstnameCaps), " \t\r\n\f\v'-");
$thirdparty->setFirstName($firstnameCaps);

View File

@@ -13,8 +13,6 @@ namespace Chill\ThirdPartyBundle\Export\Helper;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use Chill\ThirdPartyBundle\Templating\Entity\ThirdPartyRender;
use function count;
use const SORT_NUMERIC;
class LabelThirdPartyHelper
{
@@ -48,7 +46,7 @@ class LabelThirdPartyHelper
$decoded = json_decode((string) $value, null, 512, JSON_THROW_ON_ERROR);
if (0 === count($decoded)) {
if (0 === \count($decoded)) {
return '';
}
@@ -67,7 +65,7 @@ class LabelThirdPartyHelper
},
array_unique(
array_filter($decoded, static fn (?int $id) => null !== $id),
SORT_NUMERIC
\SORT_NUMERIC
)
)
);

View File

@@ -13,14 +13,10 @@ namespace Chill\ThirdPartyBundle\Form\ChoiceLoader;
use Chill\MainBundle\Entity\Center;
use Doctrine\ORM\EntityRepository;
use RuntimeException;
use Symfony\Component\Form\ChoiceList\ArrayChoiceList;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use function call_user_func;
use function in_array;
/**
* Lazy load third parties.
*
@@ -61,8 +57,8 @@ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface
foreach ($values as $value) {
$party = $this->partyRepository->find($value);
if (false === in_array($this->center, $party->getCenters()->toArray(), true)) {
throw new RuntimeException("the party's center is not authorized");
if (false === \in_array($this->center, $party->getCenters()->toArray(), true)) {
throw new \RuntimeException("the party's center is not authorized");
}
$choices[] = $party;
@@ -82,7 +78,7 @@ class ThirdPartyChoiceLoader implements ChoiceLoaderInterface
continue;
}
$id = call_user_func($value, $choice);
$id = \call_user_func($value, $choice);
$values[] = $id;
$this->lazyLoadedParties[$id] = $choice;
}

View File

@@ -34,8 +34,6 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use function array_key_exists;
class ThirdPartyType extends AbstractType
{
private readonly bool $askCenter;
@@ -71,7 +69,7 @@ class ThirdPartyType extends AbstractType
if ($this->askCenter) {
$builder
->add('centers', PickCenterType::class, [
'role' => (array_key_exists('data', $options) && $this->om->contains($options['data'])) ?
'role' => (\array_key_exists('data', $options) && $this->om->contains($options['data'])) ?
ThirdPartyVoter::UPDATE : ThirdPartyVoter::CREATE,
'choice_options' => [
'multiple' => true,

View File

@@ -24,13 +24,9 @@ use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_diff;
use function array_merge;
use function count;
use function is_array;
/**
* @deprecated use the @link{PickThirdPartyDynamicType::class}
* @deprecated use the @see{PickThirdPartyDynamicType::class}
*
* @note do remove ThirdPartyChoiceLoader if this class is removed
*/
class PickThirdPartyType extends AbstractType
@@ -69,7 +65,7 @@ class PickThirdPartyType extends AbstractType
public function buildView(\Symfony\Component\Form\FormView $view, \Symfony\Component\Form\FormInterface $form, array $options)
{
$view->vars['attr']['class'] = array_merge(['select2 '], $view->vars['attr']['class'] ?? []);
$view->vars['attr']['class'] = \array_merge(['select2 '], $view->vars['attr']['class'] ?? []);
$view->vars['attr']['data-3party-picker'] = true;
$view->vars['attr']['data-select-interactive-loading'] = true;
$view->vars['attr']['data-search-url'] = $this->urlGenerator
@@ -94,11 +90,12 @@ class PickThirdPartyType extends AbstractType
->setDefined('types')
->setRequired('types')
->setAllowedValues('types', function ($types) {
if (false === is_array($types)) {
if (false === \is_array($types)) {
return false;
}
// return false if one element is not contained in allowed types
return count(array_diff($types, $this->typesManager->getTypes())) === 0;
return 0 === \count(\array_diff($types, $this->typesManager->getTypes()));
});
$resolver

View File

@@ -20,12 +20,6 @@ use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Contracts\Translation\TranslatorInterface;
use function array_merge;
use function implode;
use function is_array;
use function is_string;
use function uasort;
class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractType
{
private const PREFIX_TYPE = 'chill_3party.key_label.';
@@ -34,16 +28,16 @@ class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractTyp
public function configureOptions(OptionsResolver $resolver)
{
$choices = array_merge(
$choices = \array_merge(
$this->thirdPartyCategoryRepository->findBy(['active' => true]),
$this->thirdPartyTypeManager->getTypes()
);
uasort($choices, function ($itemA, $itemB) {
\uasort($choices, function ($itemA, $itemB) {
$strA = $itemA instanceof ThirdPartyCategory ? $this->translatableStringHelper
->localize($itemA->getName()) : $this->translator->trans(self::PREFIX_TYPE . $itemA);
->localize($itemA->getName()) : $this->translator->trans(self::PREFIX_TYPE.$itemA);
$strB = $itemB instanceof ThirdPartyCategory ? $this->translatableStringHelper
->localize($itemB->getName()) : $this->translator->trans(self::PREFIX_TYPE . $itemB);
->localize($itemB->getName()) : $this->translator->trans(self::PREFIX_TYPE.$itemB);
return $strA <=> $strB;
});
@@ -57,7 +51,7 @@ class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractTyp
return $this->translatableStringHelper->localize($item->getName());
}
return self::PREFIX_TYPE . $item;
return self::PREFIX_TYPE.$item;
},
'choice_value' => fn ($item) => $this->reverseTransform($item),
]);
@@ -75,13 +69,13 @@ class PickThirdPartyTypeCategoryType extends \Symfony\Component\Form\AbstractTyp
}
if ($value instanceof ThirdPartyCategory) {
return 'category:' . $value->getId();
return 'category:'.$value->getId();
}
if (is_string($value)) {
return 'type:' . $value;
if (\is_string($value)) {
return 'type:'.$value;
}
throw new UnexpectedTypeException($value, implode(' or ', ['array', 'string', ThirdPartyCategory::class]));
throw new UnexpectedTypeException($value, \implode(' or ', ['array', 'string', ThirdPartyCategory::class]));
}
}

View File

@@ -19,7 +19,7 @@ final readonly class ThirdPartyACLAwareRepository implements ThirdPartyACLAwareR
{
public function __construct(private Security $security, private AuthorizationHelper $authorizationHelper, private ThirdPartyRepository $thirdPartyRepository) {}
public function buildQuery(?string $filterString = null): QueryBuilder
public function buildQuery(string $filterString = null): QueryBuilder
{
$qb = $this->thirdPartyRepository->createQueryBuilder('tp');
@@ -31,7 +31,7 @@ final readonly class ThirdPartyACLAwareRepository implements ThirdPartyACLAwareR
if (null !== $filterString) {
$qb->andWhere($qb->expr()->like('tp.canonicalized', 'LOWER(UNACCENT(:filterString))'))
->setParameter('filterString', '%' . $filterString . '%');
->setParameter('filterString', '%'.$filterString.'%');
}
return $qb;
@@ -51,13 +51,13 @@ final readonly class ThirdPartyACLAwareRepository implements ThirdPartyACLAwareR
string $role,
?string $filterString,
?array $orderBy = [],
?int $limit = null,
?int $offset = null
int $limit = null,
int $offset = null
): array {
$qb = $this->buildQuery($filterString);
foreach ($orderBy as $sort => $direction) {
$qb->addOrderBy('tp.' . $sort, $direction);
$qb->addOrderBy('tp.'.$sort, $direction);
}
$qb->setFirstResult($offset)

View File

@@ -17,9 +17,6 @@ use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Doctrine\Persistence\ObjectRepository;
use DomainException;
use function array_key_exists;
class ThirdPartyRepository implements ObjectRepository
{
@@ -32,7 +29,6 @@ class ThirdPartyRepository implements ObjectRepository
/**
* count amongst parties associated to $centers, with $terms parameters.
*
*/
public function countByMemberOfCenters(array $centers, array $terms = []): int
{
@@ -42,7 +38,7 @@ class ThirdPartyRepository implements ObjectRepository
return $qb->getQuery()->getSingleScalarResult();
}
public function createQueryBuilder(string $alias, ?string $indexBy = null): QueryBuilder
public function createQueryBuilder(string $alias, string $indexBy = null): QueryBuilder
{
return $this->repository->createQueryBuilder($alias, $indexBy);
}
@@ -66,7 +62,7 @@ class ThirdPartyRepository implements ObjectRepository
*
* @return array|ThirdParty[]
*/
public function findBy(array $criteria, ?array $orderBy = null, $limit = null, $offset = null): array
public function findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null): array
{
return $this->repository->findBy($criteria, $orderBy, $limit, $offset);
}
@@ -85,9 +81,9 @@ class ThirdPartyRepository implements ObjectRepository
* - is_active: is active = true / false
* - types: an array of types
*
* @param int $firstResult
* @param int $maxResults
* @param array $terms
* @param int $firstResult
* @param int $maxResults
* @param array $terms
* @param string[] $returnFormat a format for returning
*/
public function findByMemberOfCenters(array $centers, $firstResult = 0, $maxResults = 20, $terms = [], $returnFormat = ['entity']): array
@@ -117,7 +113,7 @@ class ThirdPartyRepository implements ObjectRepository
break;
default:
throw new DomainException('This return format is invalid');
throw new \DomainException('This return format is invalid');
}
$qb->setFirstResult($firstResult)
->setMaxResults($maxResults);
@@ -152,8 +148,8 @@ class ThirdPartyRepository implements ObjectRepository
$or = $qb->expr()->orX();
foreach ($centers as $center) {
$or->add($qb->expr()->isMemberOf(':center_' . $center->getId(), 'tp.centers'));
$qb->setParameter('center_' . $center->getId(), $center);
$or->add($qb->expr()->isMemberOf(':center_'.$center->getId(), 'tp.centers'));
$qb->setParameter('center_'.$center->getId(), $center);
}
$qb->where($or);
@@ -163,7 +159,7 @@ class ThirdPartyRepository implements ObjectRepository
private function setIsActiveCondition(QueryBuilder $qb, array $terms)
{
if (array_key_exists('is_active', $terms)) {
if (\array_key_exists('is_active', $terms)) {
$qb->andWhere(
$terms['is_active'] ? $qb->expr()->eq('tp.active', "'TRUE'") :
$qb->expr()->eq('tp.active', "'FALSE'")
@@ -177,25 +173,25 @@ class ThirdPartyRepository implements ObjectRepository
*/
private function setNameCondition(QueryBuilder $qb, array $terms)
{
if (array_key_exists('name', $terms) || array_key_exists('_default', $terms)) {
if (\array_key_exists('name', $terms) || \array_key_exists('_default', $terms)) {
$term = $terms['name'] ?? $terms['_default'];
if (null === $term || '' === $term) {
return;
}
$qb->andWhere($qb->expr()->like('UNACCENT(LOWER(tp.name))', 'UNACCENT(LOWER(:name))'));
$qb->setParameter('name', '%' . $term . '%');
$qb->setParameter('name', '%'.$term.'%');
}
}
private function setTypesCondition(QueryBuilder $qb, array $terms)
{
if (array_key_exists('types', $terms)) {
if (\array_key_exists('types', $terms)) {
$orx = $qb->expr()->orX();
foreach ($terms['types'] as $type) {
$orx->add('JSONB_EXISTS_IN_ARRAY(tp.type, :type_' . $type . ') = \'TRUE\'');
$qb->setParameter('type_' . $type, $type);
$orx->add('JSONB_EXISTS_IN_ARRAY(tp.type, :type_'.$type.') = \'TRUE\'');
$qb->setParameter('type_'.$type, $type);
}
$qb->andWhere($orx);
}

View File

@@ -15,11 +15,6 @@ use Chill\MainBundle\Search\SearchApiInterface;
use Chill\MainBundle\Search\SearchApiQuery;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use function array_merge;
use function explode;
use function implode;
use function in_array;
/*
* Internal note: test query for parametrizing / testing:
*
@@ -68,7 +63,7 @@ class ThirdPartyApiSearch implements SearchApiInterface
LEFT JOIN chill_main_address cma ON cma.id = COALESCE(parent.address_id, tparty.address_id)
LEFT JOIN chill_main_postal_code cmpc ON cma.postcode_id = cmpc.id');
$strs = explode(' ', $pattern);
$strs = \explode(' ', $pattern);
$wheres = [];
$whereArgs = [];
$pertinence = [];
@@ -86,11 +81,11 @@ class ThirdPartyApiSearch implements SearchApiInterface
$pertinence[] = 'GREATEST(
STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), tparty.canonicalized),
STRICT_WORD_SIMILARITY(LOWER(UNACCENT(?)), parent.canonicalized)
) + ' .
) + '.
"GREATEST(
(tparty.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int,
(parent.canonicalized LIKE '%s' || LOWER(UNACCENT(?)) || '%')::int
) + " .
) + ".
// take postcode label into account, but lower than the canonicalized field
"COALESCE((LOWER(UNACCENT(cmpc.label)) LIKE '%' || LOWER(UNACCENT(?)) || '%')::int * 0.3, 0)";
$pertinenceArgs[] = [$str, $str, $str, $str, $str];
@@ -98,12 +93,12 @@ class ThirdPartyApiSearch implements SearchApiInterface
}
$query
->setSelectPertinence(implode(' + ', $pertinence) . ' + 1', array_merge(
->setSelectPertinence(\implode(' + ', $pertinence).' + 1', \array_merge(
[],
...$pertinenceArgs
))
->andWhereClause(implode(' AND ', $wheres)
. ' AND tparty.active IS TRUE and (parent.active IS TRUE OR parent IS NULL)', array_merge(
->andWhereClause(\implode(' AND ', $wheres)
.' AND tparty.active IS TRUE and (parent.active IS TRUE OR parent IS NULL)', \array_merge(
[],
...$whereArgs
));
@@ -118,6 +113,6 @@ class ThirdPartyApiSearch implements SearchApiInterface
public function supportsTypes(string $pattern, array $types, array $parameters): bool
{
return in_array('thirdparty', $types, true);
return \in_array('thirdparty', $types, true);
}
}

View File

@@ -14,12 +14,10 @@ namespace Chill\ThirdPartyBundle\Search;
use Chill\MainBundle\Pagination\PaginatorFactory;
use Chill\MainBundle\Search\SearchInterface;
use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Repository\ThirdPartyRepository;
use Chill\ThirdPartyBundle\Security\Voter\ThirdPartyVoter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
use Symfony\Component\Security\Core\Role\Role;
/**
* Allow to search amongst parties.
@@ -98,7 +96,7 @@ class ThirdPartySearch implements SearchInterface
];
}
// format "html"
throw new \UnexpectedValueException("format html not supported");
throw new \UnexpectedValueException('format html not supported');
}
public function supports($domain, $format): bool

View File

@@ -17,11 +17,6 @@ use Chill\MainBundle\Security\Authorization\AuthorizationHelper;
use Chill\MainBundle\Security\ProvideRoleHierarchyInterface;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
use Symfony\Component\Security\Core\Role\Role;
use function array_intersect;
use function count;
use function in_array;
/**
* Voter for Third Party.
@@ -66,7 +61,7 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
protected function supports($attribute, $subject)
{
if ($subject instanceof ThirdParty) {
return in_array($attribute, $this->getRoles(), true);
return \in_array($attribute, $this->getRoles(), true);
}
if (null === $subject) {
@@ -77,7 +72,7 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
}
/**
* @param string $attribute
* @param string $attribute
* @param ThirdParty|null $subject
*/
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
@@ -94,11 +89,11 @@ class ThirdPartyVoter extends AbstractChillVoter implements ProvideRoleHierarchy
->getReachableCenters($user, $attribute);
if (null === $subject) {
return count($centers) > 0;
return \count($centers) > 0;
}
if ($subject instanceof ThirdParty) {
return count(array_intersect($centers, $subject->getCenters()->toArray())) > 0;
return \count(\array_intersect($centers, $subject->getCenters()->toArray())) > 0;
}
return false;

View File

@@ -11,12 +11,10 @@ declare(strict_types=1);
namespace Chill\ThirdPartyBundle\Templating\Entity;
use Chill\MainBundle\Templating\Entity\AbstractChillEntityRender;
use Chill\MainBundle\Templating\Entity\BoxUtilsChillEntityRenderTrait;
use Chill\MainBundle\Templating\Entity\ChillEntityRenderInterface;
use Chill\MainBundle\Templating\TranslatableStringHelper;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Symfony\Component\Templating\EngineInterface;
/**
* @implements ChillEntityRenderInterface<ThirdParty>
@@ -44,33 +42,33 @@ class ThirdPartyRender implements ChillEntityRenderInterface
];
return
$this->getDefaultOpeningBox('thirdparty') .
$this->getDefaultOpeningBox('thirdparty').
$this->engine->render('@ChillThirdParty/Entity/thirdparty.html.twig', [
'thirdparty' => $entity,
'render' => $options['render'] ?? 'raw',
'options' => $params,
]) .
]).
$this->getDefaultClosingBox();
}
public function renderString($entity, array $options): string
{
if ($entity->getCivility() !== null) {
if (null !== $entity->getCivility()) {
$civility = $this->translatableStringHelper
->localize($entity->getCivility()->getAbbreviation()) . ' ';
->localize($entity->getCivility()->getAbbreviation()).' ';
} else {
$civility = '';
}
if ('' !== (string) $entity->getAcronym()) {
$acronym = ' (' . $entity->getAcronym() . ')';
$acronym = ' ('.$entity->getAcronym().')';
} else {
$acronym = '';
}
$firstname = ('' === $entity->getFirstname()) ? '' : $entity->getFirstname();
return $civility . $firstname . ' ' . $entity->getName() . $acronym;
return $civility.$firstname.' '.$entity->getName().$acronym;
}
public function supports($entity, array $options): bool

View File

@@ -15,6 +15,7 @@ use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
/**
* @internal
*
* @coversNothing
*/
final class ThirdPartyControllerTest extends WebTestCase

View File

@@ -17,6 +17,7 @@ use PHPUnit\Framework\TestCase;
/**
* @internal
*
* @coversNothing
*/
final class ThirdPartyTest extends TestCase

View File

@@ -14,13 +14,13 @@ namespace Chill\ThirdPartyBundle\Tests\Serializer\Normalizer;
use Chill\MainBundle\Entity\Civility;
use Chill\ThirdPartyBundle\Entity\ThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdPartyCategory;
use libphonenumber\PhoneNumber;
use libphonenumber\PhoneNumberUtil;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* @internal
*
* @coversNothing
*/
final class ThirdPartyDocGenNormalizerTest extends KernelTestCase

View File

@@ -17,6 +17,7 @@ use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
/**
* @internal
*
* @coversNothing
*/
final class ThirdPartyJsonDenormalizerTest extends KernelTestCase

View File

@@ -11,8 +11,6 @@ declare(strict_types=1);
namespace Chill\ThirdPartyBundle\ThirdPartyType;
use function array_keys;
/**
* Manages types of third parties.
*/
@@ -55,6 +53,6 @@ class ThirdPartyTypeManager
*/
public function getTypes(): array
{
return array_keys($this->providers);
return \array_keys($this->providers);
}
}

View File

@@ -24,7 +24,7 @@ final class Version20190307111314 extends AbstractMigration
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP SEQUENCE chill_third_party_id_seq CASCADE');
$this->addSql('DROP TABLE chill_third_party');
@@ -33,7 +33,7 @@ final class Version20190307111314 extends AbstractMigration
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE SEQUENCE chill_third_party_id_seq INCREMENT BY 1 MINVALUE 1 START 1');
$this->addSql('CREATE TABLE chill_third_party (id INT NOT NULL, name VARCHAR(255) NOT NULL, telephone VARCHAR(64) DEFAULT NULL, email VARCHAR(255) DEFAULT NULL, comment TEXT DEFAULT NULL, type JSON DEFAULT NULL, PRIMARY KEY(id))');

View File

@@ -23,7 +23,7 @@ final class Version20190307131650 extends AbstractMigration
{
// this down() migration is auto-generated, please modify it to your needs
$this->throwIrreversibleMigrationException('The down version of this migration is '
. 'not written');
.'not written');
}
public function up(Schema $schema): void

View File

@@ -21,7 +21,7 @@ final class Version20190418090842 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('DROP TABLE chill_3party.party_center');
$this->addSql('ALTER TABLE chill_3party.third_party DROP active');
@@ -29,7 +29,7 @@ final class Version20190418090842 extends AbstractMigration
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('CREATE TABLE chill_3party.party_center (thirdparty_id INT NOT NULL, center_id INT NOT NULL, PRIMARY KEY(thirdparty_id, center_id))');
$this->addSql('CREATE INDEX IDX_C65D4397C7D3A8E6 ON chill_3party.party_center (thirdparty_id)');

View File

@@ -27,8 +27,8 @@ final class Version20190429171109 extends AbstractMigration
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_3party.third_party RENAME COLUMN type '
. 'TO types');
.'TO types');
$this->addSql('ALTER TABLE chill_3party.third_party ALTER COLUMN types '
. 'SET DATA TYPE jsonb');
.'SET DATA TYPE jsonb');
}
}

View File

@@ -21,7 +21,7 @@ final class Version20190502144206 extends AbstractMigration
{
public function down(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_3party.third_party DROP CONSTRAINT FK_D952467BF5B7AF75');
$this->addSql('ALTER TABLE chill_3party.third_party DROP address_id');
@@ -29,7 +29,7 @@ final class Version20190502144206 extends AbstractMigration
public function up(Schema $schema): void
{
$this->abortIf($this->connection->getDatabasePlatform()->getName() !== 'postgresql', 'Migration can only be executed safely on \'postgresql\'.');
$this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.');
$this->addSql('ALTER TABLE chill_3party.third_party ADD address_id INT DEFAULT NULL');
$this->addSql('COMMENT ON COLUMN chill_3party.third_party.types IS NULL');

View File

@@ -14,7 +14,6 @@ namespace Chill\Migrations\ThirdParty;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
use libphonenumber\PhoneNumberUtil;
use RuntimeException;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
@@ -40,7 +39,7 @@ final class Version20220302143821 extends AbstractMigration implements Container
->getParameter('chill_main')['phone_helper']['default_carrier_code'];
if (null === $carrier_code) {
throw new RuntimeException('no carrier code');
throw new \RuntimeException('no carrier code');
}
$this->addSql('ALTER TABLE chill_3party.third_party ALTER telephone TYPE VARCHAR(35)');
@@ -49,7 +48,7 @@ final class Version20220302143821 extends AbstractMigration implements Container
$this->addSql('COMMENT ON COLUMN chill_3party.third_party.telephone IS \'(DC2Type:phone_number)\'');
$this->addSql(
'UPDATE chill_3party.third_party SET ' .
'UPDATE chill_3party.third_party SET '.
$this->buildMigrationPhonenumberClause($carrier_code, 'telephone')
);
}

View File

@@ -11,12 +11,8 @@ declare(strict_types=1);
namespace Chill\Migrations\ThirdParty;
use Chill\ThirdPartyBundle\Entity\ThirdPartyProfession;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Types\Types;
use Doctrine\Migrations\AbstractMigration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
final class Version20230215175150 extends AbstractMigration
{
@@ -30,10 +26,9 @@ final class Version20230215175150 extends AbstractMigration
return 'Change profession to a string field and transfer values';
}
public function up(Schema $schema): void
{
$this->addSql('ALTER TABLE chill_3party.third_party ADD profession TEXT DEFAULT \'\' NOT NULL');
$this->addSql('UPDATE chill_3party.third_party SET profession = party_profession.name->>\'fr\' FROM chill_3party.party_profession WHERE party_profession.id = third_party.profession_id') ;
$this->addSql('UPDATE chill_3party.third_party SET profession = party_profession.name->>\'fr\' FROM chill_3party.party_profession WHERE party_profession.id = third_party.profession_id');
}
}