| Conditions | 10 |
| Paths | 60 |
| Total Lines | 46 |
| Code Lines | 30 |
| 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 |
||
| 130 | private function bumpMemoryLimit(): void |
||
| 131 | { |
||
| 132 | $memoryLimit = trim(ini_get('memory_limit')); |
||
| 133 | $memoryLimitInBytes = '-1' === $memoryLimit ? -1 : memory_to_bytes($memoryLimit); |
||
| 134 | |||
| 135 | $bumpMemoryLimit = false === $this->boxMemoryLimitInBytes && -1 !== $memoryLimitInBytes && $memoryLimitInBytes < 1024 * 1024 * 512; |
||
| 136 | $setUserDefinedMemoryLimit = $this->boxMemoryLimitInBytes && $memoryLimitInBytes !== $this->boxMemoryLimitInBytes; |
||
| 137 | |||
| 138 | if ($bumpMemoryLimit && false === $setUserDefinedMemoryLimit) { |
||
| 139 | if ($this->tmpIni) { |
||
| 140 | // Is for the restarted process |
||
| 141 | append_to_file($this->tmpIni, 'memory_limit=512M'.PHP_EOL); |
||
| 142 | } else { |
||
| 143 | // Is for the current process |
||
| 144 | ini_set('memory_limit', '512M'); |
||
| 145 | } |
||
| 146 | |||
| 147 | $this->logger->debug( |
||
| 148 | sprintf( |
||
| 149 | 'Changed the memory limit from "%s" to "%s"', |
||
| 150 | format_size($memoryLimitInBytes, 0), |
||
| 151 | '512M' |
||
| 152 | ) |
||
| 153 | ); |
||
| 154 | } elseif ($setUserDefinedMemoryLimit) { |
||
| 155 | if ($this->tmpIni) { |
||
| 156 | // Is for the restarted process |
||
| 157 | append_to_file($this->tmpIni, 'memory_limit='.$this->boxMemoryLimitInBytes.PHP_EOL); |
||
| 158 | } else { |
||
| 159 | // Is for the current process |
||
| 160 | ini_set('memory_limit', (string) $this->boxMemoryLimitInBytes); |
||
| 161 | } |
||
| 162 | |||
| 163 | $this->logger->debug( |
||
| 164 | sprintf( |
||
| 165 | 'Changed the memory limit from "%s" to %s="%s"', |
||
| 166 | format_size($memoryLimitInBytes, 0), |
||
| 167 | BOX_MEMORY_LIMIT, |
||
| 168 | format_size($this->boxMemoryLimitInBytes, 0) |
||
| 169 | ) |
||
| 170 | ); |
||
| 171 | } else { |
||
| 172 | $this->logger->debug( |
||
| 173 | sprintf( |
||
| 174 | 'Current memory limit: "%s"', |
||
| 175 | format_size($memoryLimitInBytes, 0) |
||
| 176 | ) |
||
| 181 |