Conditions | 13 |
Paths | 12 |
Total Lines | 36 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 182 |
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 |
||
21 | public function checkPrivilegeFor(int $shipId, UserInterface $user): bool |
||
22 | { |
||
23 | $privileges = $this->dockingPrivilegeRepository->getByShip($shipId); |
||
24 | if ($privileges === []) { |
||
25 | return false; |
||
26 | } |
||
27 | $allowed = false; |
||
28 | foreach ($privileges as $priv) { |
||
29 | switch ($priv->getPrivilegeType()) { |
||
30 | case ShipEnum::DOCK_PRIVILEGE_USER: |
||
31 | if ($priv->getTargetId() === $user->getId()) { |
||
32 | if ($priv->getPrivilegeMode() == ShipEnum::DOCK_PRIVILEGE_MODE_DENY) { |
||
33 | return false; |
||
34 | } |
||
35 | $allowed = true; |
||
36 | } |
||
37 | break; |
||
38 | case ShipEnum::DOCK_PRIVILEGE_ALLIANCE: |
||
39 | if ($user->getAlliance() !== null && $priv->getTargetId() === $user->getAlliance()->getId()) { |
||
40 | if ($priv->getPrivilegeMode() == ShipEnum::DOCK_PRIVILEGE_MODE_DENY) { |
||
41 | return false; |
||
42 | } |
||
43 | $allowed = true; |
||
44 | } |
||
45 | break; |
||
46 | case ShipEnum::DOCK_PRIVILEGE_FACTION: |
||
47 | if ($priv->getTargetId() == $user->getFactionId()) { |
||
48 | if ($priv->getPrivilegeMode() == ShipEnum::DOCK_PRIVILEGE_MODE_DENY) { |
||
49 | return false; |
||
50 | } |
||
51 | $allowed = true; |
||
52 | } |
||
53 | break; |
||
54 | } |
||
55 | } |
||
56 | return $allowed; |
||
57 | } |
||
59 |