| Conditions | 6 |
| Paths | 5 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 42 |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 32 | public function validate($user, Constraint $constraint): void |
||
| 33 | { |
||
| 34 | if (!$user instanceof User) { |
||
| 35 | throw new UnexpectedTypeException($user, User::class); |
||
| 36 | } |
||
| 37 | |||
| 38 | if (!$user->getUsername() || !$user->getNewUsername()) { |
||
| 39 | return; |
||
| 40 | } |
||
| 41 | if ($user->getNewUsername() === $user->getUsername()) { |
||
| 42 | $this->context->buildViolation($constraint->differentMessage) |
||
| 43 | ->addViolation(); |
||
| 44 | |||
| 45 | return; |
||
| 46 | } |
||
| 47 | |||
| 48 | if ($this->userRepository->findOneBy(['username' => $user->getNewUsername()])) { |
||
| 49 | $this->context->buildViolation($constraint->uniqueMessage) |
||
| 50 | ->addViolation(); |
||
| 51 | |||
| 52 | return; |
||
| 53 | } |
||
| 56 |