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