| Conditions | 33 |
| Paths | 60 |
| Total Lines | 123 |
| Code Lines | 60 |
| Lines | 45 |
| Ratio | 36.59 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 50 | public static function get(string $sName, string $sPortal = null, bool $bNoDoRedirect = false) |
||
| 51 | { |
||
| 52 | if ($bNoDoRedirect === true) { $sNameCache = $sName.'_true'; } else { $sNameCache = $sName; } |
||
| 53 | |||
| 54 | if ($sPortal === null || !is_string($sPortal)) { |
||
| 55 | |||
| 56 | if (defined('PORTAL')) { |
||
| 57 | |||
| 58 | $sPortal = PORTAL; |
||
| 59 | $aDirectories = array($sPortal); |
||
| 60 | } else { |
||
| 61 | |||
| 62 | $sPortal = ''; |
||
| 63 | $aDirectories = scandir(str_replace('core', 'src', __DIR__)); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | if (!isset(self::$_aConfCache[$sNameCache])) { |
||
| 68 | |||
| 69 | $base = new \StdClass; |
||
| 70 | |||
| 71 | foreach ($aDirectories as $sPortal) { |
||
|
|
|||
| 72 | |||
| 73 | if ($sPortal != '..' && $sPortal != '.') { |
||
| 74 | |||
| 75 | View Code Duplication | if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
|
| 76 | |||
| 77 | $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
||
| 78 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 79 | } |
||
| 80 | |||
| 81 | if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
||
| 82 | |||
| 83 | $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
||
| 84 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 85 | } |
||
| 86 | |||
| 87 | View Code Duplication | if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('DEV') == 1) { |
|
| 88 | |||
| 89 | $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev'; |
||
| 90 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 91 | } |
||
| 92 | |||
| 93 | View Code Duplication | if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('DEV') == 1) { |
|
| 94 | |||
| 95 | $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev'; |
||
| 96 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 97 | } |
||
| 98 | |||
| 99 | View Code Duplication | if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PROD') == 1) { |
|
| 100 | |||
| 101 | $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-prod'; |
||
| 102 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 103 | } |
||
| 104 | |||
| 105 | View Code Duplication | if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PROD') == 1) { |
|
| 106 | |||
| 107 | $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-prod'; |
||
| 108 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 109 | } |
||
| 110 | |||
| 111 | View Code Duplication | if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PREPROD') == 1) { |
|
| 112 | |||
| 113 | $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-pprod'; |
||
| 114 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 115 | } |
||
| 116 | |||
| 117 | View Code Duplication | if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('PREPROD') == 1) { |
|
| 118 | |||
| 119 | $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-pprod'; |
||
| 120 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 121 | } |
||
| 122 | |||
| 123 | View Code Duplication | if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('RECETTE') == 1) { |
|
| 124 | |||
| 125 | $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-rec'; |
||
| 126 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 127 | } |
||
| 128 | |||
| 129 | View Code Duplication | if (file_exists(str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-dev') && getenv('RECETTE') == 1) { |
|
| 130 | |||
| 131 | $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-rec'; |
||
| 132 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 133 | } |
||
| 134 | |||
| 135 | if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local')) { |
||
| 136 | |||
| 137 | $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf-local'; |
||
| 138 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 139 | } |
||
| 140 | |||
| 141 | if (file_exists(str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf')) { |
||
| 142 | |||
| 143 | $sJsonFile = str_replace('core', 'src'.DIRECTORY_SEPARATOR.$sPortal.DIRECTORY_SEPARATOR.'app'.DIRECTORY_SEPARATOR.'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf'; |
||
| 144 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 145 | } |
||
| 146 | |||
| 147 | $sJsonFile = str_replace('core', 'conf', __DIR__).DIRECTORY_SEPARATOR.$sName.'.conf'; |
||
| 148 | $base = self::_mergeAndGetConf($sJsonFile, $base); |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | if ($base === '') { |
||
| 153 | |||
| 154 | trigger_error("Error in your Json format in this file : ".$sJsonFile, E_USER_NOTICE); |
||
| 155 | } |
||
| 156 | |||
| 157 | if (isset($base->redirect) && $bNoDoRedirect === false) { |
||
| 158 | |||
| 159 | $base = self::get($sName, $base->redirect); |
||
| 160 | } |
||
| 161 | |||
| 162 | self::$_aConfCache[$sNameCache] = $base; |
||
| 163 | } |
||
| 164 | |||
| 165 | if (!self::$_aConfCache[$sNameCache]) { |
||
| 166 | |||
| 167 | $oDebug = Debug::getInstance(); |
||
| 168 | $oDebug->error('The configuration file '.$sName.' is in error!'); |
||
| 169 | } |
||
| 170 | |||
| 171 | return self::$_aConfCache[$sNameCache]; |
||
| 172 | } |
||
| 173 | |||
| 241 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: