Completed
Push — master ( d118af...3d5195 )
by Tomas
07:29 queued 04:09
created

RestartTrait   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 28
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setRestart() 0 5 1
A shouldRestart() 0 4 2
A checkRestart() 0 6 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Tomaj\Hermes\Driver;
5
6
use Tomaj\Hermes\Restart\RestartException;
7
use Tomaj\Hermes\Restart\RestartInterface;
8
9
trait RestartTrait
10
{
11
    /** @var RestartInterface */
12
    private $restart;
13
14
    private $startTime;
15
16
    public function setRestart(RestartInterface $restart)
17
    {
18
        $this->restart = $restart;
19
        $this->startTime = new \DateTime();
20
    }
21
22
    private function shouldRestart(): bool
23
    {
24
        return $this->restart && $this->restart->shouldRestart($this->startTime);
25
    }
26
27
    /**
28
     * @throws RestartException
29
     */
30
    private function checkRestart(): void
31
    {
32
        if ($this->shouldRestart()) {
33
            throw new RestartException();
34
        }
35
    }
36
}
37