Code Duplication    Length = 47-54 lines in 2 locations

src/Formatter/StartFormatter.php 1 location

@@ 21-67 (lines=47) @@
18
/**
19
 * Class StartFormatter.
20
 */
21
class StartFormatter implements RequestStartInterface
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;
66
    }
67
}
68

src/Formatter/StopFormatter.php 1 location

@@ 22-75 (lines=54) @@
19
/**
20
 * Class StopFormatter.
21
 */
22
class StopFormatter implements RequestStopInterface
23
{
24
    /**
25
     * @var callable
26
     */
27
    private $msg;
28
29
    /**
30
     * @var string|callable
31
     */
32
    private $level;
33
34
    /**
35
     * StartFormatter constructor.
36
     *
37
     * @param callable        $msg   A callable to format the messages
38
     * @param callable|string $level The log level for when the timer ends
39
     */
40
    public function __construct(callable $msg, $level = LogLevel::DEBUG)
41
    {
42
        $this->msg = $msg;
43
        $this->level = $level;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function stop(
50
        TimerInterface $timer,
51
        RequestInterface $request,
52
        ResponseInterface $response
53
    ) {
54
        $msg = $this->msg;
55
56
        return $msg($timer, $request, $response);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function levelStop(
63
        TimerInterface $timer,
64
        RequestInterface $request,
65
        ResponseInterface $response
66
    ) {
67
        $level = $this->level;
68
69
        if (is_callable($level)) {
70
            $level = $level($timer, $request, $response);
71
        }
72
73
        return $level;
74
    }
75
}
76