| Conditions | 4 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 20 | public function validate($user, Constraint $constraint): void |
||
| 21 | { |
||
| 22 | if (!$user instanceof User) { |
||
| 23 | throw new UnexpectedTypeException($user, User::class); |
||
| 24 | } |
||
| 25 | |||
| 26 | if ($user->getNewUsername() === $user->getUsername()) { |
||
| 27 | $this->context->buildViolation($constraint->differentMessage) |
||
| 28 | ->addViolation(); |
||
| 29 | return; |
||
| 30 | } |
||
| 31 | |||
| 32 | if ($this->userRepository->findOneBy(['username' => $user->getNewUsername()])) { |
||
| 33 | $this->context->buildViolation($constraint->uniqueMessage) |
||
| 34 | ->addViolation(); |
||
| 35 | return; |
||
| 36 | } |
||
| 39 |