tarlepp /
symfony-flex-backend
| 1 | <?php |
||
| 2 | declare(strict_types = 1); |
||
| 3 | /** |
||
| 4 | * /src/Rest/DTO/User/User.php |
||
| 5 | * |
||
| 6 | * @author TLe, Tarmo Leppänen <[email protected]> |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace App\DTO\User; |
||
| 10 | |||
| 11 | use App\DTO\RestDto; |
||
| 12 | use App\Entity\Interfaces\EntityInterface; |
||
| 13 | use App\Entity\Interfaces\UserGroupAwareInterface; |
||
| 14 | use App\Entity\User as Entity; |
||
| 15 | use App\Entity\UserGroup as UserGroupEntity; |
||
| 16 | use App\Enum\Language; |
||
| 17 | use App\Enum\Locale; |
||
| 18 | use App\Service\Localization; |
||
|
0 ignored issues
–
show
|
|||
| 19 | use App\Validator\Constraints as AppAssert; |
||
| 20 | use Symfony\Component\Validator\Constraints as Assert; |
||
| 21 | use function array_map; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * Class User |
||
| 25 | * |
||
| 26 | * @package App\DTO\User |
||
| 27 | * @author TLe, Tarmo Leppänen <[email protected]> |
||
| 28 | * |
||
| 29 | * @method Entity|EntityInterface update(EntityInterface $entity) |
||
| 30 | * |
||
| 31 | * @psalm-consistent-constructor |
||
| 32 | */ |
||
| 33 | #[AppAssert\UniqueEmail] |
||
| 34 | #[AppAssert\UniqueUsername] |
||
| 35 | class User extends RestDto |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * @var array<string, string> |
||
| 39 | */ |
||
| 40 | protected static array $mappings = [ |
||
| 41 | 'password' => 'updatePassword', |
||
| 42 | 'userGroups' => 'updateUserGroups', |
||
| 43 | ]; |
||
| 44 | |||
| 45 | #[Assert\NotBlank] |
||
| 46 | #[Assert\NotNull] |
||
| 47 | #[Assert\Length(min: 2, max: 255)] |
||
| 48 | protected string $username = ''; |
||
| 49 | |||
| 50 | #[Assert\NotBlank] |
||
| 51 | #[Assert\NotNull] |
||
| 52 | #[Assert\Length(min: 2, max: 255)] |
||
| 53 | protected string $firstName = ''; |
||
| 54 | |||
| 55 | #[Assert\NotBlank] |
||
| 56 | #[Assert\NotNull] |
||
| 57 | #[Assert\Length(min: 2, max: 255)] |
||
| 58 | protected string $lastName = ''; |
||
| 59 | |||
| 60 | #[Assert\NotBlank] |
||
| 61 | #[Assert\NotNull] |
||
| 62 | #[Assert\Email] |
||
| 63 | protected string $email = ''; |
||
| 64 | |||
| 65 | #[Assert\NotBlank] |
||
| 66 | #[Assert\NotNull] |
||
| 67 | protected Language $language; |
||
| 68 | |||
| 69 | #[Assert\NotBlank] |
||
| 70 | #[Assert\NotNull] |
||
| 71 | protected Locale $locale; |
||
| 72 | |||
| 73 | #[Assert\NotBlank] |
||
| 74 | #[Assert\NotNull] |
||
| 75 | #[AppAssert\Timezone] |
||
| 76 | protected string $timezone = Localization::DEFAULT_TIMEZONE; |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @var UserGroupEntity[]|array<int, UserGroupEntity> |
||
| 80 | */ |
||
| 81 | #[AppAssert\EntityReferenceExists(entityClass: UserGroupEntity::class)] |
||
| 82 | protected array $userGroups = []; |
||
| 83 | |||
| 84 | protected string $password = ''; |
||
| 85 | |||
| 86 | 166 | public function __construct() |
|
| 87 | { |
||
| 88 | 166 | $this->language = Language::getDefault(); |
|
| 89 | 166 | $this->locale = Locale::getDefault(); |
|
| 90 | } |
||
| 91 | |||
| 92 | 9 | public function getUsername(): string |
|
| 93 | { |
||
| 94 | 9 | return $this->username; |
|
| 95 | } |
||
| 96 | |||
| 97 | 21 | public function setUsername(string $username): self |
|
| 98 | { |
||
| 99 | 21 | $this->setVisited('username'); |
|
| 100 | |||
| 101 | 21 | $this->username = $username; |
|
| 102 | |||
| 103 | 21 | return $this; |
|
| 104 | } |
||
| 105 | |||
| 106 | 8 | public function getFirstName(): string |
|
| 107 | { |
||
| 108 | 8 | return $this->firstName; |
|
| 109 | } |
||
| 110 | |||
| 111 | 19 | public function setFirstName(string $firstName): self |
|
| 112 | { |
||
| 113 | 19 | $this->setVisited('firstName'); |
|
| 114 | |||
| 115 | 19 | $this->firstName = $firstName; |
|
| 116 | |||
| 117 | 19 | return $this; |
|
| 118 | } |
||
| 119 | |||
| 120 | 8 | public function getLastName(): string |
|
| 121 | { |
||
| 122 | 8 | return $this->lastName; |
|
| 123 | } |
||
| 124 | |||
| 125 | 19 | public function setLastName(string $lastName): self |
|
| 126 | { |
||
| 127 | 19 | $this->setVisited('lastName'); |
|
| 128 | |||
| 129 | 19 | $this->lastName = $lastName; |
|
| 130 | |||
| 131 | 19 | return $this; |
|
| 132 | } |
||
| 133 | |||
| 134 | 11 | public function getEmail(): string |
|
| 135 | { |
||
| 136 | 11 | return $this->email; |
|
| 137 | } |
||
| 138 | |||
| 139 | 23 | public function setEmail(string $email): self |
|
| 140 | { |
||
| 141 | 23 | $this->setVisited('email'); |
|
| 142 | |||
| 143 | 23 | $this->email = $email; |
|
| 144 | |||
| 145 | 23 | return $this; |
|
| 146 | } |
||
| 147 | |||
| 148 | 14 | public function getLanguage(): Language |
|
| 149 | { |
||
| 150 | 14 | return $this->language; |
|
| 151 | } |
||
| 152 | |||
| 153 | 19 | public function setLanguage(Language $language): self |
|
| 154 | { |
||
| 155 | 19 | $this->setVisited('language'); |
|
| 156 | |||
| 157 | 19 | $this->language = $language; |
|
| 158 | |||
| 159 | 19 | return $this; |
|
| 160 | } |
||
| 161 | |||
| 162 | 7 | public function getLocale(): Locale |
|
| 163 | { |
||
| 164 | 7 | return $this->locale; |
|
| 165 | } |
||
| 166 | |||
| 167 | 12 | public function setLocale(Locale $locale): self |
|
| 168 | { |
||
| 169 | 12 | $this->setVisited('locale'); |
|
| 170 | |||
| 171 | 12 | $this->locale = $locale; |
|
| 172 | |||
| 173 | 12 | return $this; |
|
| 174 | } |
||
| 175 | |||
| 176 | 6 | public function getTimezone(): string |
|
| 177 | { |
||
| 178 | 6 | return $this->timezone; |
|
| 179 | } |
||
| 180 | |||
| 181 | 11 | public function setTimezone(string $timezone): self |
|
| 182 | { |
||
| 183 | 11 | $this->setVisited('timezone'); |
|
| 184 | |||
| 185 | 11 | $this->timezone = $timezone; |
|
| 186 | |||
| 187 | 11 | return $this; |
|
| 188 | } |
||
| 189 | |||
| 190 | /** |
||
| 191 | * @return array<int, UserGroupEntity> |
||
| 192 | */ |
||
| 193 | 10 | public function getUserGroups(): array |
|
| 194 | { |
||
| 195 | 10 | return $this->userGroups; |
|
| 196 | } |
||
| 197 | |||
| 198 | /** |
||
| 199 | * @param array<int, UserGroupEntity> $userGroups |
||
| 200 | */ |
||
| 201 | 16 | public function setUserGroups(array $userGroups): self |
|
| 202 | { |
||
| 203 | 16 | $this->setVisited('userGroups'); |
|
| 204 | |||
| 205 | 16 | $this->userGroups = $userGroups; |
|
| 206 | |||
| 207 | 16 | return $this; |
|
| 208 | } |
||
| 209 | |||
| 210 | 5 | public function getPassword(): string |
|
| 211 | { |
||
| 212 | 5 | return $this->password; |
|
| 213 | } |
||
| 214 | |||
| 215 | 12 | public function setPassword(?string $password = null): self |
|
| 216 | { |
||
| 217 | 12 | if ($password !== null) { |
|
| 218 | 12 | $this->setVisited('password'); |
|
| 219 | |||
| 220 | 12 | $this->password = $password; |
|
| 221 | } |
||
| 222 | |||
| 223 | 12 | return $this; |
|
| 224 | } |
||
| 225 | |||
| 226 | /** |
||
| 227 | * {@inheritdoc} |
||
| 228 | * |
||
| 229 | * @param EntityInterface|Entity $entity |
||
| 230 | */ |
||
| 231 | 15 | public function load(EntityInterface $entity): self |
|
| 232 | { |
||
| 233 | 15 | if ($entity instanceof Entity) { |
|
| 234 | 15 | $this->id = $entity->getId(); |
|
| 235 | 15 | $this->username = $entity->getUsername(); |
|
| 236 | 15 | $this->firstName = $entity->getFirstName(); |
|
| 237 | 15 | $this->lastName = $entity->getLastName(); |
|
| 238 | 15 | $this->email = $entity->getEmail(); |
|
| 239 | 15 | $this->language = $entity->getLanguage(); |
|
| 240 | 15 | $this->locale = $entity->getLocale(); |
|
| 241 | 15 | $this->timezone = $entity->getTimezone(); |
|
| 242 | |||
| 243 | /** @var array<int, UserGroupEntity> $groups */ |
||
| 244 | 15 | $groups = $entity->getUserGroups()->toArray(); |
|
| 245 | |||
| 246 | 15 | $this->userGroups = $groups; |
|
| 247 | } |
||
| 248 | |||
| 249 | 15 | return $this; |
|
| 250 | } |
||
| 251 | |||
| 252 | /** |
||
| 253 | * Method to update User entity password. |
||
| 254 | */ |
||
| 255 | 3 | protected function updatePassword(Entity $entity, string $value): self |
|
| 256 | { |
||
| 257 | 3 | $entity->setPlainPassword($value); |
|
| 258 | |||
| 259 | 3 | return $this; |
|
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Method to update User entity user groups. |
||
| 264 | * |
||
| 265 | * @param array<int, UserGroupEntity> $value |
||
| 266 | */ |
||
| 267 | 2 | protected function updateUserGroups(UserGroupAwareInterface $entity, array $value): self |
|
| 268 | { |
||
| 269 | 2 | $entity->clearUserGroups(); |
|
| 270 | |||
| 271 | 2 | array_map( |
|
| 272 | 2 | static fn (UserGroupEntity $userGroup): UserGroupAwareInterface => $entity->addUserGroup($userGroup), |
|
| 273 | 2 | $value, |
|
| 274 | 2 | ); |
|
| 275 | |||
| 276 | 2 | return $this; |
|
| 277 | } |
||
| 278 | } |
||
| 279 |
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