Conditions | 14 |
Paths | 44 |
Total Lines | 54 |
Code Lines | 37 |
Lines | 30 |
Ratio | 55.56 % |
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 | { |
||
77 | $this->logger = $logger; |
||
78 | $this->globalPrefix = $globalPrefix; |
||
79 | |||
80 | if (!$localCacheClass) { |
||
|
|||
81 | $localCacheClass = self::NULL_CACHE; |
||
82 | } |
||
83 | if (!$distributedCacheClass) { |
||
84 | $distributedCacheClass = $localCacheClass; |
||
85 | } |
||
86 | |||
87 | $missingCacheMessage = 'Memcache {class} not available for {use} cache'; |
||
88 | $missingCacheHint = 'Is the matching PHP module installed and enabled?'; |
||
89 | View Code Duplication | if (!class_exists($localCacheClass) || !$localCacheClass::isAvailable()) { |
|
90 | if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
||
91 | // CLI should not hard-fail on broken memcache |
||
92 | $this->logger->info($missingCacheMessage, [ |
||
93 | 'class' => $localCacheClass, |
||
94 | 'use' => 'local', |
||
95 | 'app' => 'cli' |
||
96 | ]); |
||
97 | $localCacheClass = self::NULL_CACHE; |
||
98 | } else { |
||
99 | throw new \OC\HintException(strtr($missingCacheMessage, [ |
||
100 | '{class}' => $localCacheClass, '{use}' => 'local' |
||
101 | ]), $missingCacheHint); |
||
102 | } |
||
103 | } |
||
104 | View Code Duplication | if (!class_exists($distributedCacheClass) || !$distributedCacheClass::isAvailable()) { |
|
105 | if (\OC::$CLI && !defined('PHPUNIT_RUN')) { |
||
106 | // CLI should not hard-fail on broken memcache |
||
107 | $this->logger->info($missingCacheMessage, [ |
||
108 | 'class' => $distributedCacheClass, |
||
109 | 'use' => 'distributed', |
||
110 | 'app' => 'cli' |
||
111 | ]); |
||
112 | $distributedCacheClass = self::NULL_CACHE; |
||
113 | } else { |
||
114 | throw new \OC\HintException(strtr($missingCacheMessage, [ |
||
115 | '{class}' => $distributedCacheClass, '{use}' => 'distributed' |
||
116 | ]), $missingCacheHint); |
||
117 | } |
||
118 | } |
||
119 | if (!($lockingCacheClass && class_exists($distributedCacheClass) && $lockingCacheClass::isAvailable())) { |
||
120 | // don't fallback since the fallback might not be suitable for storing lock |
||
121 | $lockingCacheClass = self::NULL_CACHE; |
||
122 | } |
||
123 | |||
124 | $this->localCacheClass = $localCacheClass; |
||
125 | $this->distributedCacheClass = $distributedCacheClass; |
||
126 | $this->lockingCacheClass = $lockingCacheClass; |
||
127 | } |
||
128 | |||
196 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: