| Conditions | 6 |
| Paths | 8 |
| Total Lines | 52 |
| Code Lines | 17 |
| 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 |
||
| 22 | return $className; |
||
| 23 | break; |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Returns the path the framework project is located in. |
||
| 29 | * |
||
| 30 | * @return string |
||
| 31 | */ |
||
| 32 | public static function getPath() |
||
| 33 | { |
||
| 34 | return str_replace('src/WebServCo/Framework', '', __DIR__); |
||
| 35 | } |
||
| 36 | |||
| 37 | private static function loadLibraryConfiguration($configName) |
||
| 38 | { |
||
| 39 | if ('Config' == $configName) { |
||
| 40 | return false; |
||
| 41 | } |
||
| 42 | $projectPath = self::getLibrary('Config')->get( |
||
| 43 | sprintf( |
||
| 44 | 'app%1$spath%1$sproject', |
||
| 45 | \WebServCo\Framework\Settings::DIVIDER |
||
| 46 | ) |
||
| 47 | ); |
||
| 48 | if (empty($projectPath)) { |
||
| 49 | return false; |
||
| 50 | } |
||
| 51 | return self::getLibrary('Config')->load($configName, $projectPath); |
||
| 52 | } |
||
| 53 | |||
| 54 | private static function loadLibrary($className, $fullClassName, $configName = null) |
||
| 55 | { |
||
| 56 | if (!class_exists($fullClassName)) { |
||
| 57 | throw new \ErrorException( |
||
| 58 | sprintf('Library %s not found', $fullClassName) |
||
| 59 | ); |
||
| 60 | } |
||
| 61 | $configName = $configName ?: $className; |
||
| 62 | $config = self::loadLibraryConfiguration($configName); |
||
| 63 | /** |
||
| 64 | * Libraries can have custom parameters to constructor, |
||
| 65 | * however the configuration array is always the first. |
||
| 66 | * $args = is_array($args) ? array_merge([$config], $args) : [$config]; |
||
| 67 | */ |
||
| 68 | switch ($className) { |
||
| 69 | case 'Request': |
||
| 70 | $args = [$config, $_SERVER, $_POST]; |
||
| 71 | break; |
||
| 72 | default: |
||
| 73 | $args = [$config]; |
||
| 74 | break; |
||
| 117 |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.