yiisoft /
demo
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace App\User; |
||
| 6 | |||
| 7 | use App\Auth\Identity; |
||
| 8 | use App\Blog\Entity\Comment; |
||
| 9 | use App\Blog\Entity\Post; |
||
| 10 | use Cycle\Annotated\Annotation\Column; |
||
|
0 ignored issues
–
show
|
|||
| 11 | use Cycle\Annotated\Annotation\Entity; |
||
|
0 ignored issues
–
show
The type
Cycle\Annotated\Annotation\Entity was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 12 | use Cycle\Annotated\Annotation\Relation\HasMany; |
||
|
0 ignored issues
–
show
The type
Cycle\Annotated\Annotation\Relation\HasMany was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 13 | use Cycle\Annotated\Annotation\Relation\HasOne; |
||
|
0 ignored issues
–
show
The type
Cycle\Annotated\Annotation\Relation\HasOne was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 14 | use Cycle\Annotated\Annotation\Table\Index; |
||
|
0 ignored issues
–
show
The type
Cycle\Annotated\Annotation\Table\Index was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 15 | use Cycle\ORM\Entity\Behavior; |
||
|
0 ignored issues
–
show
The type
Cycle\ORM\Entity\Behavior was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 16 | use DateTimeImmutable; |
||
| 17 | use Doctrine\Common\Collections\ArrayCollection; |
||
|
0 ignored issues
–
show
The type
Doctrine\Common\Collections\ArrayCollection was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 18 | use Yiisoft\Security\PasswordHasher; |
||
|
0 ignored issues
–
show
The type
Yiisoft\Security\PasswordHasher was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 19 | |||
| 20 | #[Entity(repository: UserRepository::class)] |
||
| 21 | #[Index(columns: ['login'], unique: true)] |
||
| 22 | #[Behavior\CreatedAt(field: 'created_at', column: 'created_at')] |
||
| 23 | #[Behavior\UpdatedAt(field: 'updated_at', column: 'updated_at')] |
||
| 24 | class User |
||
| 25 | { |
||
| 26 | #[Column(type: 'primary')] |
||
| 27 | private ?int $id = null; |
||
| 28 | |||
| 29 | #[Column(type: 'string(48)')] |
||
| 30 | private string $login; |
||
| 31 | |||
| 32 | #[Column(type: 'string')] |
||
| 33 | private string $passwordHash; |
||
| 34 | |||
| 35 | #[Column(type: 'datetime')] |
||
| 36 | private DateTimeImmutable $created_at; |
||
| 37 | |||
| 38 | #[Column(type: 'datetime')] |
||
| 39 | private DateTimeImmutable $updated_at; |
||
| 40 | |||
| 41 | #[HasOne(target: Identity::class)] |
||
| 42 | private Identity $identity; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var ArrayCollection<array-key, Post> |
||
| 46 | */ |
||
| 47 | #[HasMany(target: Post::class)] |
||
| 48 | private ArrayCollection $posts; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var ArrayCollection<array-key, Comment> |
||
| 52 | */ |
||
| 53 | #[HasMany(target: Comment::class)] |
||
| 54 | private ArrayCollection $comments; |
||
| 55 | |||
| 56 | public function __construct(string $login, string $password) |
||
| 57 | { |
||
| 58 | $this->login = $login; |
||
| 59 | $this->created_at = new DateTimeImmutable(); |
||
| 60 | $this->updated_at = new DateTimeImmutable(); |
||
| 61 | $this->setPassword($password); |
||
| 62 | $this->identity = new Identity(); |
||
| 63 | $this->posts = new ArrayCollection(); |
||
| 64 | $this->comments = new ArrayCollection(); |
||
| 65 | } |
||
| 66 | |||
| 67 | public function getId(): ?string |
||
| 68 | { |
||
| 69 | return $this->id === null ? null : (string) $this->id; |
||
| 70 | } |
||
| 71 | |||
| 72 | public function getLogin(): string |
||
| 73 | { |
||
| 74 | return $this->login; |
||
| 75 | } |
||
| 76 | |||
| 77 | public function setLogin(string $login): void |
||
| 78 | { |
||
| 79 | $this->login = $login; |
||
| 80 | } |
||
| 81 | |||
| 82 | public function validatePassword(string $password): bool |
||
| 83 | { |
||
| 84 | return (new PasswordHasher())->validate($password, $this->passwordHash); |
||
| 85 | } |
||
| 86 | |||
| 87 | public function setPassword(string $password): void |
||
| 88 | { |
||
| 89 | $this->passwordHash = (new PasswordHasher())->hash($password); |
||
| 90 | } |
||
| 91 | |||
| 92 | public function getCreatedAt(): DateTimeImmutable |
||
| 93 | { |
||
| 94 | return $this->created_at; |
||
| 95 | } |
||
| 96 | |||
| 97 | public function getUpdatedAt(): DateTimeImmutable |
||
| 98 | { |
||
| 99 | return $this->updated_at; |
||
| 100 | } |
||
| 101 | |||
| 102 | public function getIdentity(): Identity |
||
| 103 | { |
||
| 104 | return $this->identity; |
||
| 105 | } |
||
| 106 | |||
| 107 | /** |
||
| 108 | * @return Post[] |
||
| 109 | */ |
||
| 110 | public function getPosts(): array |
||
| 111 | { |
||
| 112 | return $this->posts->toArray(); |
||
| 113 | } |
||
| 114 | |||
| 115 | public function addPost(Post $post): void |
||
| 116 | { |
||
| 117 | $this->posts->add($post); |
||
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return Comment[] |
||
| 122 | */ |
||
| 123 | public function getComments(): array |
||
| 124 | { |
||
| 125 | return $this->comments->toArray(); |
||
| 126 | } |
||
| 127 | |||
| 128 | public function addComment(Comment $post): void |
||
| 129 | { |
||
| 130 | $this->comments->add($post); |
||
| 131 | } |
||
| 132 | } |
||
| 133 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths