1111use Core \App \Entity \RoleInterface ;
1212use Core \App \Entity \TimestampsTrait ;
1313use Core \Setting \Entity \Setting ;
14+ use DateTimeImmutable ;
1415use Doctrine \Common \Collections \ArrayCollection ;
1516use Doctrine \Common \Collections \Collection ;
1617use Doctrine \ORM \Mapping as ORM ;
1718use League \OAuth2 \Server \Entities \UserEntityInterface ;
1819
1920use function array_map ;
2021
22+ /**
23+ * @phpstan-import-type RoleType from RoleInterface
24+ */
2125#[ORM \Entity(repositoryClass: AdminRepository::class)]
2226#[ORM \Table(name: 'admin ' )]
2327#[ORM \HasLifecycleCallbacks]
@@ -26,6 +30,7 @@ class Admin extends AbstractEntity implements UserEntityInterface
2630 use PasswordTrait;
2731 use TimestampsTrait;
2832
33+ /** @var non-empty-string|null $identity */
2934 #[ORM \Column(name: 'identity ' , type: 'string ' , length: 191 , unique: true )]
3035 protected ?string $ identity = null ;
3136
@@ -45,12 +50,14 @@ enumType: AdminStatusEnum::class,
4550 )]
4651 protected AdminStatusEnum $ status = AdminStatusEnum::Active;
4752
53+ /** @var Collection<int, RoleInterface> $roles */
4854 #[ORM \ManyToMany(targetEntity: AdminRole::class)]
4955 #[ORM \JoinTable(name: 'admin_roles ' )]
5056 #[ORM \JoinColumn(name: 'userUuid ' , referencedColumnName: 'uuid ' )]
5157 #[ORM \InverseJoinColumn(name: 'roleUuid ' , referencedColumnName: 'uuid ' )]
5258 protected Collection $ roles ;
5359
60+ /** @var Collection<int, Setting> $settings */
5461 #[ORM \OneToMany(targetEntity: Setting::class, mappedBy: 'admin ' )]
5562 protected Collection $ settings ;
5663
@@ -73,6 +80,9 @@ public function hasIdentity(): bool
7380 return $ this ->identity !== null ;
7481 }
7582
83+ /**
84+ * @param non-empty-string $identity
85+ */
7686 public function setIdentity (string $ identity ): self
7787 {
7888 $ this ->identity = $ identity ;
@@ -128,14 +138,22 @@ public function setStatus(AdminStatusEnum $status): self
128138 return $ this ;
129139 }
130140
141+ /**
142+ * @return RoleInterface[]
143+ */
131144 public function getRoles (): array
132145 {
133146 return $ this ->roles ->toArray ();
134147 }
135148
136- public function setRoles (ArrayCollection $ roles ): self
149+ /**
150+ * @param RoleInterface[] $roles
151+ */
152+ public function setRoles (array $ roles ): self
137153 {
138- $ this ->roles = $ roles ;
154+ foreach ($ roles as $ role ) {
155+ $ this ->roles ->add ($ role );
156+ }
139157
140158 return $ this ;
141159 }
@@ -196,9 +214,21 @@ public function isActive(): bool
196214
197215 public function getIdentifier (): string
198216 {
199- return $ this ->identity ;
200- }
201-
217+ return (string ) $ this ->identity ;
218+ }
219+
220+ /**
221+ * @return array{
222+ * uuid: non-empty-string,
223+ * identity: non-empty-string|null,
224+ * firstName: string|null,
225+ * lastName: string|null,
226+ * status: non-empty-string,
227+ * roles: iterable<RoleType>,
228+ * created: DateTimeImmutable,
229+ * updated: DateTimeImmutable|null,
230+ * }
231+ */
202232 public function getArrayCopy (): array
203233 {
204234 return [
@@ -207,7 +237,7 @@ public function getArrayCopy(): array
207237 'firstName ' => $ this ->firstName ,
208238 'lastName ' => $ this ->lastName ,
209239 'status ' => $ this ->status ->value ,
210- 'roles ' => array_map (fn (AdminRole $ role ): array => $ role ->getArrayCopy (), $ this ->roles ->toArray ()),
240+ 'roles ' => array_map (fn (RoleInterface $ role ): array => $ role ->getArrayCopy (), $ this ->roles ->toArray ()),
211241 'created ' => $ this ->created ,
212242 'updated ' => $ this ->updated ,
213243 ];
0 commit comments