GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

AbstractLogger::validateLogFile()   B
last analyzed

Complexity

Conditions 6
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 19
Ratio 100 %

Importance

Changes 0
Metric Value
dl 19
loc 19
rs 8.8571
c 0
b 0
f 0
cc 6
eloc 9
nc 4
nop 2
1
<?php
2
3
namespace LosMiddleware\LosLog;
4
5
use Zend\Log\Logger;
6
use Zend\Log\PsrLoggerAdapter;
7
use Zend\Log\Writer\Stream;
8
9
abstract class AbstractLogger
10
{
11
    /**
12
     * @param string $logFile
13
     * @param string $logDir
14
     * @return PsrLoggerAdapter
15
     * @throws Exception\InvalidArgumentException
16
     */
17
    public static function generateFileLogger($logFile, $logDir)
18
    {
19
        $fileName = static::validateLogFile($logFile, $logDir);
20
        $zendLogLogger = new Logger();
21
        $zendLogLogger->addWriter(new Stream($fileName));
22
23
        return new PsrLoggerAdapter($zendLogLogger);
24
    }
25
26
    /**
27
     * @param string $logFile
28
     * @param string $logDir
29
     * @return string
30
     * @throws Exception\InvalidArgumentException
31
     */
32 View Code Duplication
    public static function validateLogFile($logFile, $logDir)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        // Is logFile a stream url?
35
        if (strpos($logFile, '://') !== false) {
36
            return $logFile;
37
        }
38
39
        if (! file_exists($logDir) || ! is_writable($logDir)) {
40
            throw new Exception\InvalidArgumentException("Log dir {$logDir} must exist and be writable!");
41
        }
42
43
        $fileName = $logDir.DIRECTORY_SEPARATOR.$logFile;
44
45
        if (file_exists($fileName) && ! is_writable($fileName)) {
46
            throw new Exception\InvalidArgumentException("Log file {$fileName} must be writable!");
47
        }
48
49
        return $fileName;
50
    }
51
}
52