| Conditions | 16 |
| Paths | 8 |
| Total Lines | 67 |
| Code Lines | 56 |
| 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 |
||
| 106 | * Checks if the method is accessible. |
||
| 107 | * |
||
| 108 | * @param string $accessModifier access modifier |
||
| 109 | * @param \ReflectionClass $reflection class data |
||
| 110 | * @return bool result of the checkout |
||
| 111 | * @throws InternalError if not a valid it's impossible to check accessibility. |
||
| 112 | */ |
||
| 113 | private function isAccessible(string $accessModifier, \ReflectionClass $reflection): bool |
||
| 114 | { |
||
| 115 | if ($accessModifier == 'public') { |
||
| 116 | return true; |
||
| 117 | } |
||
| 118 | $isThis = $reflection->name == $this->backtrace['class']; |
||
| 119 | $inThisFile = $this->backtrace['file'] == $reflection->getFileName() && $this->in($reflection); |
||
| 120 | if ($accessModifier == 'private') { |
||
| 121 | return $isThis && $inThisFile; |
||
| 122 | } |
||
| 123 | $isThisBranch = is_subclass_of($this->backtrace['class'], $reflection->name) || is_subclass_of($reflection->name, |
||
| 124 | $this->backtrace['class']); |
||
| 125 | $reflection = new \ReflectionClass($this->class); |
||
| 126 | $inBranchFile = $this->backtrace['file'] == $reflection->getFileName() && $this->in(new \ReflectionClass($this->backtrace['class'])); |
||
| 127 | if ($accessModifier == 'protected') { |
||
| 128 | return ($isThis && $inThisFile) || ($isThis && $inBranchFile) || ($isThisBranch && $inBranchFile); |
||
| 129 | } |
||
| 130 | throw new InternalError('not a valid access modifier given'); |
||
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * Checks if the method called in right place and it is accessible there. |
||
| 135 | * |
||
| 136 | * @param \ReflectionClass $reflection class data |
||
| 137 | * @return bool result of the checkout |
||
| 138 | */ |
||
| 139 | private function in(\ReflectionClass $reflection): bool |
||
| 140 | { |
||
| 141 | return $reflection->getStartLine() <= $this->backtrace['line'] && $reflection->getEndLine() >= $this->backtrace['line']; |
||
| 142 | } |
||
| 143 | } |
||
| 144 |