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   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 43
Duplicated Lines 44.19 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 4
dl 19
loc 43
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A generateFileLogger() 0 8 1
B validateLogFile() 19 19 6

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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