| Conditions | 11 |
| Paths | 112 |
| Total Lines | 42 |
| Code Lines | 25 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 29 | public function __invoke(): ?AuditorUserInterface |
||
| 30 | { |
||
| 31 | $identifier = null; |
||
| 32 | $username = null; |
||
| 33 | $tokenUser = null; |
||
| 34 | |||
| 35 | $token = $this->getToken(); |
||
| 36 | if (null !== $token) { |
||
| 37 | $tokenUser = $token->getUser(); |
||
| 38 | } |
||
| 39 | |||
| 40 | $impersonatorUser = $this->getImpersonatorUser(); |
||
| 41 | |||
| 42 | if ($tokenUser instanceof UserInterface) { |
||
| 43 | if (method_exists($tokenUser, 'getId')) { |
||
| 44 | $identifier = $tokenUser->getId(); |
||
| 45 | } |
||
| 46 | |||
| 47 | $username = ''; |
||
| 48 | if (method_exists($tokenUser, 'getUserIdentifier')) { |
||
| 49 | $username = $tokenUser->getUserIdentifier(); |
||
| 50 | } elseif (method_exists($tokenUser, 'getUsername')) { |
||
| 51 | $username = $tokenUser->getUsername(); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | if ($impersonatorUser instanceof UserInterface) { |
||
| 56 | $impersonatorUsername = ''; |
||
| 57 | if (method_exists($impersonatorUser, 'getUserIdentifier')) { |
||
| 58 | $impersonatorUsername = $impersonatorUser->getUserIdentifier(); |
||
| 59 | } elseif (method_exists($impersonatorUser, 'getUsername')) { |
||
| 60 | $impersonatorUsername = $impersonatorUser->getUsername(); |
||
| 61 | } |
||
| 62 | |||
| 63 | $username .= '[impersonator '.$impersonatorUsername.']'; |
||
| 64 | } |
||
| 65 | |||
| 66 | if (null === $identifier && null === $username) { |
||
| 67 | return null; |
||
| 68 | } |
||
| 69 | |||
| 70 | return new User((string) $identifier, $username); |
||
| 71 | } |
||
| 99 |