| Conditions | 5 |
| Paths | 5 |
| Total Lines | 57 |
| Code Lines | 36 |
| 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 |
||
| 36 | public function evaluate() |
||
| 37 | { |
||
| 38 | $phpMemoryLimit = $this->memoryLimit(); |
||
| 39 | if ($phpMemoryLimit) { |
||
| 40 | $ratio = $phpMemoryLimit / $this->sample->craftTotalMemory; |
||
| 41 | $displayCraftTotalMemory = (($this->sample->craftTotalMemory / 1024) / 1024) . 'M'; |
||
| 42 | $displayPhpMemoryLimit = (($phpMemoryLimit / 1024) / 1024) . 'M'; |
||
| 43 | $displayCraftMinMemory = ((self::MIN_CRAFT_MEMORY / 1024) / 1024) . 'M'; |
||
| 44 | $displayCraftMaxMemory = ((self::MAX_CRAFT_MEMORY / 1024) / 1024) . 'M'; |
||
| 45 | $this->summary = Craft::t( |
||
| 46 | 'webperf', |
||
| 47 | 'Check the `memory_limit` setting in your `php.ini` file', |
||
| 48 | [] |
||
| 49 | ); |
||
| 50 | // See if they have enough memory allocated |
||
| 51 | if ($phpMemoryLimit < self::MIN_CRAFT_MEMORY) { |
||
| 52 | $this->hasRecommendation = true; |
||
| 53 | $this->detail = Craft::t( |
||
| 54 | 'webperf', |
||
| 55 | 'Pixel & Tonic recommends at least {displayCraftMinMemory} allocated to PHP for Craft CMS 3. You have only {displayPhpMemoryLimit} allocated in your `php.ini` file.', |
||
| 56 | [ |
||
| 57 | 'displayPhpMemoryLimit' => $displayPhpMemoryLimit, |
||
| 58 | 'displayCraftMinMemory' => $displayCraftMinMemory, |
||
| 59 | ] |
||
| 60 | ); |
||
| 61 | $this->learnMoreUrl = 'https://docs.craftcms.com/v3/requirements.html'; |
||
| 62 | |||
| 63 | return; |
||
| 64 | } |
||
| 65 | // See if they have too much memory allocated |
||
| 66 | if ($phpMemoryLimit >= self::MAX_CRAFT_MEMORY) { |
||
| 67 | $this->hasRecommendation = true; |
||
| 68 | $this->detail = Craft::t( |
||
| 69 | 'webperf', |
||
| 70 | 'Your `php.ini` file has `memory_limit` set to {displayPhpMemoryLimit}. This may be set too high, since it is a per-process memory limit, and memory-intensive image transforms are done in a process separate from PHP.', |
||
| 71 | [ |
||
| 72 | 'displayPhpMemoryLimit' => $displayPhpMemoryLimit, |
||
| 73 | ] |
||
| 74 | ); |
||
| 75 | $this->learnMoreUrl = 'https://docs.craftcms.com/v3/requirements.html'; |
||
| 76 | |||
| 77 | return; |
||
| 78 | } |
||
| 79 | // See if they have too much memory allocated |
||
| 80 | if ($ratio < 1.5) { |
||
| 81 | $this->hasRecommendation = true; |
||
| 82 | $this->detail = Craft::t( |
||
| 83 | 'webperf', |
||
| 84 | 'Your `php.ini` file has `memory_limit` set to {displayPhpMemoryLimit}, but Craft is using {displayCraftTotalMemory}. Consider raising your `memory_limit` to maintain a `1.5x` buffer of available memory.', |
||
| 85 | [ |
||
| 86 | 'displayPhpMemoryLimit' => $displayPhpMemoryLimit, |
||
| 87 | 'displayCraftTotalMemory' => $displayCraftTotalMemory, |
||
| 88 | ] |
||
| 89 | ); |
||
| 90 | $this->learnMoreUrl = 'https://docs.craftcms.com/v3/requirements.html'; |
||
| 91 | |||
| 92 | return; |
||
| 93 | } |
||
| 117 |