| Conditions | 12 |
| Paths | 10 |
| Total Lines | 39 |
| Code Lines | 26 |
| 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 |
||
| 91 | public function findClass($class) { |
||
| 92 | $class = trim($class, '\\'); |
||
| 93 | |||
| 94 | $paths = array(); |
||
| 95 | if ($this->useGlobalClassPath && array_key_exists($class, \OC::$CLASSPATH)) { |
||
| 96 | $paths[] = \OC::$CLASSPATH[$class]; |
||
| 97 | /** |
||
| 98 | * @TODO: Remove this when necessary |
||
| 99 | * Remove "apps/" from inclusion path for smooth migration to multi app dir |
||
| 100 | */ |
||
| 101 | if (strpos(\OC::$CLASSPATH[$class], 'apps/') === 0) { |
||
| 102 | \OCP\Util::writeLog('core', 'include path for class "' . $class . '" starts with "apps/"', \OCP\Util::DEBUG); |
||
| 103 | $paths[] = str_replace('apps/', '', \OC::$CLASSPATH[$class]); |
||
| 104 | } |
||
| 105 | } elseif (strpos($class, 'OC_') === 0) { |
||
| 106 | $paths[] = \OC::$SERVERROOT . '/lib/private/legacy/' . strtolower(str_replace('_', '/', substr($class, 3)) . '.php'); |
||
| 107 | } elseif (strpos($class, 'OCA\\') === 0) { |
||
| 108 | list(, $app, $rest) = explode('\\', $class, 3); |
||
| 109 | $app = strtolower($app); |
||
| 110 | $appPath = \OC_App::getAppPath($app); |
||
| 111 | if ($appPath && stream_resolve_include_path($appPath)) { |
||
|
|
|||
| 112 | $paths[] = $appPath . '/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
||
| 113 | // If not found in the root of the app directory, insert '/lib' after app id and try again. |
||
| 114 | $paths[] = $appPath . '/lib/' . strtolower(str_replace('\\', '/', $rest) . '.php'); |
||
| 115 | } |
||
| 116 | } elseif ($class === 'Test\\TestCase') { |
||
| 117 | // This File is considered public API, so we make sure that the class |
||
| 118 | // can still be loaded, although the PSR-4 paths have not been loaded. |
||
| 119 | $paths[] = \OC::$SERVERROOT . '/tests/lib/TestCase.php'; |
||
| 120 | |||
| 121 | } elseif ($class === 'Test\\TestCasePhpUnitCompatibility') { |
||
| 122 | $paths[] = \OC::$SERVERROOT . '/tests/lib/TestCasePhpUnitCompatibility.php'; |
||
| 123 | } elseif ($class === 'Test\\TestCasePhpUnit5') { |
||
| 124 | $paths[] = \OC::$SERVERROOT . '/tests/lib/TestCasePhpUnit5.php'; |
||
| 125 | } elseif ($class === 'Test\\TestCasePhpUnit4') { |
||
| 126 | $paths[] = \OC::$SERVERROOT . '/tests/lib/TestCasePhpUnit4.php'; |
||
| 127 | } |
||
| 128 | return $paths; |
||
| 129 | } |
||
| 130 | |||
| 191 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
stringvalues, the empty string''is a special case, in particular the following results might be unexpected: