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.
Completed
Push — master ( 4adec4...0bfd70 )
by Leandro
04:14
created

LoggerFactory::__invoke()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 8
nop 3
1
<?php
2
namespace LosMiddleware\LosLog;
3
4
use Interop\Container\ContainerInterface;
5
use Zend\Log\Logger;
6
use Zend\Log\PsrLoggerAdapter;
7
use Zend\Log\Writer\Stream;
8
use Zend\ServiceManager\Factory\FactoryInterface;
9
10
class LoggerFactory implements FactoryInterface
11
{
12
    /**
13
     * {@inheritDoc}
14
     * @see \Zend\ServiceManager\Factory\FactoryInterface::__invoke()
15
     */
16
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
17
    {
18
        $config = $container->get('config');
19
        $losConfig = array_key_exists('loslog', $config) ? $config['loslog'] : [];
20
21
        $logDir = array_key_exists('log_dir', $losConfig) ? $losConfig['log_dir'] : 'data/logs';
22
        $logFile = array_key_exists('error_logger_file', $losConfig) ? $losConfig['error_logger_file'] : 'error.log';
23
24
        $fileName = $this->validateLogFile($logFile, $logDir);
25
        $zendLogLogger = new Logger();
26
        $zendLogLogger->addWriter(new Stream($fileName));
27
28
        return new PsrLoggerAdapter($zendLogLogger);
29
    }
30
31 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...
32
    {
33
        // Is logFile a stream url?
34
        if (strpos($logFile, '://') !== false) {
35
            return $logFile;
36
        }
37
38
        if (!file_exists($logDir) || !is_writable($logDir)) {
39
            throw new Exception\InvalidArgumentException("Log dir {$logDir} must exist and be writable!");
40
        }
41
42
        $fileName = $logDir.DIRECTORY_SEPARATOR.$logFile;
43
44
        if (file_exists($fileName) && !is_writable($fileName)) {
45
            throw new Exception\InvalidArgumentException("Log file {$fileName} must be writable!");
46
        }
47
48
        return $fileName;
49
    }
50
}
51