Lines 80.00% 4 / 5
Methods 75.00% 3 / 4
Classes 0.00% 0 / 1
Name Lines Methods CRAP
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 recordState 100.00% 2 / 2 100.00% 1 / 1 2
 recordStateKeepingVersion 100.00% 1 / 1 100.00% 1 / 1 1
 isActive 0.00% 0 / 1 0.00% 0 / 1 2
11final class ComponentTracker
12{
13    public private(set) ComponentDetection $detection;
14
15    public function __construct(private readonly Clock $clock)
16    {
17        $this->detection = new ComponentDetection(ComponentState::Unchecked, null, $clock->getNow());
18    }
19
20    public function recordState(ComponentState $state, ?ComponentVersion $version): void
21    {
22        $since = $state === $this->detection->state ? $this->detection->since : $this->clock->getNow();
23        $this->detection = new ComponentDetection($state, $version, $since);
24    }
25
26    public function recordStateKeepingVersion(ComponentState $state): void
27    {
28        $this->recordState($state, $this->detection->version);
29    }
30
31    public function isActive(): bool
32    {
33        return $this->detection->state === ComponentState::Active;
34    }
35}