Completed
Push — master ( 509b14...929e7e )
by Barney
04:52 queued 03:02
created

StartFormatter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 100 %

Importance

Changes 0
Metric Value
wmc 4
dl 45
loc 45
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A start() 5 5 1
A __construct() 4 4 1
A levelStart() 8 8 2

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
 * @codingStandardsIgnoreStart
4
 *
5
 * @author       Barney Hanlon <[email protected]>
6
 * @copyright    Barney Hanlon 2017
7
 * @license      https://opensource.org/licenses/MIT
8
 *
9
 * @codingStandardsIgnoreEnd
10
 */
11
12
namespace Shrikeh\GuzzleMiddleware\TimerLogger\Formatter;
13
14
use Psr\Http\Message\RequestInterface;
15
use Psr\Log\LogLevel;
16
use Shrikeh\GuzzleMiddleware\TimerLogger\Timer\TimerInterface;
17
18
/**
19
 * Class StartFormatter.
20
 */
21 View Code Duplication
class StartFormatter implements RequestStartInterface
0 ignored issues
show
Duplication introduced by
This class 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...
22
{
23
    /**
24
     * @var string|callable
25
     */
26
    private $msg;
27
28
    /**
29
     * @var string|callable
30
     */
31
    private $level;
32
33
    /**
34
     * StartFormatter constructor.
35
     *
36
     * @param callable        $msg   A callable used to create the message
37
     * @param callable|string $level the level this should be logged at
38
     */
39
    public function __construct(callable $msg, $level = LogLevel::DEBUG)
40
    {
41
        $this->msg = $msg;
42
        $this->level = $level;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function start(TimerInterface $timer, RequestInterface $request)
49
    {
50
        $msg = $this->msg;
51
52
        return $msg($timer, $request);
53
    }
54
55
    /**
56
     * {@inheritdoc}
57
     */
58
    public function levelStart(TimerInterface $timer, RequestInterface $request)
59
    {
60
        $level = $this->level;
61
        if (is_callable($level)) {
62
            $level = $level($timer, $request);
63
        }
64
65
        return $level;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $level also could return the type callable which is incompatible with the return type mandated by Shrikeh\GuzzleMiddleware...Interface::levelStart() of string.
Loading history...
66
    }
67
}
68