| Conditions | 1 |
| Paths | 1 |
| Total Lines | 54 |
| 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 |
||
| 85 | public function rulesLimitProcessorAndMemoryUsage() |
||
| 86 | { |
||
| 87 | $task1 = new ProcessCallbackTask(function () { |
||
| 88 | return; |
||
| 89 | }); |
||
| 90 | |||
| 91 | $task2 = new ProcessCallbackTask(function () { |
||
| 92 | return; |
||
| 93 | }); |
||
| 94 | |||
| 95 | $rule1 = new InMemoryRule(); |
||
| 96 | $rule1->setProcesses(1); |
||
| 97 | $rule1->setMinimumProcessorUsage(50); |
||
| 98 | $rule1->setMaximumProcessorUsage(100); |
||
| 99 | |||
| 100 | $profile1 = new InMemoryProfile(); |
||
| 101 | $profile1->setProcesses(array($task1)); |
||
| 102 | $profile1->setProcessorLoad(75); |
||
| 103 | |||
| 104 | $this->assertFalse($this->rules->addRule($rule1)->canRunTask($task2, $profile1)); |
||
| 105 | |||
| 106 | $rule2 = new InMemoryRule(); |
||
| 107 | $rule2->setProcesses(1); |
||
| 108 | $rule2->setMinimumMemoryUsage(50); |
||
| 109 | $rule2->setMaximumMemoryUsage(100); |
||
| 110 | |||
| 111 | $profile2 = new InMemoryProfile(); |
||
| 112 | $profile2->setProcesses(array($task1)); |
||
| 113 | $profile2->setMemoryLoad(75); |
||
| 114 | |||
| 115 | $this->assertFalse($this->rules->removeRule($rule1)->addRule($rule2)->canRunTask($task2, $profile2)); |
||
| 116 | |||
| 117 | $rule3 = new InMemoryRule(); |
||
| 118 | $rule3->setProcesses(1); |
||
| 119 | $rule3->setMinimumSiblingProcessorUsage(50); |
||
| 120 | $rule3->setMaximumSiblingProcessorUsage(100); |
||
| 121 | |||
| 122 | $profile3 = new InMemoryProfile(); |
||
| 123 | $profile3->setSiblingProcesses(array($task1)); |
||
| 124 | $profile3->setSiblingProcessorLoad(75); |
||
| 125 | |||
| 126 | $this->assertFalse($this->rules->removeRule($rule2)->addRule($rule3)->canRunTask($task2, $profile3)); |
||
| 127 | |||
| 128 | $rule4 = new InMemoryRule(); |
||
| 129 | $rule4->setProcesses(1); |
||
| 130 | $rule4->setMinimumSiblingMemoryUsage(50); |
||
| 131 | $rule4->setMaximumSiblingMemoryUsage(100); |
||
| 132 | |||
| 133 | $profile4 = new InMemoryProfile(); |
||
| 134 | $profile4->setSiblingProcesses(array($task1)); |
||
| 135 | $profile4->setSiblingMemoryLoad(75); |
||
| 136 | |||
| 137 | $this->assertFalse($this->rules->removeRule($rule3)->addRule($rule4)->canRunTask($task2, $profile4)); |
||
| 138 | } |
||
| 139 | } |
||
| 140 |