From 0fbc571edbcd741a52ccbd5fc6598980a23d4d6e Mon Sep 17 00:00:00 2001 From: roadiz-ci Date: Fri, 6 Dec 2024 08:56:55 +0000 Subject: [PATCH] Merge branch release/v2.4.0 --- .github/workflows/run-test.yml | 4 +- composer.json | 15 +- phpcs.xml.dist | 13 - src/Bag/LazyParameterBag.php | 30 +- .../AbstractEntities/AbstractDateTimed.php | 80 ++--- src/Core/AbstractEntities/AbstractEntity.php | 19 +- src/Core/AbstractEntities/AbstractField.php | 287 +++++------------- src/Core/AbstractEntities/AbstractHuman.php | 119 +++----- .../AbstractEntities/AbstractPositioned.php | 10 +- src/Core/AbstractEntities/LeafInterface.php | 5 +- src/Core/AbstractEntities/LeafTrait.php | 20 +- src/Core/AbstractEntities/NodeInterface.php | 25 ++ .../AbstractEntities/PersistableInterface.php | 2 - .../AbstractEntities/PositionedInterface.php | 8 +- src/Core/AbstractEntities/PositionedTrait.php | 20 +- .../AbstractEntities/TranslationInterface.php | 34 --- .../Events/LeafEntityLifeCycleSubscriber.php | 84 +++-- src/Core/Handlers/AbstractHandler.php | 6 +- src/Utils/StringHandler.php | 53 +--- tests/StringHandlerTest.php | 214 ++++++------- 20 files changed, 367 insertions(+), 681 deletions(-) delete mode 100644 phpcs.xml.dist create mode 100644 src/Core/AbstractEntities/NodeInterface.php diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml index 1f9d8b6..49e8d32 100644 --- a/.github/workflows/run-test.yml +++ b/.github/workflows/run-test.yml @@ -19,7 +19,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - php-version: ['8.1', '8.2', '8.3'] + php-version: ['8.2', '8.3'] steps: - uses: shivammathur/setup-php@v2 with: @@ -37,7 +37,5 @@ jobs: run: composer install --no-scripts --no-ansi --no-interaction --no-progress - name: Run PHPUnit tests run: vendor/bin/phpunit -v --whitelist ./src tests - - name: Run PHP Code Sniffer - run: vendor/bin/phpcs -p ./src - name: Run PHPStan run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon diff --git a/composer.json b/composer.json index cbcf736..d894f5d 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,10 @@ } ], "require": { - "php": ">=8.1", - "doctrine/orm": "~2.19.0", + "php": ">=8.2", + "doctrine/orm": "~2.20.0", "jms/serializer": "^3.9.0", + "roadiz/nodetype-contracts": "~1.1.2", "symfony/string": "6.4.*", "symfony/translation-contracts": "^3.0", "symfony/http-foundation": "6.4.*", @@ -28,10 +29,10 @@ "symfony/validator": "6.4.*" }, "require-dev": { - "phpunit/phpunit": "^9.5", + "doctrine/doctrine-bundle": "^2.8.1", "php-coveralls/php-coveralls": "^2.4", - "squizlabs/php_codesniffer": "^3.5", - "phpstan/phpstan": "^1.5.3" + "phpstan/phpstan": "^1.5.3", + "phpunit/phpunit": "^9.5" }, "autoload": { "psr-4": { @@ -51,8 +52,8 @@ }, "extra": { "branch-alias": { - "dev-master": "2.3.x-dev", - "dev-develop": "2.4.x-dev" + "dev-master": "2.4.x-dev", + "dev-develop": "2.5.x-dev" } } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index 19bff0c..0000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - src/ - diff --git a/src/Bag/LazyParameterBag.php b/src/Bag/LazyParameterBag.php index a258d5b..ad29543 100644 --- a/src/Bag/LazyParameterBag.php +++ b/src/Bag/LazyParameterBag.php @@ -19,8 +19,8 @@ public function __construct() } /** - * @param string $key * @param mixed|null $default + * * @return mixed|null */ public function get(string $key, $default = null): mixed @@ -32,11 +32,7 @@ public function get(string $key, $default = null): mixed return parent::get($key, $default); } - /** - * @param string|null $key - * @return array - */ - public function all(string $key = null): array + public function all(?string $key = null): array { if (!$this->ready) { $this->populateParameters(); @@ -45,11 +41,6 @@ public function all(string $key = null): array return parent::all(); } - /** - * @param string $key - * - * @return bool - */ public function has(string $key): bool { if (!$this->ready) { @@ -59,9 +50,6 @@ public function has(string $key): bool return parent::has($key); } - /** - * @return array - */ public function keys(): array { if (!$this->ready) { @@ -71,9 +59,6 @@ public function keys(): array return parent::keys(); } - /** - * @return \ArrayIterator - */ #[\ReturnTypeWillChange] public function getIterator(): \ArrayIterator { @@ -84,9 +69,6 @@ public function getIterator(): \ArrayIterator return parent::getIterator(); } - /** - * @return int - */ #[\ReturnTypeWillChange] public function count(): int { @@ -98,12 +80,8 @@ public function count(): int } /** - * @param string $key - * @param null $default - * @param int $filter - * @param array $options - * - * @return mixed + * @param null $default + * @param array $options */ public function filter(string $key, $default = null, int $filter = \FILTER_DEFAULT, $options = []): mixed { diff --git a/src/Core/AbstractEntities/AbstractDateTimed.php b/src/Core/AbstractEntities/AbstractDateTimed.php index 3483f9b..90449e3 100644 --- a/src/Core/AbstractEntities/AbstractDateTimed.php +++ b/src/Core/AbstractEntities/AbstractDateTimed.php @@ -4,7 +4,6 @@ namespace RZ\Roadiz\Core\AbstractEntities; -use DateTime; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation as SymfonySerializer; @@ -12,104 +11,87 @@ /** * An AbstractEntity with datetime fields to keep track of time with your items. */ - #[ ORM\MappedSuperclass, ORM\HasLifecycleCallbacks, ORM\Table, - ORM\Index(columns: ["created_at"]), - ORM\Index(columns: ["updated_at"]), + ORM\Index(columns: ['created_at']), + ORM\Index(columns: ['updated_at']), ] abstract class AbstractDateTimed extends AbstractEntity { - /** - * @var DateTime|null - */ #[ - ORM\Column(name: "created_at", type: "datetime", nullable: true), - Serializer\Groups(["timestamps"]), - SymfonySerializer\Groups(["timestamps"]), + ORM\Column(name: 'created_at', type: 'datetime', nullable: true), + Serializer\Groups(['timestamps']), + SymfonySerializer\Groups(['timestamps']), ] - protected ?DateTime $createdAt = null; + protected ?\DateTime $createdAt = null; - /** - * @var DateTime|null - */ #[ - ORM\Column(name: "updated_at", type: "datetime", nullable: true), - Serializer\Groups(["timestamps"]), - SymfonySerializer\Groups(["timestamps"]), + ORM\Column(name: 'updated_at', type: 'datetime', nullable: true), + Serializer\Groups(['timestamps']), + SymfonySerializer\Groups(['timestamps']), ] - protected ?DateTime $updatedAt = null; + protected ?\DateTime $updatedAt = null; - /** - * @return DateTime|null - */ - public function getCreatedAt(): ?DateTime + public function getCreatedAt(): ?\DateTime { return $this->createdAt; } /** - * @param DateTime|null $createdAt - * @return AbstractDateTimed + * @return $this */ - public function setCreatedAt(?DateTime $createdAt) + public function setCreatedAt(?\DateTime $createdAt): self { $this->createdAt = $createdAt; + return $this; } - /** - * @return DateTime|null - */ - public function getUpdatedAt(): ?DateTime + public function getUpdatedAt(): ?\DateTime { return $this->updatedAt; } /** - * @param DateTime|null $updatedAt - * @return AbstractDateTimed + * @return $this */ - public function setUpdatedAt(?DateTime $updatedAt) + public function setUpdatedAt(?\DateTime $updatedAt): self { $this->updatedAt = $updatedAt; + return $this; } protected function initAbstractDateTimed(): void { - $this->setUpdatedAt(new DateTime("now")); - $this->setCreatedAt(new DateTime("now")); + $this->setUpdatedAt(new \DateTime('now')); + $this->setCreatedAt(new \DateTime('now')); } - /** - * @return void - */ #[ORM\PreUpdate] - public function preUpdate() + public function preUpdate(): void { - $this->setUpdatedAt(new DateTime("now")); + $this->setUpdatedAt(new \DateTime('now')); } - /** - * @return void - */ + #[ORM\PrePersist] - public function prePersist() + public function prePersist(): void { - $this->setUpdatedAt(new DateTime("now")); - $this->setCreatedAt(new DateTime("now")); + $this->setUpdatedAt(new \DateTime('now')); + $this->setCreatedAt(new \DateTime('now')); } + /** * Set creation and update date to *now*. * - * @return AbstractEntity + * @return $this */ - public function resetDates() + public function resetDates(): self { - $this->setCreatedAt(new DateTime("now")); - $this->setUpdatedAt(new DateTime("now")); + $this->setCreatedAt(new \DateTime('now')); + $this->setUpdatedAt(new \DateTime('now')); return $this; } diff --git a/src/Core/AbstractEntities/AbstractEntity.php b/src/Core/AbstractEntities/AbstractEntity.php index 7eee795..49b5b87 100644 --- a/src/Core/AbstractEntities/AbstractEntity.php +++ b/src/Core/AbstractEntities/AbstractEntity.php @@ -17,34 +17,25 @@ ] abstract class AbstractEntity implements PersistableInterface { - /** - * @var int|string|null - */ #[ ORM\Id, - ORM\Column(type: "integer"), + ORM\Column(type: 'integer'), ORM\GeneratedValue, - Serializer\Groups(["id"]), - Serializer\Type("integer"), - SymfonySerializer\Groups(["id"]) + Serializer\Groups(['id']), + Serializer\Type('integer'), + SymfonySerializer\Groups(['id']) ] protected int|string|null $id = null; - /** - * @return int|string|null - */ public function getId(): int|string|null { return $this->id; } - /** - * @param int|string|null $id - * @return AbstractEntity - */ public function setId(int|string|null $id): self { $this->id = $id; + return $this; } } diff --git a/src/Core/AbstractEntities/AbstractField.php b/src/Core/AbstractEntities/AbstractField.php index ba5c48b..f228f7e 100644 --- a/src/Core/AbstractEntities/AbstractField.php +++ b/src/Core/AbstractEntities/AbstractField.php @@ -4,19 +4,20 @@ namespace RZ\Roadiz\Core\AbstractEntities; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Mapping as ORM; -use RZ\Roadiz\Utils\StringHandler; use JMS\Serializer\Annotation as Serializer; +use RZ\Roadiz\Utils\StringHandler; use Symfony\Component\Serializer\Annotation as SymfonySerializer; use Symfony\Component\Validator\Constraints as Assert; #[ ORM\MappedSuperclass, ORM\Table, - ORM\Index(columns: ["position"]), - ORM\Index(columns: ["group_name"]), - ORM\Index(columns: ["group_name_canonical"]), - Serializer\ExclusionPolicy("all") + ORM\Index(columns: ['position']), + ORM\Index(columns: ['group_name']), + ORM\Index(columns: ['group_name_canonical']), + Serializer\ExclusionPolicy('all') ] abstract class AbstractField extends AbstractPositioned { @@ -109,12 +110,14 @@ abstract class AbstractField extends AbstractPositioned /** * Radio group field is like ENUM_T but rendered as a radio * button group. + * * @deprecated This option does not mean any data type, just presentation */ public const RADIO_GROUP_T = 19; /** * Check group field is like MULTIPLE_T but rendered as * a checkbox group. + * * @deprecated This option does not mean any data type, just presentation */ public const CHECK_GROUP_T = 20; @@ -128,19 +131,19 @@ abstract class AbstractField extends AbstractPositioned */ public const DATE_T = 22; /** - * Textarea to write Json syntax code + * Textarea to write Json syntax code. */ public const JSON_T = 23; /** - * Textarea to write CSS syntax code + * Textarea to write CSS syntax code. */ public const CSS_T = 24; /** - * Select-box to choose ISO Country + * Select-box to choose ISO Country. */ public const COUNTRY_T = 25; /** - * Textarea to write YAML syntax text + * Textarea to write YAML syntax text. */ public const YAML_T = 26; /** @@ -160,7 +163,7 @@ abstract class AbstractField extends AbstractPositioned */ public const SINGLE_PROVIDER_T = 30; /** - * Collection field + * Collection field. */ public const COLLECTION_T = 31; @@ -170,6 +173,7 @@ abstract class AbstractField extends AbstractPositioned * These string will be used as translation key. * * @var array + * * @internal */ #[SymfonySerializer\Ignore] @@ -206,6 +210,7 @@ abstract class AbstractField extends AbstractPositioned * Associates abstract field type to a Doctrine type. * * @var array + * * @internal */ #[SymfonySerializer\Ignore] @@ -244,6 +249,7 @@ abstract class AbstractField extends AbstractPositioned * List searchable fields types in a searchEngine such as Solr. * * @var array + * * @internal */ #[SymfonySerializer\Ignore] @@ -255,43 +261,43 @@ abstract class AbstractField extends AbstractPositioned ]; #[ - ORM\Column(name: "group_name", type: "string", length: 250, nullable: true), + ORM\Column(name: 'group_name', type: 'string', length: 250, nullable: true), Assert\Length(max: 250), - SymfonySerializer\Groups(["node_type", "setting"]), - Serializer\Groups(["node_type", "setting"]), - Serializer\Type("string"), + SymfonySerializer\Groups(['node_type', 'setting']), + Serializer\Groups(['node_type', 'setting']), + Serializer\Type('string'), Serializer\Expose ] protected ?string $groupName = null; #[ - ORM\Column(name: "group_name_canonical", type: "string", length: 250, nullable: true), - Serializer\Groups(["node_type", "setting"]), - SymfonySerializer\Groups(["node_type", "setting"]), + ORM\Column(name: 'group_name_canonical', type: 'string', length: 250, nullable: true), + Serializer\Groups(['node_type', 'setting']), + SymfonySerializer\Groups(['node_type', 'setting']), Assert\Length(max: 250), - Serializer\Type("string"), + Serializer\Type('string'), Serializer\Expose ] protected ?string $groupNameCanonical = null; #[ - ORM\Column(type: "string", length: 250), + ORM\Column(type: 'string', length: 250), Serializer\Expose, - Serializer\Groups(["node_type", "setting"]), - SymfonySerializer\Groups(["node_type", "setting"]), + Serializer\Groups(['node_type', 'setting']), + SymfonySerializer\Groups(['node_type', 'setting']), Assert\Length(max: 250), - Serializer\Type("string"), + Serializer\Type('string'), Assert\NotBlank(), Assert\NotNull() ] protected string $name; #[ - ORM\Column(type: "string", length: 250), + ORM\Column(type: 'string', length: 250), Serializer\Expose, - Serializer\Groups(["node_type", "setting"]), - Serializer\Type("string"), - SymfonySerializer\Groups(["node_type", "setting"]), + Serializer\Groups(['node_type', 'setting']), + Serializer\Type('string'), + SymfonySerializer\Groups(['node_type', 'setting']), Assert\Length(max: 250), Assert\NotBlank(), Assert\NotNull() @@ -299,38 +305,42 @@ abstract class AbstractField extends AbstractPositioned protected ?string $label; #[ - ORM\Column(type: "string", length: 250, nullable: true), + ORM\Column(type: 'string', length: 250, nullable: true), Serializer\Expose, - Serializer\Groups(["node_type", "setting"]), - SymfonySerializer\Groups(["node_type", "setting"]), + Serializer\Groups(['node_type', 'setting']), + SymfonySerializer\Groups(['node_type', 'setting']), Assert\Length(max: 250), - Serializer\Type("string") + Serializer\Type('string') ] protected ?string $placeholder = null; #[ - ORM\Column(type: "text", nullable: true), + ORM\Column(type: 'text', nullable: true), Serializer\Expose, - Serializer\Groups(["node_type", "setting"]), - SymfonySerializer\Groups(["node_type", "setting"]), - Serializer\Type("string") + Serializer\Groups(['node_type', 'setting']), + SymfonySerializer\Groups(['node_type', 'setting']), + Serializer\Type('string') ] protected ?string $description = null; #[ - ORM\Column(name: "default_values", type: "text", nullable: true), - Serializer\Groups(["node_type", "setting"]), - SymfonySerializer\Groups(["node_type", "setting"]), - Serializer\Type("string"), + ORM\Column(name: 'default_values', type: 'text', nullable: true), + Serializer\Groups(['node_type', 'setting']), + SymfonySerializer\Groups(['node_type', 'setting']), + Serializer\Type('string'), Serializer\Expose ] protected ?string $defaultValues = null; #[ - ORM\Column(type: "integer"), - Serializer\Groups(["node_type", "setting"]), - SymfonySerializer\Groups(["node_type", "setting"]), - Serializer\Type("int"), + ORM\Column( + type: Types::SMALLINT, + nullable: false, + options: ['default' => AbstractField::STRING_T] + ), + Serializer\Groups(['node_type', 'setting']), + SymfonySerializer\Groups(['node_type', 'setting']), + Serializer\Type('int'), Serializer\Expose ] protected int $type = AbstractField::STRING_T; @@ -339,10 +349,10 @@ abstract class AbstractField extends AbstractPositioned * If current field data should be expanded (for choices and country types). */ #[ - ORM\Column(name: "expanded", type: "boolean", nullable: false, options: ["default" => false]), - Serializer\Groups(["node_type", "setting"]), - SymfonySerializer\Groups(["node_type", "setting"]), - Serializer\Type("bool"), + ORM\Column(name: 'expanded', type: 'boolean', nullable: false, options: ['default' => false]), + Serializer\Groups(['node_type', 'setting']), + SymfonySerializer\Groups(['node_type', 'setting']), + Serializer\Type('bool'), Serializer\Expose ] protected bool $expanded = false; @@ -370,13 +380,12 @@ public function getName(): string } /** - * @param string|null $name - * * @return $this */ - public function setName(?string $name) + public function setName(?string $name): AbstractField { $this->name = StringHandler::variablize($name ?? ''); + return $this; } @@ -385,7 +394,7 @@ public function setName(?string $name) */ public function getGetterName(): string { - return StringHandler::camelCase('get ' . $this->getName()); + return StringHandler::camelCase('get '.$this->getName()); } /** @@ -393,122 +402,99 @@ public function getGetterName(): string */ public function getSetterName(): string { - return StringHandler::camelCase('set ' . $this->getName()); + return StringHandler::camelCase('set '.$this->getName()); } - /** - * @return string - */ public function getLabel(): string { return $this->label ?? ''; } /** - * @param string|null $label - * - * @return self + * @return $this */ - public function setLabel(?string $label) + public function setLabel(?string $label): AbstractField { $this->label = $label ?? ''; + return $this; } - /** - * @return string|null - */ public function getPlaceholder(): ?string { return $this->placeholder; } /** - * @param string|null $placeholder - * @return AbstractField + * @return $this */ - public function setPlaceholder(?string $placeholder) + public function setPlaceholder(?string $placeholder): AbstractField { $this->placeholder = $placeholder; + return $this; } - /** - * @return string|null - */ public function getDescription(): ?string { return $this->description; } /** - * @param string|null $description - * * @return $this */ - public function setDescription(?string $description) + public function setDescription(?string $description): AbstractField { $this->description = $description; + return $this; } - /** - * @return string|null - */ public function getDefaultValues(): ?string { return $this->defaultValues; } /** - * @param string|null $defaultValues - * * @return $this */ - public function setDefaultValues(?string $defaultValues) + public function setDefaultValues(?string $defaultValues): AbstractField { $this->defaultValues = $defaultValues; + return $this; } - /** - * @return string - */ public function getTypeName(): string { if (!key_exists($this->getType(), static::$typeToHuman)) { - throw new \InvalidArgumentException($this->getType() . ' cannot be mapped to human label.'); + throw new \InvalidArgumentException($this->getType().' cannot be mapped to human label.'); } + return static::$typeToHuman[$this->type]; } - /** - * @return int - */ public function getType(): int { return $this->type; } /** - * @param int $type - * * @return $this */ - public function setType(int $type) + public function setType(int $type): AbstractField { $this->type = $type; + return $this; } - /** - * @return string - */ public function getDoctrineType(): string { if (!key_exists($this->getType(), static::$typeToDoctrine)) { - throw new \InvalidArgumentException($this->getType() . ' cannot be mapped to Doctrine.'); + throw new \InvalidArgumentException($this->getType().' cannot be mapped to Doctrine.'); } + return static::$typeToDoctrine[$this->getType()] ?? ''; } @@ -517,7 +503,7 @@ public function getDoctrineType(): string */ public function isVirtual(): bool { - return static::$typeToDoctrine[$this->getType()] === null; + return null === static::$typeToDoctrine[$this->getType()]; } /** @@ -530,8 +516,6 @@ public function isSearchable(): bool /** * Gets the value of groupName. - * - * @return string|null */ public function getGroupName(): ?string { @@ -542,9 +526,10 @@ public function getGroupName(): ?string * Sets the value of groupName. * * @param string|null $groupName the group name - * @return static + * + * @return $this */ - public function setGroupName(?string $groupName) + public function setGroupName(?string $groupName): AbstractField { if (null === $groupName) { $this->groupName = null; @@ -553,294 +538,190 @@ public function setGroupName(?string $groupName) $this->groupName = trim(strip_tags($groupName)); $this->groupNameCanonical = StringHandler::slugify($this->getGroupName()); } + return $this; } - /** - * @return string|null - */ public function getGroupNameCanonical(): ?string { return $this->groupNameCanonical; } - /** - * @return bool - */ public function isExpanded(): bool { return $this->expanded; } /** - * @param bool $expanded - * @return AbstractField + * @return $this */ - public function setExpanded(bool $expanded) + public function setExpanded(bool $expanded): AbstractField { $this->expanded = $expanded; + return $this; } - /** - * @return bool - */ public function isString(): bool { return $this->getType() === static::STRING_T; } - /** - * @return bool - */ public function isText(): bool { return $this->getType() === static::TEXT_T; } - /** - * @return bool - */ public function isDate(): bool { return $this->getType() === static::DATE_T; } - /** - * @return bool - */ public function isDateTime(): bool { return $this->getType() === static::DATETIME_T; } - /** - * @return bool - */ public function isRichText(): bool { return $this->getType() === static::RICHTEXT_T; } - /** - * @return bool - */ public function isMarkdown(): bool { return $this->getType() === static::MARKDOWN_T; } - /** - * @return bool - */ public function isBool(): bool { return $this->isBoolean(); } - /** - * @return bool - */ public function isBoolean(): bool { return $this->getType() === static::BOOLEAN_T; } - /** - * @return bool - */ public function isInteger(): bool { return $this->getType() === static::INTEGER_T; } - /** - * @return bool - */ public function isDecimal(): bool { return $this->getType() === static::DECIMAL_T; } - /** - * @return bool - */ public function isEmail(): bool { return $this->getType() === static::EMAIL_T; } - /** - * @return bool - */ public function isDocuments(): bool { return $this->getType() === static::DOCUMENTS_T; } - /** - * @return bool - */ public function isPassword(): bool { return $this->getType() === static::PASSWORD_T; } - /** - * @return bool - */ public function isColor(): bool { return $this->isColour(); } - /** - * @return bool - */ public function isColour(): bool { return $this->getType() === static::COLOUR_T; } - /** - * @return bool - */ public function isGeoTag(): bool { return $this->getType() === static::GEOTAG_T; } - /** - * @return bool - */ public function isNodes(): bool { return $this->getType() === static::NODES_T; } - /** - * @return bool - */ public function isUser(): bool { return $this->getType() === static::USER_T; } - /** - * @return bool - */ public function isEnum(): bool { return $this->getType() === static::ENUM_T; } - /** - * @return bool - */ public function isChildrenNodes(): bool { return $this->getType() === static::CHILDREN_T; } - /** - * @return bool - */ public function isCustomForms(): bool { return $this->getType() === static::CUSTOM_FORMS_T; } - /** - * @return bool - */ public function isMultiple(): bool { return $this->getType() === static::MULTIPLE_T; } - /** - * @return bool - */ public function isMultiGeoTag(): bool { return $this->getType() === static::MULTI_GEOTAG_T; } - /** - * @return bool - */ public function isJson(): bool { return $this->getType() === static::JSON_T; } - /** - * @return bool - */ public function isYaml(): bool { return $this->getType() === static::YAML_T; } - /** - * @return bool - */ public function isCss(): bool { return $this->getType() === static::CSS_T; } - /** - * @return bool - */ public function isManyToMany(): bool { return $this->getType() === static::MANY_TO_MANY_T; } - /** - * @return bool - */ public function isManyToOne(): bool { return $this->getType() === static::MANY_TO_ONE_T; } - /** - * @return bool - */ public function isCountry(): bool { return $this->getType() === static::COUNTRY_T; } - /** - * @return bool - */ public function isSingleProvider(): bool { return $this->getType() === static::SINGLE_PROVIDER_T; } - /** - * @return bool - */ public function isMultipleProvider(): bool { return $this->isMultiProvider(); } - /** - * @return bool - */ public function isMultiProvider(): bool { return $this->getType() === static::MULTI_PROVIDER_T; } - /** - * @return bool - */ public function isCollection(): bool { return $this->getType() === static::COLLECTION_T; diff --git a/src/Core/AbstractEntities/AbstractHuman.php b/src/Core/AbstractEntities/AbstractHuman.php index 72725d7..5c38bdb 100644 --- a/src/Core/AbstractEntities/AbstractHuman.php +++ b/src/Core/AbstractEntities/AbstractHuman.php @@ -4,7 +4,6 @@ namespace RZ\Roadiz\Core\AbstractEntities; -use DateTime; use Doctrine\ORM\Mapping as ORM; use JMS\Serializer\Annotation as Serializer; use Symfony\Component\Serializer\Annotation as SymfonySerializer; @@ -23,9 +22,9 @@ abstract class AbstractHuman extends AbstractDateTimed { #[ - ORM\Column(type: "string", length: 200, unique: true), - Serializer\Groups(["user_personal", "human"]), - SymfonySerializer\Groups(["user_personal", "human"]), + ORM\Column(type: 'string', length: 200, unique: true), + Serializer\Groups(['user_personal', 'human']), + SymfonySerializer\Groups(['user_personal', 'human']), Assert\NotNull(), Assert\NotBlank(), Assert\Length(max: 200), @@ -37,206 +36,172 @@ abstract class AbstractHuman extends AbstractDateTimed * Public name (pseudonyme) that can be displayed to a public audience. */ #[ - ORM\Column(name: "publicName", type: "string", length: 250, nullable: true), - Serializer\Groups(["user_public", "human"]), - SymfonySerializer\Groups(["user_public", "human"]), + ORM\Column(name: 'publicName', type: 'string', length: 250, nullable: true), + Serializer\Groups(['user_public', 'human']), + SymfonySerializer\Groups(['user_public', 'human']), Assert\Length(max: 250) ] protected ?string $publicName = null; #[ - ORM\Column(name: "firstName", type: "string", length: 250, nullable: true), - Serializer\Groups(["user_personal", "human"]), - SymfonySerializer\Groups(["user_personal", "human"]), + ORM\Column(name: 'firstName', type: 'string', length: 250, nullable: true), + Serializer\Groups(['user_personal', 'human']), + SymfonySerializer\Groups(['user_personal', 'human']), Assert\Length(max: 250) ] protected ?string $firstName = null; #[ - ORM\Column(name: "lastName", type: "string", length: 250, nullable: true), - Serializer\Groups(["user_personal", "human"]), - SymfonySerializer\Groups(["user_personal", "human"]), + ORM\Column(name: 'lastName', type: 'string', length: 250, nullable: true), + Serializer\Groups(['user_personal', 'human']), + SymfonySerializer\Groups(['user_personal', 'human']), Assert\Length(max: 250) ] protected ?string $lastName = null; #[ - ORM\Column(type: "string", length: 50, nullable: true), - Serializer\Groups(["user_personal", "human"]), - SymfonySerializer\Groups(["user_personal", "human"]), + ORM\Column(type: 'string', length: 50, nullable: true), + Serializer\Groups(['user_personal', 'human']), + SymfonySerializer\Groups(['user_personal', 'human']), Assert\Length(max: 50) ] protected ?string $phone = null; #[ - ORM\Column(type: "string", length: 250, nullable: true), - Serializer\Groups(["user_personal", "human"]), - SymfonySerializer\Groups(["user_personal", "human"]), + ORM\Column(type: 'string', length: 250, nullable: true), + Serializer\Groups(['user_personal', 'human']), + SymfonySerializer\Groups(['user_personal', 'human']), Assert\Length(max: 250) ] protected ?string $company = null; #[ - ORM\Column(type: "string", length: 250, nullable: true), - Serializer\Groups(["user_personal", "human"]), - SymfonySerializer\Groups(["user_personal", "human"]), + ORM\Column(type: 'string', length: 250, nullable: true), + Serializer\Groups(['user_personal', 'human']), + SymfonySerializer\Groups(['user_personal', 'human']), Assert\Length(max: 250) ] protected ?string $job = null; #[ - ORM\Column(type: "datetime", nullable: true), - Serializer\Groups(["user_personal", "human"]), - SymfonySerializer\Groups(["user_personal", "human"]) + ORM\Column(type: 'datetime', nullable: true), + Serializer\Groups(['user_personal', 'human']), + SymfonySerializer\Groups(['user_personal', 'human']) ] - protected ?DateTime $birthday = null; + protected ?\DateTime $birthday = null; - /** - * @return string|null - */ public function getEmail(): ?string { return $this->email; } /** - * @param string|null $email - * * @return $this */ - public function setEmail(?string $email) + public function setEmail(?string $email): AbstractHuman { - if (filter_var($email ?? '', FILTER_VALIDATE_EMAIL) !== false) { + if (false !== filter_var($email ?? '', FILTER_VALIDATE_EMAIL)) { $this->email = $email; } return $this; } - /** - * @return string|null - */ public function getFirstName(): ?string { return $this->firstName; } /** - * @param string|null $firstName - * * @return $this */ - public function setFirstName(?string $firstName) + public function setFirstName(?string $firstName): AbstractHuman { $this->firstName = $firstName; + return $this; } - /** - * @return string|null - */ public function getLastName(): ?string { return $this->lastName; } /** - * @param string|null $lastName - * * @return $this */ - public function setLastName(?string $lastName) + public function setLastName(?string $lastName): AbstractHuman { $this->lastName = $lastName; + return $this; } - /** - * @return string|null - */ public function getCompany(): ?string { return $this->company; } /** - * @param string|null $company - * * @return $this */ - public function setCompany(?string $company) + public function setCompany(?string $company): AbstractHuman { $this->company = $company; + return $this; } - /** - * @return string|null - */ public function getJob(): ?string { return $this->job; } /** - * @param string|null $job - * * @return $this */ - public function setJob(?string $job) + public function setJob(?string $job): AbstractHuman { $this->job = $job; + return $this; } - /** - * @return DateTime|null - */ - public function getBirthday(): ?DateTime + public function getBirthday(): ?\DateTime { return $this->birthday; } + /** - * @param DateTime|null $birthday - * * @return $this */ - public function setBirthday(?DateTime $birthday = null) + public function setBirthday(?\DateTime $birthday = null): AbstractHuman { $this->birthday = $birthday; + return $this; } - /** - * @return string|null - */ public function getPhone(): ?string { return $this->phone; } /** - * @param string|null $phone - * - * @return self + * @return $this */ - public function setPhone(?string $phone) + public function setPhone(?string $phone): AbstractHuman { $this->phone = $phone; + return $this; } - /** - * @return string|null - */ public function getPublicName(): ?string { return $this->publicName; } - /** - * @param string|null $publicName - */ public function setPublicName(?string $publicName): void { $this->publicName = $publicName; diff --git a/src/Core/AbstractEntities/AbstractPositioned.php b/src/Core/AbstractEntities/AbstractPositioned.php index db394b1..e0b934c 100644 --- a/src/Core/AbstractEntities/AbstractPositioned.php +++ b/src/Core/AbstractEntities/AbstractPositioned.php @@ -16,17 +16,17 @@ ORM\MappedSuperclass, ORM\HasLifecycleCallbacks, ORM\Table, - ORM\Index(columns: ["position"]) + ORM\Index(columns: ['position']) ] abstract class AbstractPositioned extends AbstractEntity implements PositionedInterface, Comparable { use PositionedTrait; #[ - ORM\Column(type: "float"), - Serializer\Groups(["position"]), - SymfonySerializer\Groups(["position"]), - Serializer\Type("float") + ORM\Column(type: 'float'), + Serializer\Groups(['position']), + SymfonySerializer\Groups(['position']), + Serializer\Type('float') ] protected float $position = 0.0; } diff --git a/src/Core/AbstractEntities/LeafInterface.php b/src/Core/AbstractEntities/LeafInterface.php index 898a0ad..924b9b7 100644 --- a/src/Core/AbstractEntities/LeafInterface.php +++ b/src/Core/AbstractEntities/LeafInterface.php @@ -13,12 +13,14 @@ public function getChildren(): Collection; /** * @param static $child + * * @return $this */ public function addChild(LeafInterface $child): static; /** * @param static $child + * * @return $this */ public function removeChild(LeafInterface $child): static; @@ -36,15 +38,12 @@ public function getParent(): ?LeafInterface; public function getParents(): array; /** - * @param LeafInterface|null $parent * @return $this */ public function setParent(?LeafInterface $parent = null): static; /** * Gets the leaf depth. - * - * @return int */ public function getDepth(): int; } diff --git a/src/Core/AbstractEntities/LeafTrait.php b/src/Core/AbstractEntities/LeafTrait.php index f9068a9..8518eec 100644 --- a/src/Core/AbstractEntities/LeafTrait.php +++ b/src/Core/AbstractEntities/LeafTrait.php @@ -11,13 +11,16 @@ trait LeafTrait use PositionedTrait; /** - * @return Collection + * @return Collection */ public function getChildren(): Collection { return $this->children; } + /** + * @return $this + */ public function setChildren(Collection $children): static { $this->children = $children; @@ -25,11 +28,11 @@ public function setChildren(Collection $children): static foreach ($this->children as $child) { $child->setParent($this); } + return $this; } /** - * @param LeafInterface $child * @return $this */ public function addChild(LeafInterface $child): static @@ -41,8 +44,8 @@ public function addChild(LeafInterface $child): static return $this; } + /** - * @param LeafInterface $child * @return $this */ public function removeChild(LeafInterface $child): static @@ -63,7 +66,7 @@ public function removeChild(LeafInterface $child): static */ public function getParent(): ?LeafInterface { - /** @phpstan-ignore-next-line */ + /* @phpstan-ignore-next-line */ return $this->parent; } @@ -77,24 +80,23 @@ public function getParents(): array do { $parent = $parent->getParent(); - if ($parent !== null) { + if (null !== $parent) { $parentsArray[] = $parent; } - } while ($parent !== null); + } while (null !== $parent); return array_reverse($parentsArray); } /** * Gets the nodes' depth. - * - * @return int */ public function getDepth(): int { - if ($this->getParent() === null) { + if (null === $this->getParent()) { return 0; } + return $this->getParent()->getDepth() + 1; } } diff --git a/src/Core/AbstractEntities/NodeInterface.php b/src/Core/AbstractEntities/NodeInterface.php new file mode 100644 index 0000000..7883888 --- /dev/null +++ b/src/Core/AbstractEntities/NodeInterface.php @@ -0,0 +1,25 @@ +position; } - /** - * Set position as a float to enable increment and decrement by O.5 - * to insert a node between two others. - * - * @param float $newPosition - * @return $this - */ - public function setPosition(float $newPosition) + public function setPosition(float $newPosition): PositionedInterface { if ($newPosition > -1) { $this->position = $newPosition; @@ -33,15 +23,11 @@ public function setPosition(float $newPosition) return $this; } - /** - * @param mixed $other - * @return int - */ public function compareTo($other): int { if ($other instanceof PositionedInterface) { return $this->getPosition() <=> $other->getPosition(); } - throw new \LogicException('Cannot compare object which does not implement ' . PositionedInterface::class); + throw new \LogicException('Cannot compare object which does not implement '.PositionedInterface::class); } } diff --git a/src/Core/AbstractEntities/TranslationInterface.php b/src/Core/AbstractEntities/TranslationInterface.php index ee2d01e..733fa8b 100644 --- a/src/Core/AbstractEntities/TranslationInterface.php +++ b/src/Core/AbstractEntities/TranslationInterface.php @@ -6,54 +6,24 @@ interface TranslationInterface extends PersistableInterface { - /** - * @return string - */ public function getName(): string; - /** - * @param string|null $name - * @return TranslationInterface - */ public function setName(?string $name): TranslationInterface; - /** - * @return string - */ public function getLocale(): string; - /** - * @param string $locale - * @return TranslationInterface - */ public function setLocale(string $locale): TranslationInterface; - /** - * @return boolean - */ public function isAvailable(): bool; - /** - * @param boolean $available - * @return TranslationInterface - */ public function setAvailable(bool $available): TranslationInterface; - /** - * @return boolean - */ public function isDefaultTranslation(): bool; - /** - * @param bool $defaultTranslation - * @return TranslationInterface - */ public function setDefaultTranslation(bool $defaultTranslation): TranslationInterface; /** * Gets the value of overrideLocale. - * - * @return string */ public function getOverrideLocale(): ?string; @@ -61,15 +31,11 @@ public function getOverrideLocale(): ?string; * Sets the value of overrideLocale. * * @param string|null $overrideLocale the override locale - * - * @return TranslationInterface */ public function setOverrideLocale(?string $overrideLocale): TranslationInterface; /** * Get preferred locale between overrideLocale or locale. - * - * @return string */ public function getPreferredLocale(): string; diff --git a/src/Core/Events/LeafEntityLifeCycleSubscriber.php b/src/Core/Events/LeafEntityLifeCycleSubscriber.php index 8d56061..f5f7964 100644 --- a/src/Core/Events/LeafEntityLifeCycleSubscriber.php +++ b/src/Core/Events/LeafEntityLifeCycleSubscriber.php @@ -4,72 +4,56 @@ namespace RZ\Roadiz\Core\Events; -use Doctrine\Common\EventSubscriber; -use Doctrine\ORM\Event\LifecycleEventArgs; +use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener; +use Doctrine\ORM\Event\PrePersistEventArgs; use Doctrine\ORM\Events; use RZ\Roadiz\Core\AbstractEntities\AbstractEntity; use RZ\Roadiz\Core\AbstractEntities\LeafInterface; use RZ\Roadiz\Core\Handlers\HandlerFactoryInterface; -/** - * @package RZ\Roadiz\Core\Events - */ -class LeafEntityLifeCycleSubscriber implements EventSubscriber +#[AsDoctrineListener(event: Events::prePersist)] +final readonly class LeafEntityLifeCycleSubscriber { - private HandlerFactoryInterface $handlerFactory; - - public function __construct(HandlerFactoryInterface $handlerFactory) + public function __construct(private HandlerFactoryInterface $handlerFactory) { - $this->handlerFactory = $handlerFactory; } - /** - * {@inheritdoc} - */ - public function getSubscribedEvents(): array + public function prePersist(PrePersistEventArgs $event): void { - return [ - Events::prePersist, - ]; - } + $entity = $event->getObject(); - /** - * @param LifecycleEventArgs $event - * @return void - */ - public function prePersist(LifecycleEventArgs $event) - { - $entity = $event->getEntity(); - if ($entity instanceof AbstractEntity && $entity instanceof LeafInterface) { - /* - * Automatically set position only if not manually set before. - */ - try { - $handler = $this->handlerFactory->getHandler($entity); + if (!($entity instanceof AbstractEntity) || !($entity instanceof LeafInterface)) { + return; + } - if ($entity->getPosition() === 0.0) { - /* - * Get the last index after last tag in parent - */ - $lastPosition = $handler->cleanPositions(false); - if ($lastPosition > 1 && null !== $entity->getParent()) { - /* - * Need to decrement position because current tag is already - * in parent's children collection count. - */ - $entity->setPosition($lastPosition - 1); - } else { - $entity->setPosition($lastPosition); - } - } elseif ($entity->getPosition() === 0.5) { + /* + * Automatically set position only if not manually set before. + */ + try { + $handler = $this->handlerFactory->getHandler($entity); + + if (0.0 === $entity->getPosition()) { + /* + * Get the last index after last tag in parent + */ + $lastPosition = $handler->cleanPositions(false); + if ($lastPosition > 1 && null !== $entity->getParent()) { /* - * Position is set to 0.5, so we need to - * shift all tags to the bottom. + * Need to decrement position because current tag is already + * in parent's children collection count. */ - $handler->cleanPositions(true); + $entity->setPosition($lastPosition - 1); + } else { + $entity->setPosition($lastPosition); } - } catch (\InvalidArgumentException $e) { + } elseif (0.5 === $entity->getPosition()) { + /* + * Position is set to 0.5, so we need to + * shift all tags to the bottom. + */ + $handler->cleanPositions(true); } + } catch (\InvalidArgumentException $e) { } } } diff --git a/src/Core/Handlers/AbstractHandler.php b/src/Core/Handlers/AbstractHandler.php index d7e1fbb..5b664d9 100644 --- a/src/Core/Handlers/AbstractHandler.php +++ b/src/Core/Handlers/AbstractHandler.php @@ -8,23 +8,19 @@ abstract class AbstractHandler { - /** - * @return ObjectManager - */ public function getObjectManager(): ObjectManager { return $this->objectManager; } public function __construct( - protected readonly ObjectManager $objectManager + protected readonly ObjectManager $objectManager, ) { } /** * Clean positions for current entity siblings. * - * @param bool $setPositions * @return float Return the next position after the **last** entity */ public function cleanPositions(bool $setPositions = true): float diff --git a/src/Utils/StringHandler.php b/src/Utils/StringHandler.php index 8608a99..2b0e1d4 100644 --- a/src/Utils/StringHandler.php +++ b/src/Utils/StringHandler.php @@ -12,8 +12,6 @@ class StringHandler /** * Remove diacritics characters and replace them with their basic alpha letter. * - * @param string|null $string - * @return string * @deprecated Use Symfony\Component\String\UnicodeString::ascii() */ public static function removeDiacritics(?string $string): string @@ -30,9 +28,6 @@ public static function removeDiacritics(?string $string): string /** * Transform to lowercase and replace every non-alpha character with a dash. - * - * @param string|null $string - * @return string */ public static function slugify(?string $string): string { @@ -40,13 +35,13 @@ public static function slugify(?string $string): string return ''; } $slugger = new AsciiSlugger(); + return $slugger->slug($string)->lower()->toString(); } + /** * Transform a string for use as a classname. * - * @param string|null $string - * * @return string Classified string */ public static function classify(?string $string): string @@ -62,12 +57,9 @@ public static function classify(?string $string): string ->toString() ; } + /** * Transform to lowercase and replace every non-alpha character with an underscore. - * - * @param string|null $string - * - * @return string */ public static function cleanForFilename(?string $string): string { @@ -86,10 +78,6 @@ public static function cleanForFilename(?string $string): string /** * Transform to lowercase and replace every non-alpha character with an underscore. - * - * @param string|null $string - * - * @return string */ public static function variablize(?string $string): string { @@ -110,11 +98,7 @@ public static function variablize(?string $string): string } /** - * Transform to camelcase. - * - * @param string|null $string - * - * @return string + * Transform to lower camelCase. */ public static function camelCase(?string $string): string { @@ -131,14 +115,12 @@ public static function camelCase(?string $string): string ->toString()); } - /** * Encode a string using website security secret. * - * @param string|null $value String to encode + * @param string|null $value String to encode * @param string|null $secret Secret salt * - * @return string * @throws \InvalidArgumentException */ public static function encodeWithSecret(?string $value, ?string $secret): string @@ -147,19 +129,19 @@ public static function encodeWithSecret(?string $value, ?string $secret): string if (!empty($secret)) { $secret = crypt($secret, $secret); - return base64_encode($secret . base64_encode(strip_tags($value ?? ''))); + + return base64_encode($secret.base64_encode(strip_tags($value ?? ''))); } else { - throw new \InvalidArgumentException("You cannot encode with an empty salt. Did you enter a secret security phrase in your conf/config.json file?", 1); + throw new \InvalidArgumentException('You cannot encode with an empty salt. Did you enter a secret security phrase in your conf/config.json file?', 1); } } /** * Decode a string using website security secret. * - * @param string|null $value Salted base64 string + * @param string|null $value Salted base64 string * @param string|null $secret Secret salt * - * @return string * @throws \InvalidArgumentException */ public static function decodeWithSecret(?string $value, ?string $secret): string @@ -170,23 +152,20 @@ public static function decodeWithSecret(?string $value, ?string $secret): string $secret = crypt($secret, $secret); $salted = base64_decode($value ?? ''); - $nonSalted = str_replace($secret, "", $salted); + $nonSalted = str_replace($secret, '', $salted); return base64_decode($nonSalted); } else { - throw new \InvalidArgumentException("You cannot encode with an empty salt. Did you enter a secret security phrase in your conf/config.json file?", 1); + throw new \InvalidArgumentException('You cannot encode with an empty salt. Did you enter a secret security phrase in your conf/config.json file?', 1); } } /** - * @param string $haystack - * @param string $needle - * @return bool * @deprecated Use UnicodeString::endsWith($needle) */ public static function endsWith(string $haystack, string $needle): bool { - if ($needle === '') { + if ('' === $needle) { return true; } @@ -195,17 +174,11 @@ public static function endsWith(string $haystack, string $needle): bool ; } - /** - * @param string $search - * @param string $replace - * @param string $subject - * @return string - */ public static function replaceLast(string $search, string $replace, string $subject): string { $pos = strrpos($subject, $search); - if ($pos !== false) { + if (false !== $pos) { $subject = \substr_replace($subject, $replace, $pos, \mb_strlen($search)); } diff --git a/tests/StringHandlerTest.php b/tests/StringHandlerTest.php index a1ccaf7..15ed248 100644 --- a/tests/StringHandlerTest.php +++ b/tests/StringHandlerTest.php @@ -1,5 +1,7 @@ assertEquals($expected, StringHandler::replaceLast($wanted, "", $input)); + $this->assertEquals($expected, StringHandler::replaceLast($wanted, '', $input)); } - /** - * @return array - */ public function replaceLastProvider(): array { return [ - ["testPage", "Locale", "testPage"], - ["localePage", "Locale", "localePage"], - ["testLocalePage", "Locale", "testPage"], - ["testPageLocale", "Locale", "testPage"], - ["testPagelocale", "Locale", "testPagelocale"], - ["testPageGateau", "Locale", "testPageGateau"], - ["testPage", "", "testPage"], - ["LocalePage", "Locale", "Page"], + ['testPage', 'Locale', 'testPage'], + ['localePage', 'Locale', 'localePage'], + ['testLocalePage', 'Locale', 'testPage'], + ['testPageLocale', 'Locale', 'testPage'], + ['testPagelocale', 'Locale', 'testPagelocale'], + ['testPageGateau', 'Locale', 'testPageGateau'], + ['testPage', '', 'testPage'], + ['LocalePage', 'Locale', 'Page'], ]; } @@ -101,23 +100,20 @@ public function testRemoveDiacritics(string $input, string $expected): void $this->assertEquals($expected, StringHandler::removeDiacritics($input)); } - /** - * @return array - */ public function removeDiacriticsProvider(): array { return [ - ["à", "a"], - ["é", "e"], - ["À", "A"], - ["É", "E"], - ["œ", "oe"], - ["ç", "c"], - ["__à", "__a"], - ["--é", "--e"], + ['à', 'a'], + ['é', 'e'], + ['À', 'A'], + ['É', 'E'], + ['œ', 'oe'], + ['ç', 'c'], + ['__à', '__a'], + ['--é', '--e'], [ - "Les-echos_26022015_Les-entrepreneurs-partent-à-lassaut-du-secteur-bancaire.pdf", - "Les-echos_26022015_Les-entrepreneurs-partent-a-lassaut-du-secteur-bancaire.pdf" + 'Les-echos_26022015_Les-entrepreneurs-partent-à-lassaut-du-secteur-bancaire.pdf', + 'Les-echos_26022015_Les-entrepreneurs-partent-a-lassaut-du-secteur-bancaire.pdf', ], ]; } @@ -131,29 +127,26 @@ public function testVariablize(string $input, string $expected): void $this->assertEquals($expected, StringHandler::variablize($input)); } - /** - * @return array - */ public function variablizeProvider(): array { return [ - ["à", "a"], - ["é", "e"], - ["À", "a"], - ["É", "e"], - ["œ", "oe"], - ["ç", "c"], - ["__à", "a"], - ["--é", "e"], - ["Ligula $* _--Egestas Mattis Nullam$* _ ", "ligula_egestas_mattis_nullam"], - ["Véèsti buœlum Rïsus+", "veesti_buoelum_risus"], - ["J'aime les sushis!", "j_aime_les_sushis"], - ["J’aime les sushis!", "j_aime_les_sushis"], - ["J'aime les\n sushis!\t\n", "j_aime_les_sushis"], - ["?header_image", "header_image"], - ["JAime les_sushis", "j_aime_les_sushis"], - ["Ébène", "ebene"], - ["ébène", "ebene"], + ['à', 'a'], + ['é', 'e'], + ['À', 'a'], + ['É', 'e'], + ['œ', 'oe'], + ['ç', 'c'], + ['__à', 'a'], + ['--é', 'e'], + ['Ligula $* _--Egestas Mattis Nullam$* _ ', 'ligula_egestas_mattis_nullam'], + ['Véèsti buœlum Rïsus+', 'veesti_buoelum_risus'], + ["J'aime les sushis!", 'j_aime_les_sushis'], + ['J’aime les sushis!', 'j_aime_les_sushis'], + ["J'aime les\n sushis!\t\n", 'j_aime_les_sushis'], + ['?header_image', 'header_image'], + ['JAime les_sushis', 'j_aime_les_sushis'], + ['Ébène', 'ebene'], + ['ébène', 'ebene'], ]; } @@ -166,17 +159,14 @@ public function testClassify(string $input, string $expected): void $this->assertEquals($expected, StringHandler::classify($input)); } - /** - * @return array - */ public function classifyProvider(): array { return [ - ["Ligula $* _--Egestas Mattis Nullam", "LigulaEgestasMattisNullam"], - ["Véèsti buœlum Rïsus", "VeestiBuoelumRisus"], - ["J'aime les sushis", "JAimeLesSushis"], - ["header_image", "HeaderImage"], - ["JAime les_sushis", "JAimeLesSushis"], + ['Ligula $* _--Egestas Mattis Nullam', 'LigulaEgestasMattisNullam'], + ['Véèsti buœlum Rïsus', 'VeestiBuoelumRisus'], + ["J'aime les sushis", 'JAimeLesSushis'], + ['header_image', 'HeaderImage'], + ['JAime les_sushis', 'JAimeLesSushis'], ]; } @@ -189,17 +179,14 @@ public function testCamelCase(string $input, string $expected): void $this->assertEquals($expected, StringHandler::camelcase($input)); } - /** - * @return array - */ public function camelCaseProvider(): array { return [ - ["Ligula $* _--Egestas Mattis Nullam", "ligulaEgestasMattisNullam"], - ["Véèsti buœlum Rïsus", "veestiBuoelumRisus"], - ["J'aime les sushis", "jAimeLesSushis"], - ["header_image", "headerImage"], - ["JAime les_sushis", "jAimeLesSushis"], + ['Ligula $* _--Egestas Mattis Nullam', 'ligulaEgestasMattisNullam'], + ['Véèsti buœlum Rïsus', 'veestiBuoelumRisus'], + ["J'aime les sushis", 'jAimeLesSushis'], + ['header_image', 'headerImage'], + ['JAime les_sushis', 'jAimeLesSushis'], ]; } @@ -212,28 +199,25 @@ public function testSlugify(string $input, string $expected): void $this->assertEquals($expected, StringHandler::slugify($input)); } - /** - * @return array - */ public function slugifyProvider(): array { return [ - ["Ligula $* _--Egestas Mattis Nullam$* _ ", "ligula-egestas-mattis-nullam"], - ["Véèsti buœlum Rïsus+", "veesti-buoelum-risus"], - ["veesti-buoelum-risus", "veesti-buoelum-risus"], - ["J'aime les sushis!", "j-aime-les-sushis"], - ["J’aime les sushis!", "j-aime-les-sushis"], - ["J'aime les\n sushis!\t\n", "j-aime-les-sushis"], - ["?header_image", "header-image"], - ["JAime les_sushis", "jaime-les-sushis"], - ["Ébène", "ebene"], - ["ébène", "ebene"], - ["Page1 1", "page1-1"], - ["Page3", "page3"], - ["Page 3", "page-3"], - ["Page 3 3", "page-3-3"], - ["12 Page 3 3", "12-page-3-3"], - ["straßburg", "strassburg"] + ['Ligula $* _--Egestas Mattis Nullam$* _ ', 'ligula-egestas-mattis-nullam'], + ['Véèsti buœlum Rïsus+', 'veesti-buoelum-risus'], + ['veesti-buoelum-risus', 'veesti-buoelum-risus'], + ["J'aime les sushis!", 'j-aime-les-sushis'], + ['J’aime les sushis!', 'j-aime-les-sushis'], + ["J'aime les\n sushis!\t\n", 'j-aime-les-sushis'], + ['?header_image', 'header-image'], + ['JAime les_sushis', 'jaime-les-sushis'], + ['Ébène', 'ebene'], + ['ébène', 'ebene'], + ['Page1 1', 'page1-1'], + ['Page3', 'page3'], + ['Page 3', 'page-3'], + ['Page 3 3', 'page-3-3'], + ['12 Page 3 3', '12-page-3-3'], + ['straßburg', 'strassburg'], ]; } @@ -248,17 +232,14 @@ public function testEncodeWithSecret(string $input, string $secret): void $this->assertEquals($input, StringHandler::decodeWithSecret($code, $secret)); } - /** - * @return array - */ public function encodeWithSecretProvider(): array { return [ - ["Ligula $* _--Egestas Mattis Nullam", "Commodo Pellentesque Sem Fusce Quam"], - ["Véèsti buœlum Rïsus ", " change#this#secret#very#important"], - ["J'aime les sushis ", " Fringilla Vulputate Dolor Inceptos"], - ["au " . PHP_EOL . "ietaui.\\eauie@auietsrt.trr", "Sit Vestibulum Dolor Ullamcorper Aenean"], - ["JAime les_sushis", "Sit Vestibulum Dolor"], + ['Ligula $* _--Egestas Mattis Nullam', 'Commodo Pellentesque Sem Fusce Quam'], + ['Véèsti buœlum Rïsus ', ' change#this#secret#very#important'], + ["J'aime les sushis ", ' Fringilla Vulputate Dolor Inceptos'], + ['au '.PHP_EOL.'ietaui.\\eauie@auietsrt.trr', 'Sit Vestibulum Dolor Ullamcorper Aenean'], + ['JAime les_sushis', 'Sit Vestibulum Dolor'], ]; } @@ -275,16 +256,13 @@ public function testEncodeWithSecretNoSalt(string $input, string $secret): void $this->assertEquals($input, StringHandler::decodeWithSecret($code, $secret)); } - /** - * @return array - */ public function encodeWithSecretNoSaltProvider(): array { return [ - ["Ligula $* _--Egestas Mattis Nullam", ""], - ["Véèsti buœlum Rïsus ", " "], - ["J'aime les sushis ", " "], - ["auietauieauie@auietsrt.trr", PHP_EOL], + ['Ligula $* _--Egestas Mattis Nullam', ''], + ['Véèsti buœlum Rïsus ', ' '], + ["J'aime les sushis ", ' '], + ['auietauieauie@auietsrt.trr', PHP_EOL], ]; } }