Lines 100.00% 9 / 9
Functions and Methods 100.00% 3 / 3
Classes and Traits 100.00% 1 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ManifestDrift 100.00% 9 / 9 100.00% 3 / 3 4 100.00% 1 / 1
 __construct 100.00% 1 / 1 100.00% 1 / 1 1
 calculateBetween 100.00% 7 / 7 100.00% 1 / 1 1
 isEmpty 100.00% 1 / 1 100.00% 1 / 1 2
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\Runtime\Broker;
6
7final readonly class ManifestDrift
8{
9    /**
10     * @param list<string> $added
11     * @param list<string> $removed
12     */
13    public function __construct(
14        public array $added,
15        public array $removed,
16    ) {}
17
18    /**
19     * @param list<string> $generated
20     * @param list<string> $live
21     * @param list<string> $ignored
22     */
23    public static function calculateBetween(array $generated, array $live, array $ignored = []): self
24    {
25        $known = array_flip([...$generated, ...$ignored]);
26        $present = array_flip($live);
27
28        $added = array_values(array_filter($live, static fn(string $id): bool => !isset($known[$id])));
29        $removed = array_values(array_filter($generated, static fn(string $id): bool => !isset($present[$id])));
30
31        sort($added);
32        sort($removed);
33
34        return new self($added, $removed);
35    }
36
37    public function isEmpty(): bool
38    {
39        return $this->added === [] && $this->removed === [];
40    }
41}