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.

Logger   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 34.69 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
dl 17
loc 49
ccs 18
cts 22
cp 0.8182
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 3

5 Methods

Rating   Name   Duplication   Size   Complexity  
A log() 0 4 1
A __construct() 0 4 1
A callback() 0 6 1
A printBuffer() 0 6 2
A writeln() 17 17 3

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
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Logger;
9
10
use Deployer\Component\ProcessRunner\Printer;
11
use Deployer\Host\Host;
12
use Deployer\Logger\Handler\HandlerInterface;
13
use Symfony\Component\Process\Process;
14
15
class Logger
16
{
17
    /**
18
     * @var HandlerInterface
19
     */
20
    private $handler;
21
22 9
    public function __construct(HandlerInterface $handler)
23
    {
24 9
        $this->handler = $handler;
25 9
    }
26
27 8
    public function log(string $message)
28
    {
29 8
        $this->handler->log("$message\n");
30 8
    }
31
32
    public function callback(Host $host)
33
    {
34
        return function ($type, $buffer) use ($host) {
35
            $this->printBuffer($type, $host, $buffer);
36
        };
37
    }
38
39 8
    public function printBuffer(Host $host, string $type, string $buffer)
40
    {
41 8
        foreach (explode("\n", rtrim($buffer)) as $line) {
42 8
            $this->writeln($host, $type, $line);
43
        }
44 8
    }
45
46 8 View Code Duplication
    public function writeln(Host $host, string $type, string $line)
47
    {
48 8
        $line = Printer::filterOutput($line);
49
50
        // Omit empty lines
51 8
        if (empty($line)) {
52
            return;
53
        }
54
55 8
        if ($type === Process::ERR) {
56 1
            $line = "[{$host->getAlias()}] err $line";
57
        } else {
58 8
            $line = "[{$host->getAlias()}] $line";
59
        }
60
61 8
        $this->log($line);
62 8
    }
63
}
64