| Conditions | 14 |
| Paths | 25 |
| Total Lines | 35 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 73 | final public function setStatus(int $status, ?DateTime $now, bool $setStartTime = true, bool $setEndTime = true): void |
||
| 74 | { |
||
| 75 | if ($status === $this->status) { |
||
| 76 | //nothing to do |
||
| 77 | return; |
||
| 78 | } |
||
| 79 | $this->ensureValidValue($status); |
||
| 80 | if (!$this->changeIsValid($this->status, $status)) { |
||
| 81 | Internal::error("Invalid status change!"); |
||
| 82 | } |
||
| 83 | //set reset start/end times |
||
| 84 | if ($this->statusIsFinished($status)) { |
||
| 85 | if ($setEndTime && !$this->statusIsFinished($this->status)) { |
||
| 86 | $this->setEndTime($now); |
||
| 87 | } |
||
| 88 | if ($setStartTime && !$this->statusIsStarted($this->status)) { |
||
| 89 | $this->setStartTime($now); |
||
| 90 | } |
||
| 91 | } elseif ($this->statusIsStarted($status)) { |
||
| 92 | if ($setEndTime) { |
||
| 93 | $this->setEndTime(null); |
||
| 94 | } |
||
| 95 | if ($setStartTime && !$this->statusIsStarted($this->status)) { |
||
| 96 | $this->setStartTime($now); |
||
| 97 | } |
||
| 98 | } else { |
||
| 99 | if ($setEndTime) { |
||
| 100 | $this->setEndTime(null); |
||
| 101 | } |
||
| 102 | if ($setStartTime) { |
||
| 103 | $this->setStartTime(null); |
||
| 104 | } |
||
| 105 | } |
||
| 106 | |||
| 107 | $this->status = $status; |
||
| 108 | } |
||
| 155 | } |