From 9d1be2ee696eb4cc0fb15370719a23d0253c10dc Mon Sep 17 00:00:00 2001 From: Adrien Crivelli Date: Tue, 25 Apr 2023 16:31:24 +0700 Subject: [PATCH] Migrate to PHP attributes #9606 --- composer.json | 2 +- composer.lock | 87 +++++++++++++------------ src/Model/Message.php | 4 +- src/Model/Traits/AbstractFile.php | 24 +++---- src/Model/Traits/HasDescription.php | 4 +- src/Model/Traits/HasInternalRemarks.php | 4 +- src/Model/Traits/HasName.php | 4 +- src/Model/Traits/HasOtp.php | 27 +++----- src/Model/Traits/HasPassword.php | 25 +++---- src/Model/Traits/HasUrl.php | 12 ++-- src/Model/Traits/Image.php | 16 ++--- src/Model/Traits/Log.php | 35 +++------- src/Model/Traits/Message.php | 31 +++------ tests/Blog/Model/AbstractModel.php | 11 ++-- tests/Blog/Model/Post.php | 15 ++--- tests/Blog/Model/User.php | 23 ++----- tests/Traits/TestWithEntityManager.php | 2 +- 17 files changed, 120 insertions(+), 206 deletions(-) diff --git a/composer.json b/composer.json index 87de591..e4cb1d5 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,7 @@ "cakephp/chronos": "^2.3", "doctrine/dbal": "^3.5", "doctrine/migrations": "^3.5", - "ecodev/graphql-doctrine": "^7.3", + "ecodev/graphql-doctrine": "^8.0", "imagine/imagine": "^1.3", "laminas/laminas-diactoros": "^2.21", "laminas/laminas-log": "^2.15", diff --git a/composer.lock b/composer.lock index c3ce070..3ce768b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "8bf1c54464da8e2cd3e609f807ec89f4", + "content-hash": "d866e0a498e774b0ab2773613f30be83", "packages": [ { "name": "cakephp/chronos", @@ -974,51 +974,52 @@ }, { "name": "doctrine/orm", - "version": "2.13.3", + "version": "2.14.3", "source": { "type": "git", "url": "https://github.com/doctrine/orm.git", - "reference": "e750360bd52b080c4cbaaee1b48b80f7dc873b36" + "reference": "a64f315dfeae5e50b17f132626fd9e9b4ec8985d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/orm/zipball/e750360bd52b080c4cbaaee1b48b80f7dc873b36", - "reference": "e750360bd52b080c4cbaaee1b48b80f7dc873b36", + "url": "https://api.github.com/repos/doctrine/orm/zipball/a64f315dfeae5e50b17f132626fd9e9b4ec8985d", + "reference": "a64f315dfeae5e50b17f132626fd9e9b4ec8985d", "shasum": "" }, "require": { "composer-runtime-api": "^2", "doctrine/cache": "^1.12.1 || ^2.1.1", - "doctrine/collections": "^1.5", + "doctrine/collections": "^1.5 || ^2.0", "doctrine/common": "^3.0.3", "doctrine/dbal": "^2.13.1 || ^3.2", "doctrine/deprecations": "^0.5.3 || ^1", - "doctrine/event-manager": "^1.1", + "doctrine/event-manager": "^1.2 || ^2", "doctrine/inflector": "^1.4 || ^2.0", "doctrine/instantiator": "^1.3", - "doctrine/lexer": "^1.2.3", + "doctrine/lexer": "^1.2.3 || ^2", "doctrine/persistence": "^2.4 || ^3", "ext-ctype": "*", "php": "^7.1 || ^8.0", "psr/cache": "^1 || ^2 || ^3", - "symfony/console": "^3.0 || ^4.0 || ^5.0 || ^6.0", + "symfony/console": "^4.2 || ^5.0 || ^6.0", "symfony/polyfill-php72": "^1.23", "symfony/polyfill-php80": "^1.16" }, "conflict": { - "doctrine/annotations": "<1.13 || >= 2.0" + "doctrine/annotations": "<1.13 || >= 3.0" }, "require-dev": { - "doctrine/annotations": "^1.13", - "doctrine/coding-standard": "^9.0.2 || ^10.0", + "doctrine/annotations": "^1.13 || ^2", + "doctrine/coding-standard": "^9.0.2 || ^11.0", "phpbench/phpbench": "^0.16.10 || ^1.0", - "phpstan/phpstan": "~1.4.10 || 1.8.5", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "phpstan/phpstan": "~1.4.10 || 1.10.6", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6", "psr/log": "^1 || ^2 || ^3", - "squizlabs/php_codesniffer": "3.7.1", + "squizlabs/php_codesniffer": "3.7.2", "symfony/cache": "^4.4 || ^5.4 || ^6.0", + "symfony/var-exporter": "^4.4 || ^5.4 || ^6.2", "symfony/yaml": "^3.4 || ^4.0 || ^5.0 || ^6.0", - "vimeo/psalm": "4.27.0" + "vimeo/psalm": "4.30.0 || 5.9.0" }, "suggest": { "ext-dom": "Provides support for XSD validation for XML mapping files", @@ -1068,22 +1069,22 @@ ], "support": { "issues": "https://github.com/doctrine/orm/issues", - "source": "https://github.com/doctrine/orm/tree/2.13.3" + "source": "https://github.com/doctrine/orm/tree/2.14.3" }, - "time": "2022-10-07T06:37:17+00:00" + "time": "2023-04-20T09:46:32+00:00" }, { "name": "doctrine/persistence", - "version": "2.5.5", + "version": "2.5.7", "source": { "type": "git", "url": "https://github.com/doctrine/persistence.git", - "reference": "38670dd6ac8f2d997a0b5b6c98cb380ef0ba9bd3" + "reference": "e36f22765f4d10a7748228babbf73da5edfeed3c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/persistence/zipball/38670dd6ac8f2d997a0b5b6c98cb380ef0ba9bd3", - "reference": "38670dd6ac8f2d997a0b5b6c98cb380ef0ba9bd3", + "url": "https://api.github.com/repos/doctrine/persistence/zipball/e36f22765f4d10a7748228babbf73da5edfeed3c", + "reference": "e36f22765f4d10a7748228babbf73da5edfeed3c", "shasum": "" }, "require": { @@ -1095,18 +1096,18 @@ "psr/cache": "^1.0 || ^2.0 || ^3.0" }, "conflict": { - "doctrine/annotations": "<1.0 || >=2.0", + "doctrine/annotations": "<1.0 || >=3.0", "doctrine/common": "<2.10" }, "require-dev": { "composer/package-versions-deprecated": "^1.11", - "doctrine/annotations": "^1.0", - "doctrine/coding-standard": "^9 || ^10", + "doctrine/annotations": "^1 || ^2", + "doctrine/coding-standard": "^9 || ^11", "doctrine/common": "^3.0", - "phpstan/phpstan": "~1.4.10 || 1.8.8", + "phpstan/phpstan": "~1.4.10 || 1.9.4", "phpunit/phpunit": "^7.5.20 || ^8.5 || ^9.5", "symfony/cache": "^4.4 || ^5.4 || ^6.0", - "vimeo/psalm": "4.29.0" + "vimeo/psalm": "4.30.0 || 5.3.0" }, "type": "library", "autoload": { @@ -1156,7 +1157,7 @@ ], "support": { "issues": "https://github.com/doctrine/persistence/issues", - "source": "https://github.com/doctrine/persistence/tree/2.5.5" + "source": "https://github.com/doctrine/persistence/tree/2.5.7" }, "funding": [ { @@ -1172,24 +1173,24 @@ "type": "tidelift" } ], - "time": "2022-10-13T07:17:40+00:00" + "time": "2023-02-03T15:51:16+00:00" }, { "name": "ecodev/graphql-doctrine", - "version": "7.3.0", + "version": "8.0.0", "source": { "type": "git", "url": "https://github.com/Ecodev/graphql-doctrine.git", - "reference": "631ad00a690711bc428a2a117ac391403a7c43ac" + "reference": "9642833b6484e8f51ad59952370e9bfedd35f16d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Ecodev/graphql-doctrine/zipball/631ad00a690711bc428a2a117ac391403a7c43ac", - "reference": "631ad00a690711bc428a2a117ac391403a7c43ac", + "url": "https://api.github.com/repos/Ecodev/graphql-doctrine/zipball/9642833b6484e8f51ad59952370e9bfedd35f16d", + "reference": "9642833b6484e8f51ad59952370e9bfedd35f16d", "shasum": "" }, "require": { - "doctrine/orm": "^2.13", + "doctrine/orm": "^2.14", "doctrine/persistence": "^2.0", "php": "^8.1", "psr/container": "^1.1 || ^2.0", @@ -1212,7 +1213,7 @@ "license": [ "MIT" ], - "description": "Declare GraphQL types from Doctrine entities and annotations", + "description": "Declare GraphQL types from Doctrine entities and attributes", "keywords": [ "api", "doctrine", @@ -1221,9 +1222,9 @@ ], "support": { "issues": "https://github.com/Ecodev/graphql-doctrine/issues", - "source": "https://github.com/Ecodev/graphql-doctrine/tree/7.3.0" + "source": "https://github.com/Ecodev/graphql-doctrine/tree/8.0.0" }, - "time": "2022-11-11T12:06:06+00:00" + "time": "2023-04-25T09:15:45+00:00" }, { "name": "friendsofphp/proxy-manager-lts", @@ -4422,16 +4423,16 @@ }, { "name": "webonyx/graphql-php", - "version": "v14.11.8", + "version": "v14.11.9", "source": { "type": "git", "url": "https://github.com/webonyx/graphql-php.git", - "reference": "04a48693acd785330eefd3b0e4fa67df8dfee7c3" + "reference": "ff91c9f3cf241db702e30b2c42bcc0920e70ac70" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/04a48693acd785330eefd3b0e4fa67df8dfee7c3", - "reference": "04a48693acd785330eefd3b0e4fa67df8dfee7c3", + "url": "https://api.github.com/repos/webonyx/graphql-php/zipball/ff91c9f3cf241db702e30b2c42bcc0920e70ac70", + "reference": "ff91c9f3cf241db702e30b2c42bcc0920e70ac70", "shasum": "" }, "require": { @@ -4476,7 +4477,7 @@ ], "support": { "issues": "https://github.com/webonyx/graphql-php/issues", - "source": "https://github.com/webonyx/graphql-php/tree/v14.11.8" + "source": "https://github.com/webonyx/graphql-php/tree/v14.11.9" }, "funding": [ { @@ -4484,7 +4485,7 @@ "type": "open_collective" } ], - "time": "2022-09-21T15:35:03+00:00" + "time": "2023-01-06T12:12:50+00:00" } ], "packages-dev": [ diff --git a/src/Model/Message.php b/src/Model/Message.php index 340efe1..32261d6 100644 --- a/src/Model/Message.php +++ b/src/Model/Message.php @@ -5,6 +5,7 @@ namespace Ecodev\Felix\Model; use Cake\Chronos\Chronos; +use GraphQL\Doctrine\Attribute as API; interface Message extends Model { @@ -20,9 +21,8 @@ public function getDateSent(): ?Chronos; /** * Set sent time. - * - * @API\Exclude */ + #[Api\Exclude] public function setDateSent(?Chronos $dateSent): void; /** diff --git a/src/Model/Traits/AbstractFile.php b/src/Model/Traits/AbstractFile.php index 70d2154..1bcf938 100644 --- a/src/Model/Traits/AbstractFile.php +++ b/src/Model/Traits/AbstractFile.php @@ -6,7 +6,7 @@ use Doctrine\ORM\Mapping as ORM; use Exception; -use GraphQL\Doctrine\Annotation as API; +use GraphQL\Doctrine\Attribute as API; use Psr\Http\Message\UploadedFileInterface; /** @@ -26,15 +26,11 @@ abstract protected function getBasePath(): string; */ abstract protected function getAcceptedMimeTypes(): array; - /** - * @API\Exclude - * @ORM\Column(type="string", length=190, options={"default" = ""}) - */ + #[ORM\Column(type: 'string', length: 190, options: ['default' => ''])] + #[API\Exclude] private string $filename = ''; - /** - * @ORM\Column(type="string", length=255, options={"default" = ""}) - */ + #[ORM\Column(type: 'string', length: 255, options: ['default' => ''])] private string $mime = ''; /** @@ -55,9 +51,8 @@ public function setFile(UploadedFileInterface $file): void /** * Set filename (without path). - * - * @API\Exclude */ + #[API\Exclude] public function setFilename(string $filename): void { $this->filename = $filename; @@ -65,9 +60,8 @@ public function setFilename(string $filename): void /** * Get filename (without path). - * - * @API\Exclude */ + #[API\Exclude] public function getFilename(): string { return $this->filename; @@ -83,9 +77,8 @@ public function getMime(): string /** * Get absolute path to file on disk. - * - * @API\Exclude */ + #[API\Exclude] public function getPath(): string { return realpath('.') . '/' . $this->getBasePath() . $this->getFilename(); @@ -95,9 +88,8 @@ public function getPath(): string * Automatically called by Doctrine when the object is deleted * Is called after database update because we can have issues on remove operation (like integrity test) * and it's preferable to keep a related file on drive before removing it definitely. - * - * @ORM\PostRemove */ + #[ORM\PostRemove] public function deleteFile(): void { $path = $this->getPath(); diff --git a/src/Model/Traits/HasDescription.php b/src/Model/Traits/HasDescription.php index 1dc60b2..832db63 100644 --- a/src/Model/Traits/HasDescription.php +++ b/src/Model/Traits/HasDescription.php @@ -8,9 +8,7 @@ trait HasDescription { - /** - * @ORM\Column(type="text", length=65535) - */ + #[ORM\Column(type: 'text', length: 65535)] private string $description = ''; /** diff --git a/src/Model/Traits/HasInternalRemarks.php b/src/Model/Traits/HasInternalRemarks.php index b6f4892..3d75247 100644 --- a/src/Model/Traits/HasInternalRemarks.php +++ b/src/Model/Traits/HasInternalRemarks.php @@ -8,9 +8,7 @@ trait HasInternalRemarks { - /** - * @ORM\Column(type="text", length=65535) - */ + #[ORM\Column(type: 'text', length: 65535)] private string $internalRemarks = ''; /** diff --git a/src/Model/Traits/HasName.php b/src/Model/Traits/HasName.php index 12755bb..bbf3553 100644 --- a/src/Model/Traits/HasName.php +++ b/src/Model/Traits/HasName.php @@ -11,9 +11,7 @@ */ trait HasName { - /** - * @ORM\Column(type="string", length=191) - */ + #[ORM\Column(type: 'string', length: 191)] private string $name = ''; /** diff --git a/src/Model/Traits/HasOtp.php b/src/Model/Traits/HasOtp.php index 1e913e8..5987147 100644 --- a/src/Model/Traits/HasOtp.php +++ b/src/Model/Traits/HasOtp.php @@ -6,7 +6,7 @@ use Doctrine\ORM\Mapping as ORM; use Exception; -use GraphQL\Doctrine\Annotation as API; +use GraphQL\Doctrine\Attribute as API; use OTPHP; /** @@ -14,15 +14,11 @@ */ trait HasOtp { - /** - * @ORM\Column(type="boolean", options={"default" = 0}) - */ + #[ORM\Column(type: 'boolean', options: ['default' => 0])] private bool $otp = false; - /** - * @API\Exclude - * @ORM\Column(type="string", length=255, nullable=true) - */ + #[ORM\Column(type: 'string', length: 255, nullable: true)] + #[API\Exclude] private ?string $otpUri = null; /** @@ -33,9 +29,8 @@ abstract public function getLogin(): ?string; /** * Enable 2FA for the user * This should be only enabled after otpUri has been generated, stored and verified. - * - * @API\Exclude */ + #[API\Exclude] public function setOtp(bool $otp): void { if ($otp && empty($this->otpUri)) { @@ -55,9 +50,8 @@ public function isOtp(): bool /** * Returns the OTP provisionning URI (to display QR code). - * - * @API\Exclude */ + #[API\Exclude] public function getOtpUri(): ?string { return $this->otpUri; @@ -67,9 +61,8 @@ public function getOtpUri(): ?string * Generate and store a new OTP secret. * * @param string $issuer identify the service that provided the OTP (application or host name) - * - * @API\Exclude */ + #[API\Exclude] public function createOtpSecret(string $issuer): void { $this->revokeOtpSecret(); @@ -87,9 +80,8 @@ public function createOtpSecret(string $issuer): void /** * Revoke the existing OTP secret * This will also disable 2FA. - * - * @API\Exclude */ + #[API\Exclude] public function revokeOtpSecret(): void { $this->otp = false; @@ -98,9 +90,8 @@ public function revokeOtpSecret(): void /** * Verify an OTP received from the user. - * - * @API\Exclude */ + #[API\Exclude] public function verifyOtp(string $received): bool { if (empty($this->otpUri)) { diff --git a/src/Model/Traits/HasPassword.php b/src/Model/Traits/HasPassword.php index d5ca7db..2af345e 100644 --- a/src/Model/Traits/HasPassword.php +++ b/src/Model/Traits/HasPassword.php @@ -6,31 +6,26 @@ use Cake\Chronos\Chronos; use Doctrine\ORM\Mapping as ORM; -use GraphQL\Doctrine\Annotation as API; +use GraphQL\Doctrine\Attribute as API; /** * Trait for a user with a password and password reset capabilities. */ trait HasPassword { - /** - * @API\Exclude - * @ORM\Column(type="string", length=255) - */ + #[ORM\Column(type: 'string', length: 255)] + #[API\Exclude] private string $password = ''; - /** - * @API\Exclude - * @ORM\Column(type="string", length=32, nullable=true, unique=true) - */ + #[ORM\Column(type: 'string', length: 32, nullable: true, unique: true)] + #[API\Exclude] private ?string $token = null; /** * The time when user asked to reset password. - * - * @API\Exclude - * @ORM\Column(type="datetime", nullable=true) */ + #[ORM\Column(type: 'datetime', nullable: true)] + #[API\Exclude] private ?Chronos $tokenCreationDate = null; /** @@ -53,9 +48,8 @@ public function setPassword(string $password): void /** * Returns the hashed password. - * - * @API\Exclude */ + #[API\Exclude] public function getPassword(): string { return $this->password; @@ -83,9 +77,8 @@ public function revokeToken(): void /** * Check if token is valid. - * - * @API\Exclude */ + #[API\Exclude] public function isTokenValid(): bool { if (!$this->tokenCreationDate) { diff --git a/src/Model/Traits/HasUrl.php b/src/Model/Traits/HasUrl.php index d0a4301..536089e 100644 --- a/src/Model/Traits/HasUrl.php +++ b/src/Model/Traits/HasUrl.php @@ -5,23 +5,20 @@ namespace Ecodev\Felix\Model\Traits; use Doctrine\ORM\Mapping as ORM; -use GraphQL\Doctrine\Annotation as API; +use GraphQL\Doctrine\Attribute as API; /** * Trait for all objects with an URL. */ trait HasUrl { - /** - * @ORM\Column(type="string", length=2000, options={"default" = ""}) - */ + #[ORM\Column(type: 'string', length: 2000, options: ['default' => ''])] private string $url = ''; /** * Set url. - * - * @API\Input(type="Url") */ + #[API\Input(type: 'Url')] public function setUrl(string $url): void { $this->url = $url; @@ -29,9 +26,8 @@ public function setUrl(string $url): void /** * Get url. - * - * @API\Field(type="Url") */ + #[API\Field(type: 'Url')] public function getUrl(): string { return $this->url; diff --git a/src/Model/Traits/Image.php b/src/Model/Traits/Image.php index 8a1f59a..515b99e 100644 --- a/src/Model/Traits/Image.php +++ b/src/Model/Traits/Image.php @@ -5,7 +5,7 @@ namespace Ecodev\Felix\Model\Traits; use Doctrine\ORM\Mapping as ORM; -use GraphQL\Doctrine\Annotation as API; +use GraphQL\Doctrine\Attribute as API; use Imagine\Filter\Basic\Autorotate; use Imagine\Image\ImagineInterface; use Psr\Http\Message\UploadedFileInterface; @@ -38,14 +38,10 @@ protected function getAcceptedMimeTypes(): array ]; } - /** - * @ORM\Column(type="integer") - */ + #[ORM\Column(type: 'integer')] private int $width = 0; - /** - * @ORM\Column(type="integer") - */ + #[ORM\Column(type: 'integer')] private int $height = 0; /** @@ -58,9 +54,8 @@ public function getWidth(): int /** * Set image width. - * - * @API\Exclude */ + #[API\Exclude] public function setWidth(int $width): void { $this->width = $width; @@ -76,9 +71,8 @@ public function getHeight(): int /** * Set image height. - * - * @API\Exclude */ + #[API\Exclude] public function setHeight(int $height): void { $this->height = $height; diff --git a/src/Model/Traits/Log.php b/src/Model/Traits/Log.php index 2da9994..ce2b782 100644 --- a/src/Model/Traits/Log.php +++ b/src/Model/Traits/Log.php @@ -5,7 +5,7 @@ namespace Ecodev\Felix\Model\Traits; use Doctrine\ORM\Mapping as ORM; -use GraphQL\Doctrine\Annotation as API; +use GraphQL\Doctrine\Attribute as API; /** * Log. @@ -14,37 +14,26 @@ trait Log { use HasUrl; - /** - * @ORM\Column(type="smallint") - */ + #[ORM\Column(type: 'smallint')] private int $priority; - /** - * @ORM\Column(type="string", length=5000, nullable=false) - */ + #[ORM\Column(type: 'string', length: 5000, nullable: false)] private string $message = ''; - /** - * @ORM\Column(type="string", length=500, nullable=false) - */ + #[ORM\Column(type: 'string', length: 500, nullable: false)] private string $referer = ''; - /** - * @ORM\Column(type="string", length=1000, nullable=false) - */ + #[ORM\Column(type: 'string', length: 1000, nullable: false)] private string $request = ''; - /** - * @ORM\Column(type="string", length=40, nullable=false) - */ + #[ORM\Column(type: 'string', length: 40, nullable: false)] private string $ip = ''; /** * The statistics data. - * - * @API\Exclude - * @ORM\Column(type="json", options={"default" = "[]"}) */ + #[ORM\Column(type: 'json', options: ['default' => '[]'])] + #[API\Exclude] private array $extra = []; /** @@ -127,17 +116,13 @@ public function getIp(): string return $this->ip; } - /** - * @API\Exclude - */ + #[API\Exclude] public function getExtra(): array { return $this->extra; } - /** - * @API\Exclude - */ + #[API\Exclude] public function setExtra(array $extra): void { $this->extra = $extra; diff --git a/src/Model/Traits/Message.php b/src/Model/Traits/Message.php index 847654c..a2edac9 100644 --- a/src/Model/Traits/Message.php +++ b/src/Model/Traits/Message.php @@ -6,43 +6,32 @@ use Cake\Chronos\Chronos; use Doctrine\ORM\Mapping as ORM; -use GraphQL\Doctrine\Annotation as API; +use GraphQL\Doctrine\Attribute as API; /** * A message sent to a user. */ trait Message { - /** - * @ORM\Column(type="string", length=191) - */ + #[ORM\Column(type: 'string', length: 191)] private string $email = ''; - /** - * @ORM\Column(type="MessageType") - */ + #[ORM\Column(type: 'MessageType')] private string $type; - /** - * @ORM\Column(type="datetime", nullable=true) - */ + #[ORM\Column(type: 'datetime', nullable: true)] private ?Chronos $dateSent = null; - /** - * @ORM\Column(type="string", length=255, options={"default" = ""}) - */ + #[ORM\Column(type: 'string', length: 255, options: ['default' => ''])] private string $subject = ''; - /** - * @ORM\Column(type="text", length=65535, options={"default" = ""}) - */ + #[ORM\Column(type: 'text', length: 65535, options: ['default' => ''])] private string $body = ''; /** * Set type. - * - * @API\Input(type="MessageType") */ + #[API\Input(type: 'MessageType')] public function setType(string $type): void { $this->type = $type; @@ -50,9 +39,8 @@ public function setType(string $type): void /** * Get type. - * - * @API\Field(type="MessageType") */ + #[API\Field(type: 'MessageType')] public function getType(): string { return $this->type; @@ -88,9 +76,8 @@ public function getDateSent(): ?Chronos /** * Set sent time. - * - * @API\Exclude */ + #[API\Exclude] public function setDateSent(?Chronos $dateSent): void { $this->dateSent = $dateSent; diff --git a/tests/Blog/Model/AbstractModel.php b/tests/Blog/Model/AbstractModel.php index 5a81d98..17c0a58 100644 --- a/tests/Blog/Model/AbstractModel.php +++ b/tests/Blog/Model/AbstractModel.php @@ -10,16 +10,13 @@ /** * Base class for all objects stored in database. - * - * @ORM\MappedSuperclass */ +#[ORM\MappedSuperclass] abstract class AbstractModel implements HasOwner, Model { - /** - * @ORM\Column(type="integer", options={"unsigned" = true}) - * @ORM\Id - * @ORM\GeneratedValue(strategy="IDENTITY") - */ + #[ORM\Column(type: 'integer', options: ['unsigned' => true])] + #[ORM\Id] + #[ORM\GeneratedValue(strategy: 'IDENTITY')] protected ?int $id = null; private ?User $owner = null; diff --git a/tests/Blog/Model/Post.php b/tests/Blog/Model/Post.php index d0b620c..ace208c 100644 --- a/tests/Blog/Model/Post.php +++ b/tests/Blog/Model/Post.php @@ -8,23 +8,16 @@ /** * A blog post with title and body. - * - * @ORM\Entity(repositoryClass="EcodevTests\Felix\Blog\Repository\PostRepository") */ +#[ORM\Entity(repositoryClass: 'EcodevTests\Felix\Blog\Repository\PostRepository')] final class Post extends AbstractModel { - /** - * @ORM\Column(type="string", length=50, options={"default" = ""}) - */ + #[ORM\Column(type: 'string', length: 50, options: ['default' => ''])] private string $title = ''; - /** - * @ORM\Column(type="text") - */ + #[ORM\Column(type: 'text')] private string $body = ''; - /** - * @ORM\ManyToOne(targetEntity="EcodevTests\Felix\Blog\Model\User", inversedBy="posts") - */ + #[ORM\ManyToOne(targetEntity: 'EcodevTests\Felix\Blog\Model\User', inversedBy: 'posts')] private User $user; } diff --git a/tests/Blog/Model/User.php b/tests/Blog/Model/User.php index 33e39b1..9e91e05 100644 --- a/tests/Blog/Model/User.php +++ b/tests/Blog/Model/User.php @@ -7,34 +7,25 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\Mapping as ORM; use Ecodev\Felix\Acl\MultipleRoles; -use GraphQL\Doctrine\Annotation as API; +use GraphQL\Doctrine\Attribute as API; /** * A blog author. - * - * @ORM\Entity */ +#[ORM\Entity] final class User extends AbstractModel implements \Ecodev\Felix\Model\User { - /** - * @ORM\Column(name="custom_column_name", type="string", length=50, options={"default" = ""}) - */ + #[ORM\Column(name: 'custom_column_name', type: 'string', length: 50, options: ['default' => ''])] private string $name = ''; - /** - * @ORM\Column(type="string", length=50, nullable=true) - */ + #[ORM\Column(type: 'string', length: 50, nullable: true)] private ?string $email = null; - /** - * @ORM\Column(name="password", type="string", length=255) - * @Api\Exclude - */ + #[ORM\Column(name: 'password', type: 'string', length: 255)] + #[API\Exclude] private string $password; - /** - * @ORM\OneToMany(targetEntity="EcodevTests\Felix\Blog\Model\Post", mappedBy="user") - */ + #[ORM\OneToMany(targetEntity: 'EcodevTests\Felix\Blog\Model\Post', mappedBy: 'user')] private Collection $posts; public function __construct(private MultipleRoles|string $role = 'member') diff --git a/tests/Traits/TestWithEntityManager.php b/tests/Traits/TestWithEntityManager.php index 002cc9e..7b66c82 100644 --- a/tests/Traits/TestWithEntityManager.php +++ b/tests/Traits/TestWithEntityManager.php @@ -20,7 +20,7 @@ trait TestWithEntityManager public function setUp(): void { // Create the entity manager - $config = ORMSetup::createAnnotationMetadataConfiguration([__DIR__ . '/Blog/Model'], true); + $config = ORMSetup::createAttributeMetadataConfiguration([__DIR__ . '/Blog/Model'], true); $config->addCustomNumericFunction('native_in', NativeIn::class); $config->setNamingStrategy(new UnderscoreNamingStrategy(CASE_LOWER, true));