| Conditions | 14 |
| Paths | 44 |
| Total Lines | 52 |
| Code Lines | 35 |
| 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 |
||
| 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 | if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
||
| 90 | // CLI should not hard-fail on broken memcache |
||
| 91 | $this->logger->info($missingCacheMessage, [ |
||
| 92 | 'class' => $localCacheClass, |
||
| 93 | 'use' => 'local', |
||
| 94 | 'app' => 'cli' |
||
| 95 | ]); |
||
| 96 | $localCacheClass = self::NULL_CACHE; |
||
| 97 | } else { |
||
| 98 | throw new \OC\HintException(strtr($missingCacheMessage, [ |
||
| 99 | '{class}' => $localCacheClass, '{use}' => 'local' |
||
| 100 | ]), $missingCacheHint); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | if (!class_exists($distributedCacheClass) || !$distributedCacheClass::isAvailable()) { |
||
| 104 | if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
||
| 105 | // CLI should not hard-fail on broken memcache |
||
| 106 | $this->logger->info($missingCacheMessage, [ |
||
| 107 | 'class' => $distributedCacheClass, |
||
| 108 | 'use' => 'distributed', |
||
| 109 | 'app' => 'cli' |
||
| 110 | ]); |
||
| 111 | $distributedCacheClass = self::NULL_CACHE; |
||
| 112 | } else { |
||
| 113 | throw new \OC\HintException(strtr($missingCacheMessage, [ |
||
| 114 | '{class}' => $distributedCacheClass, '{use}' => 'distributed' |
||
| 115 | ]), $missingCacheHint); |
||
| 116 | } |
||
| 117 | } |
||
| 118 | if (!($lockingCacheClass && class_exists($distributedCacheClass) && $lockingCacheClass::isAvailable())) { |
||
| 119 | // don't fallback since the fallback might not be suitable for storing lock |
||
| 120 | $lockingCacheClass = self::NULL_CACHE; |
||
| 121 | } |
||
| 122 | |||
| 123 | $this->localCacheClass = $localCacheClass; |
||
| 124 | $this->distributedCacheClass = $distributedCacheClass; |
||
| 125 | $this->lockingCacheClass = $lockingCacheClass; |
||
| 126 | } |
||
| 185 |