| Conditions | 8 |
| Paths | 22 |
| Total Lines | 63 |
| Code Lines | 35 |
| 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 |
||
| 110 | public function get(bool $required = null): ?array |
||
| 111 | { |
||
| 112 | if (null === $required) { |
||
| 113 | $required = (bool) ini_get('phar.require_hash'); |
||
| 114 | } |
||
| 115 | |||
| 116 | $this->seek(-4, SEEK_END); |
||
| 117 | |||
| 118 | if ('GBMB' !== $this->read(4)) { |
||
| 119 | if ($required) { |
||
| 120 | throw new PharException( |
||
| 121 | sprintf( |
||
| 122 | 'The phar "%s" is not signed.', |
||
| 123 | $this->file |
||
| 124 | ) |
||
| 125 | ); |
||
| 126 | } |
||
| 127 | |||
| 128 | return null; |
||
| 129 | } |
||
| 130 | |||
| 131 | $this->seek(-8, SEEK_END); |
||
| 132 | |||
| 133 | $flag = unpack('V', $this->read(4)); |
||
| 134 | $flag = $flag[1]; |
||
| 135 | |||
| 136 | foreach (self::TYPES as $type) { |
||
| 137 | if ($flag === $type['flag']) { |
||
| 138 | break; |
||
| 139 | } |
||
| 140 | |||
| 141 | unset($type); |
||
| 142 | } |
||
| 143 | |||
| 144 | if (!isset($type)) { |
||
| 145 | throw new PharException( |
||
| 146 | sprintf( |
||
| 147 | 'The signature type (%x) is not recognized for the phar "%s".', |
||
| 148 | $flag, |
||
| 149 | $this->file |
||
| 150 | ) |
||
| 151 | ); |
||
| 152 | } |
||
| 153 | |||
| 154 | $offset = -8; |
||
| 155 | |||
| 156 | if (0x10 === $type['flag']) { |
||
|
|
|||
| 157 | $offset = -12; |
||
| 158 | |||
| 159 | $this->seek(-12, SEEK_END); |
||
| 160 | |||
| 161 | $type['size'] = unpack('V', $this->read(4)); |
||
| 162 | $type['size'] = $type['size'][1]; |
||
| 163 | } |
||
| 164 | |||
| 165 | $this->seek($offset - $type['size'], SEEK_END); |
||
| 166 | |||
| 167 | $hash = $this->read($type['size']); |
||
| 168 | $hash = unpack('H*', $hash); |
||
| 169 | |||
| 170 | return [ |
||
| 171 | 'hash_type' => $type['name'], |
||
| 172 | 'hash' => strtoupper($hash[1]), |
||
| 173 | ]; |
||
| 275 |