| Conditions | 10 |
| Paths | 16 |
| Total Lines | 32 |
| Code Lines | 21 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 74 | public function __construct(string $globalPrefix, ILogger $logger, |
||
| 75 | $localCacheClass = null, $distributedCacheClass = null, $lockingCacheClass = null) { |
||
| 76 | $this->logger = $logger; |
||
| 77 | $this->globalPrefix = $globalPrefix; |
||
| 78 | |||
| 79 | if (!$localCacheClass) { |
||
| 80 | $localCacheClass = self::NULL_CACHE; |
||
| 81 | } |
||
| 82 | if (!$distributedCacheClass) { |
||
| 83 | $distributedCacheClass = $localCacheClass; |
||
| 84 | } |
||
| 85 | |||
| 86 | $missingCacheMessage = 'Memcache {class} not available for {use} cache'; |
||
| 87 | $missingCacheHint = 'Is the matching PHP module installed and enabled?'; |
||
| 88 | if (!class_exists($localCacheClass) || !$localCacheClass::isAvailable()) { |
||
| 89 | throw new \OC\HintException(strtr($missingCacheMessage, [ |
||
| 90 | '{class}' => $localCacheClass, '{use}' => 'local' |
||
| 91 | ]), $missingCacheHint); |
||
| 92 | } |
||
| 93 | if (!class_exists($distributedCacheClass) || !$distributedCacheClass::isAvailable()) { |
||
| 94 | throw new \OC\HintException(strtr($missingCacheMessage, [ |
||
| 95 | '{class}' => $distributedCacheClass, '{use}' => 'distributed' |
||
| 96 | ]), $missingCacheHint); |
||
| 97 | } |
||
| 98 | if (!($lockingCacheClass && class_exists($distributedCacheClass) && $lockingCacheClass::isAvailable())) { |
||
| 99 | // don't fallback since the fallback might not be suitable for storing lock |
||
| 100 | $lockingCacheClass = self::NULL_CACHE; |
||
| 101 | } |
||
| 102 | |||
| 103 | $this->localCacheClass = $localCacheClass; |
||
| 104 | $this->distributedCacheClass = $distributedCacheClass; |
||
| 105 | $this->lockingCacheClass = $lockingCacheClass; |
||
| 106 | } |
||
| 165 |