| Conditions | 10 |
| Paths | 22 |
| Total Lines | 37 |
| Code Lines | 22 |
| 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 |
||
| 132 | private function validateKey(KeyManagerInterface $key, $algorithm) |
||
| 133 | { |
||
| 134 | $header = [ |
||
| 135 | 'R' => ['BEGIN PRIVATE KEY', 'BEGIN ENCRYPTED PRIVATE KEY'], |
||
| 136 | 'E' => 'BEGIN EC PRIVATE KEY' |
||
| 137 | ]; |
||
| 138 | |||
| 139 | if ($algorithm[0] === 'H') { |
||
| 140 | return; |
||
| 141 | } |
||
| 142 | |||
| 143 | $content = $key->getContent(); |
||
| 144 | |||
| 145 | if (is_array($header[$algorithm[0]])) { |
||
| 146 | foreach ($header[$algorithm[0]] as $h) { |
||
|
|
|||
| 147 | $isHeaderMatched = strpos($content, $h) === false |
||
| 148 | ? false |
||
| 149 | : true; |
||
| 150 | |||
| 151 | if ($isHeaderMatched) { |
||
| 152 | break; |
||
| 153 | } |
||
| 154 | } |
||
| 155 | } else { |
||
| 156 | $isHeaderMatched = strpos($content, $header[$algorithm[0]]) === false |
||
| 157 | ? false |
||
| 158 | : true; |
||
| 159 | } |
||
| 160 | |||
| 161 | if ($algorithm[0] === 'R' || $algorithm[0] === 'E') { |
||
| 162 | if (false === $isHeaderMatched) { |
||
| 163 | throw new \InvalidArgumentException( |
||
| 164 | "PEM certificate must provided in RSA or ECDSA signing mode." |
||
| 165 | ); |
||
| 166 | } |
||
| 167 | } |
||
| 168 | } |
||
| 169 | } |
||
| 170 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.