Completed
Push — develop ( 5e5cd6...0f5f43 )
by Barney
12s
created

HandlerStaticConstructorTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A createFrom() 0 9 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\Handler\Traits;
13
14
use Shrikeh\GuzzleMiddleware\TimerLogger\Handler\ExceptionHandler\ExceptionHandlerInterface;
15
use Shrikeh\GuzzleMiddleware\TimerLogger\Handler\ExceptionHandler\TriggerErrorHandler;
16
use Shrikeh\GuzzleMiddleware\TimerLogger\ResponseTimeLogger\ResponseTimeLoggerInterface;
17
18
/**
19
 * Trait HandlerStaticConstructorTrait.
20
 */
21
trait HandlerStaticConstructorTrait
22
{
23
    /**
24
     * @var ResponseTimeLoggerInterface
25
     */
26
    private $responseTimeLogger;
27
28
    /**
29
     * @var ExceptionHandlerInterface
30
     */
31
    private $exceptionHandler;
32
33
    /**
34
     * @param ResponseTimeLoggerInterface    $responseTimeLogger A logger for logging the response start
35
     * @param ExceptionHandlerInterface|null $exceptionHandler   An optional handler for exceptions
36
     *
37
     * @return \Shrikeh\GuzzleMiddleware\TimerLogger\Handler\StartTimer
38
     */
39
    public static function createFrom(
40
        ResponseTimeLoggerInterface $responseTimeLogger,
41
        ExceptionHandlerInterface $exceptionHandler = null
42
    ) {
43
        if (!$exceptionHandler) {
44
            $exceptionHandler = new TriggerErrorHandler();
45
        }
46
47
        return new self($responseTimeLogger, $exceptionHandler);
48
    }
49
50
    /**
51
     * StartTimer constructor.
52
     *
53
     * @param ResponseTimeLoggerInterface $responseTimeLogger A logger for logging the response start
54
     * @param ExceptionHandlerInterface   $exceptionHandler   A handler for exceptions
55
     */
56
    public function __construct(
57
        ResponseTimeLoggerInterface $responseTimeLogger,
58
        ExceptionHandlerInterface $exceptionHandler
59
    ) {
60
        $this->responseTimeLogger = $responseTimeLogger;
61
        $this->exceptionHandler = $exceptionHandler;
62
    }
63
}
64