mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-22 15:43:51 +00:00
Refactored code to use PHP8 attributes instead of annotations
In this change, Doctrine and validation annotations have been replaced with PHP8 Attributes. The Rector tool has been configured with a list of annotations to convert to attributes. As a consequence, the PHPStan's rules have been updated to reflect these changes. The PHP8's nullable operator (?) has been added where required, and comments in field declaration have been replaced with #[Attribute] syntax.
This commit is contained in:
@@ -65,18 +65,14 @@ class Location implements TrackCreationInterface, TrackUpdateInterface
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::STRING, length: 255, nullable: true)]
|
||||
private ?string $name = null;
|
||||
|
||||
/**
|
||||
* @PhonenumberConstraint(type="any")
|
||||
*/
|
||||
#[Serializer\Groups(['read', 'write', 'docgen:read'])]
|
||||
#[ORM\Column(type: 'phone_number', nullable: true)]
|
||||
#[PhonenumberConstraint(type: 'any')]
|
||||
private ?PhoneNumber $phonenumber1 = null;
|
||||
|
||||
/**
|
||||
* @PhonenumberConstraint(type="any")
|
||||
*/
|
||||
#[Serializer\Groups(['read', 'write', 'docgen:read'])]
|
||||
#[ORM\Column(type: 'phone_number', nullable: true)]
|
||||
#[PhonenumberConstraint(type: 'any')]
|
||||
private ?PhoneNumber $phonenumber2 = null;
|
||||
|
||||
#[Serializer\Groups(['read'])]
|
||||
|
@@ -14,7 +14,6 @@ namespace Chill\MainBundle\Entity;
|
||||
use Chill\MainBundle\Doctrine\Model\TrackUpdateInterface;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\Common\Collections\Order;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
use Symfony\Component\Validator\Context\ExecutionContextInterface;
|
||||
@@ -58,7 +57,7 @@ class Notification implements TrackUpdateInterface
|
||||
* @var Collection<NotificationComment>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: NotificationComment::class, mappedBy: 'notification', orphanRemoval: true)]
|
||||
#[ORM\OrderBy(['createdAt' => 'ASC'])]
|
||||
#[ORM\OrderBy(['createdAt' => \Doctrine\Common\Collections\Criteria::ASC])]
|
||||
private Collection $comments;
|
||||
|
||||
#[ORM\Column(type: \Doctrine\DBAL\Types\Types::DATETIME_IMMUTABLE)]
|
||||
|
@@ -111,10 +111,9 @@ class User implements UserInterface, \Stringable, PasswordAuthenticatedUserInter
|
||||
|
||||
/**
|
||||
* The user's mobile phone number.
|
||||
*
|
||||
* @PhonenumberConstraint()
|
||||
*/
|
||||
#[ORM\Column(type: 'phone_number', nullable: true)]
|
||||
#[PhonenumberConstraint]
|
||||
private ?PhoneNumber $phonenumber = null;
|
||||
|
||||
/**
|
||||
|
@@ -24,12 +24,10 @@ use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Serializer\Annotation as Serializer;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* @EntityWorkflowCreation(groups={"creation"})
|
||||
*/
|
||||
#[Serializer\DiscriminatorMap(typeProperty: 'type', mapping: ['entity_workflow' => EntityWorkflow::class])]
|
||||
#[ORM\Entity]
|
||||
#[ORM\Table('chill_main_workflow_entity')]
|
||||
#[EntityWorkflowCreation(groups: ['creation'])]
|
||||
class EntityWorkflow implements TrackCreationInterface, TrackUpdateInterface
|
||||
{
|
||||
use TrackCreationTrait;
|
||||
|
@@ -102,7 +102,7 @@ class SortExportElementTest extends KernelTestCase
|
||||
private function makeTranslator(): TranslatorInterface
|
||||
{
|
||||
return new class () implements TranslatorInterface {
|
||||
public function trans(string $id, array $parameters = [], string $domain = null, string $locale = null)
|
||||
public function trans(string $id, array $parameters = [], ?string $domain = null, ?string $locale = null)
|
||||
{
|
||||
return $id;
|
||||
}
|
||||
|
@@ -13,9 +13,7 @@ namespace Chill\MainBundle\Validation\Constraint;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_METHOD)]
|
||||
class PhonenumberConstraint extends Constraint
|
||||
{
|
||||
public $notLandlineMessage = 'This is not a landline phonenumber';
|
||||
@@ -29,7 +27,13 @@ class PhonenumberConstraint extends Constraint
|
||||
*
|
||||
* @var string 'landline', 'mobile' or 'any'
|
||||
*/
|
||||
public $type;
|
||||
public string $type;
|
||||
|
||||
public function __construct(?array $options = null, ?string $type = null, ?array $groups = null, $payload = null)
|
||||
{
|
||||
parent::__construct($options ?? [], $groups, $payload);
|
||||
$this->type = $type ?? 'any';
|
||||
}
|
||||
|
||||
public function validatedBy()
|
||||
{
|
||||
|
@@ -13,9 +13,7 @@ namespace Chill\MainBundle\Validator\Constraints\Entity;
|
||||
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
|
||||
/**
|
||||
* @Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class UserCircleConsistency extends Constraint
|
||||
{
|
||||
public $getUserFunction = 'getUser';
|
||||
|
@@ -17,9 +17,8 @@ namespace Chill\MainBundle\Workflow\Validator;
|
||||
* * a handler exists;
|
||||
* * a related entity does exists;
|
||||
* * a workflow can be associated with this entity.
|
||||
*
|
||||
* @Annotation
|
||||
*/
|
||||
#[\Attribute(\Attribute::TARGET_CLASS)]
|
||||
class EntityWorkflowCreation extends \Symfony\Component\Validator\Constraint
|
||||
{
|
||||
public string $messageEntityNotFound = 'Related entity is not found';
|
||||
|
Reference in New Issue
Block a user