Conditions | 10 |
Paths | 22 |
Total Lines | 37 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 0 | Features | 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 |
||
75 | protected function assert($value, $operator, $expected) |
||
76 | { |
||
77 | $businessEntity = null; |
||
78 | if ($this->currentViewHelper->getCurrentView() instanceof BusinessPage) { |
||
79 | $businessEntity = $this->currentViewHelper->getCurrentView()->getBusinessEntity(); |
||
80 | } |
||
81 | $result = false; |
||
82 | switch ($operator) { |
||
83 | case self::OPERAND_EQUAL: |
||
84 | $result = $value === $expected; |
||
85 | break; |
||
86 | case self::OPERAND_TRUE: |
||
87 | $result = $value == true; |
||
88 | break; |
||
89 | case self::OPERAND_FALSE: |
||
90 | $result = $value == false; |
||
91 | break; |
||
92 | case self::OPERAND_IN: |
||
93 | $result = in_array($value, unserialize($expected)); |
||
94 | break; |
||
95 | case self::IS_GRANTED: |
||
96 | case self::IS_NOT_GRANTED: |
||
97 | if (!$this->authorizationChecker->isGranted('ROLE_VICTOIRE')) { |
||
98 | $granted = $this->authorizationChecker->isGranted($expected, $businessEntity); |
||
99 | if ($operator === self::IS_GRANTED) { |
||
100 | $result = $granted; |
||
101 | } else { |
||
102 | $result = (false === $granted); |
||
103 | } |
||
104 | } else { |
||
105 | $result = true; |
||
106 | } |
||
107 | break; |
||
108 | } |
||
109 | |||
110 | return $result; |
||
111 | } |
||
112 | } |
||
113 |