Completed
Pull Request — master (#4)
by Barney
01:41
created

FormatterTrait::level()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 3
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\Http\Message\ResponseInterface;
16
use Shrikeh\GuzzleMiddleware\TimerLogger\Timer\TimerInterface;
17
18
/**
19
 * Trait FormatterTrait
20
 */
21
trait FormatterTrait
22
{
23
    /**
24
     * @var string|callable
25
     */
26
    private $msg;
27
28
    /**
29
     * @var string|callable
30
     */
31
    private $level;
32
33
    /**
34
     * @param \Shrikeh\GuzzleMiddleware\TimerLogger\Timer\TimerInterface $timer    A Timer to format
35
     * @param \Psr\Http\Message\RequestInterface                         $request  A Request to format
36
     * @param \Psr\Http\Message\ResponseInterface|null                   $response The Response to format
37
     *
38
     * @return string
39
     */
40
    private function msg(
41
        TimerInterface $timer,
42
        RequestInterface $request,
43
        ResponseInterface $response = null
44
    ) {
45
        $msg = $this->msg;
46
47
        return $msg($timer, $request, $response);
48
    }
49
50
    /**
51
     * @param \Shrikeh\GuzzleMiddleware\TimerLogger\Timer\TimerInterface $timer    A Timer to format
52
     * @param \Psr\Http\Message\RequestInterface                         $request  A Request to format
53
     * @param \Psr\Http\Message\ResponseInterface|null                   $response The Response to format
54
     *
55
     * @return string
56
     */
57
    private function level(
58
        TimerInterface $timer,
59
        RequestInterface $request,
60
        ResponseInterface $response = null
61
    ) {
62
        $level = $this->level;
63
64
        if (is_callable($level)) {
65
            $level = $level($timer, $request, $response);
66
        }
67
68
        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 documented return type string.
Loading history...
69
    }
70
}
71