| Conditions | 12 |
| Paths | 55 |
| Total Lines | 78 |
| 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 |
||
| 97 | private static function _checkConsistency() |
||
| 98 | { |
||
| 99 | /** @var Config $config */ |
||
| 100 | $config = self::$serviceLocator->get(Config::class); |
||
| 101 | $appRoot = realpath($config->get('projectRoot')); |
||
| 102 | $logDirs = $config->get('log'); |
||
| 103 | |||
| 104 | if ($logDirs === null) { |
||
| 105 | return true; |
||
| 106 | } |
||
| 107 | |||
| 108 | $hasInfoTypeInConf = false; |
||
| 109 | |||
| 110 | if (in_array('info', array_keys($logDirs))) { |
||
| 111 | $hasInfoTypeInConf = true; |
||
| 112 | } |
||
| 113 | |||
| 114 | foreach ($logDirs as $level => $path) { |
||
| 115 | |||
| 116 | if (!in_array($level, self::$levels, true)) { |
||
| 117 | |||
| 118 | throw new LogTypeNotSupportedException( |
||
| 119 | 'Log type "' . $level . '" is currently not supported.' |
||
| 120 | . 'Please use one of the following log types:' . PHP_EOL |
||
| 121 | . implode(", ", self::$levels) |
||
| 122 | ); |
||
| 123 | |||
| 124 | } |
||
| 125 | |||
| 126 | $lastDirectorySeparator = strrpos($path, '/'); |
||
| 127 | |||
| 128 | if ($lastDirectorySeparator === false) { |
||
| 129 | throw new LogFileInvalidException( |
||
| 130 | 'You have to define the logfile path as an absolute path beginning from your project root' |
||
| 131 | . ' (i.e. if "/var/www/vhosts/app" is your project root set the logfile path to "/logs/{$level}.log")' |
||
| 132 | ); |
||
| 133 | } |
||
| 134 | |||
| 135 | $logDir = substr($path, 0, $lastDirectorySeparator); |
||
| 136 | |||
| 137 | if (!is_dir($appRoot . $logDir)) { |
||
| 138 | mkdir($appRoot . $logDir, 0774, true); |
||
| 139 | } |
||
| 140 | |||
| 141 | $file = substr($path, $lastDirectorySeparator, strlen($path)); |
||
| 142 | $fullPath = $appRoot . $logDir . $file; |
||
| 143 | $fileType = strrpos($fullPath, '.'); |
||
| 144 | |||
| 145 | if ($fileType !== false) { |
||
| 146 | $fileType = substr($fullPath, $fileType, strlen($fullPath)); |
||
| 147 | } |
||
| 148 | |||
| 149 | if (!file_exists($fullPath)) { |
||
| 150 | file_put_contents($fullPath, ''); |
||
| 151 | chmod($fullPath, 0744); |
||
| 152 | } |
||
| 153 | |||
| 154 | if (!$hasInfoTypeInConf && !file_exists($appRoot . $logDir . '/info' . $fileType)) { |
||
| 155 | |||
| 156 | file_put_contents($appRoot . $logDir . '/info' . $fileType, ''); |
||
| 157 | chmod($appRoot . $logDir . '/info' . $fileType, 0744); |
||
| 158 | |||
| 159 | self::$logFiles[self::LEVEL_INFO] = $appRoot . $logDir . '/info' . $fileType; |
||
| 160 | |||
| 161 | } else if (!$hasInfoTypeInConf) { |
||
| 162 | |||
| 163 | self::$logFiles[self::LEVEL_INFO] = $appRoot . $logDir . '/info' . $fileType; |
||
| 164 | |||
| 165 | } |
||
| 166 | |||
| 167 | self::$logFiles[$level] = $fullPath; |
||
| 168 | |||
| 169 | } |
||
| 170 | |||
| 171 | self::$fileSystemChecked = true; |
||
| 172 | |||
| 173 | return true; |
||
| 174 | } |
||
| 175 | |||
| 176 | } |