Conditions | 13 |
Paths | 14 |
Total Lines | 48 |
Code Lines | 24 |
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 |
||
128 | private static function _getCacheObject() |
||
129 | { |
||
130 | if (self::$_sTypeOfCache === 'file') { |
||
131 | |||
132 | if (!isset(self::$_aCache['file'])) { self::$_aCache['file'] = new CacheFile; } |
||
133 | |||
134 | return self::$_aCache['file']; |
||
135 | } |
||
136 | else if (self::$_sTypeOfCache === 'memcache') { |
||
137 | |||
138 | if (!isset(self::$_aCache['memcache'])) { |
||
139 | |||
140 | $oDbConf = Config::get('Memcache')->configuration; |
||
141 | |||
142 | if (isset($oDbConf->port)) { $sPort = $oDbConf->port; } |
||
143 | else { $sPort = null; } |
||
144 | |||
145 | if (isset($oDbConf->timeout)) { $iTimeout = $oDbConf->timeout; } |
||
146 | else { $iTimeout = null; } |
||
147 | |||
148 | self::$_aCache['memcache'] = new CacheMemcache($oDbConf->host, $sPort, $iTimeout); |
||
|
|||
149 | } |
||
150 | |||
151 | return self::$_aCache['memcache']; |
||
152 | } |
||
153 | else if (self::$_sTypeOfCache === 'apc') { |
||
154 | |||
155 | if (!isset(self::$_aCache['apc'])) { self::$_aCache['apc'] = new Apc; } |
||
156 | |||
157 | return self::$_aCache['apc']; |
||
158 | } |
||
159 | else if (self::$_sTypeOfCache === 'redis') { |
||
160 | |||
161 | if (!isset(self::$_aCache['redis'])) { |
||
162 | |||
163 | $oDbConf = Config::get('Redis')->configuration; |
||
164 | self::$_aCache['memcache'] = new Redis($oDbConf); |
||
165 | } |
||
166 | |||
167 | return self::$_aCache['redis']; |
||
168 | } |
||
169 | else if (self::$_sTypeOfCache === 'mock') { |
||
170 | |||
171 | if (!isset(self::$_aCache['mock'])) { self::$_aCache['mock'] = new Mock; } |
||
172 | |||
173 | return self::$_aCache['mock']; |
||
174 | } |
||
175 | } |
||
176 | } |
||
177 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.