Lines 100.00% 8 / 8
Functions and Methods 100.00% 7 / 7
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
DeployState 100.00% 8 / 8 100.00% 7 / 7 7 100.00% 1 / 1
 recordRunningCommit 100.00% 1 / 1 100.00% 1 / 1 1
 recordPoll 100.00% 1 / 1 100.00% 1 / 1 1
 recordFailure 100.00% 2 / 2 100.00% 1 / 1 1
 findRunningCommit 100.00% 1 / 1 100.00% 1 / 1 1
 findLastPolledAt 100.00% 1 / 1 100.00% 1 / 1 1
 findLastFailure 100.00% 1 / 1 100.00% 1 / 1 1
 countFailures 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Broker\Deploy;
6
7use Stewart\Contracts\Time\Instant;
8
9final class DeployState
10{
11    private ?CommitId $runningCommit = null;
12
13    private ?Instant $lastPolledAt = null;
14
15    private ?ReleaseFailure $lastFailure = null;
16
17    private int $failures = 0;
18
19    public function recordRunningCommit(CommitId $commit): void
20    {
21        $this->runningCommit = $commit;
22    }
23
24    public function recordPoll(Instant $polledAt): void
25    {
26        $this->lastPolledAt = $polledAt;
27    }
28
29    public function recordFailure(ReleaseFailure $failure): void
30    {
31        $this->lastFailure = $failure;
32        ++$this->failures;
33    }
34
35    public function findRunningCommit(): ?CommitId
36    {
37        return $this->runningCommit;
38    }
39
40    public function findLastPolledAt(): ?Instant
41    {
42        return $this->lastPolledAt;
43    }
44
45    public function findLastFailure(): ?ReleaseFailure
46    {
47        return $this->lastFailure;
48    }
49
50    public function countFailures(): int
51    {
52        return $this->failures;
53    }
54}