Conditions | 10 |
Paths | 10 |
Total Lines | 32 |
Code Lines | 22 |
Lines | 0 |
Ratio | 0 % |
Tests | 22 |
CRAP Score | 10 |
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 |
||
59 | 96 | protected function decryptionFormat(&$bytes) |
|
60 | { |
||
61 | 96 | $hexCasePattern = '/^[a-f0-9]+$/'; |
|
62 | 96 | $base64Pattern = '%^[a-zA-Z0-9/+]*={0,2}$%'; |
|
63 | 96 | $base64UrlFriendlyPattern = '/^[a-zA-Z0-9_-]+$/'; |
|
64 | |||
65 | 96 | switch ($this->cipherFormat) { |
|
66 | 96 | case self::ENCRYPTION_OUTPUT_HEX_LOWER: |
|
67 | 96 | case self::ENCRYPTION_OUTPUT_HEX_UPPER: |
|
1 ignored issue
–
show
|
|||
68 | 12 | if (preg_match($hexCasePattern, StringBuilder::stringToLower($bytes))) { |
|
69 | 12 | $bytes = hex2bin(StringBuilder::stringToLower($bytes)); |
|
70 | } |
||
71 | 12 | break; |
|
72 | 96 | case self::ENCRYPTION_OUTPUT_BASE_64: |
|
1 ignored issue
–
show
|
|||
73 | 12 | if (preg_match($base64Pattern, $bytes) && StringBuilder::stringLength($bytes) % 4 === 0) { |
|
74 | 12 | $bytes = base64_decode($bytes); |
|
75 | } |
||
76 | 12 | break; |
|
77 | 96 | case self::ENCRYPTION_OUTPUT_BASE_64_URL: |
|
78 | default: |
||
79 | 96 | if (preg_match($base64UrlFriendlyPattern, $bytes)) { |
|
80 | 84 | $bytes = StringBuilder::stringReplace(['-', '_'], ['+', '/'], $bytes); |
|
81 | 84 | $times = StringBuilder::stringLength($bytes) % 4; |
|
82 | |||
83 | // Instead of str_pad for encoding friendly appending |
||
84 | 84 | for ($i = 0; $i < $times; $i++) { |
|
85 | 72 | $bytes .= '='; |
|
86 | } |
||
87 | |||
88 | 84 | $bytes = base64_decode($bytes); |
|
89 | } |
||
90 | 96 | break; |
|
91 | } |
||
160 |