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

StartFormatter::start()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 5
Ratio 100 %

Importance

Changes 0
Metric Value
dl 5
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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