| Conditions | 14 |
| Paths | 36 |
| Total Lines | 42 |
| Code Lines | 29 |
| 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 |
||
| 126 | private function parseRetentionObligation(){ |
||
| 127 | $splitValues = explode(',', $this->retentionObligation); |
||
| 128 | if (!isset($splitValues[0])) { |
||
| 129 | $minValue = self::DEFAULT_RETENTION_OBLIGATION; |
||
| 130 | } else { |
||
| 131 | $minValue = trim($splitValues[0]); |
||
| 132 | } |
||
| 133 | |||
| 134 | if (!isset($splitValues[1]) && $minValue === 'auto') { |
||
| 135 | $maxValue = 'auto'; |
||
| 136 | } elseif (!isset($splitValues[1])) { |
||
| 137 | $maxValue = self::DEFAULT_RETENTION_OBLIGATION; |
||
| 138 | } else { |
||
| 139 | $maxValue = trim($splitValues[1]); |
||
| 140 | } |
||
| 141 | |||
| 142 | if ($minValue === 'auto' && $maxValue === 'auto') { |
||
| 143 | // Default: Keep for 30 days but delete anytime if space needed |
||
| 144 | $this->minAge = self::DEFAULT_RETENTION_OBLIGATION; |
||
| 145 | $this->maxAge = self::NO_OBLIGATION; |
||
| 146 | $this->canPurgeToSaveSpace = true; |
||
| 147 | } elseif ($minValue !== 'auto' && $maxValue === 'auto') { |
||
| 148 | // Keep for X days but delete anytime if space needed |
||
| 149 | $this->minAge = (int)$minValue; |
||
| 150 | $this->maxAge = self::NO_OBLIGATION; |
||
| 151 | $this->canPurgeToSaveSpace = true; |
||
| 152 | } elseif ($minValue === 'auto' && $maxValue !== 'auto') { |
||
| 153 | // Delete anytime if space needed, Delete all older than max automatically |
||
| 154 | $this->minAge = self::NO_OBLIGATION; |
||
| 155 | $this->maxAge = (int)$maxValue; |
||
| 156 | $this->canPurgeToSaveSpace = true; |
||
| 157 | } elseif ($minValue !== 'auto' && $maxValue !== 'auto') { |
||
| 158 | // Delete all older than max OR older than min if space needed |
||
| 159 | |||
| 160 | // Max < Min as per https://github.com/owncloud/core/issues/16300 |
||
| 161 | if ($maxValue < $minValue) { |
||
| 162 | $maxValue = $minValue; |
||
| 163 | } |
||
| 164 | |||
| 165 | $this->minAge = (int)$minValue; |
||
| 166 | $this->maxAge = (int)$maxValue; |
||
| 167 | $this->canPurgeToSaveSpace = false; |
||
| 168 | } |
||
| 171 |