Lines 33.33% 4 / 12
Functions and Methods 50.00% 4 / 8
Classes and Traits 0.00% 0 / 1
Name Lines Functions and Methods CRAP Classes and Traits
ManifestCatalog 33.33% 4 / 12 50.00% 4 / 8 33.00 0.00% 0 / 1
 __construct 0.00% 0 / 1 0.00% 0 / 1 2
 fromLists 0.00% 0 / 5 0.00% 0 / 1 2
 knowsEntity 100.00% 1 / 1 100.00% 1 / 1 2
 isIgnoredEntity 100.00% 1 / 1 100.00% 1 / 1 1
 listKnownEntityIds 100.00% 1 / 1 100.00% 1 / 1 1
 knowsAction 0.00% 0 / 1 0.00% 0 / 1 2
 listActionNames 0.00% 0 / 1 0.00% 0 / 1 2
 computeHash 100.00% 1 / 1 100.00% 1 / 1 1
1<?php
2
3declare(strict_types=1);
4
5namespace Stewart\PHPStan\Manifest;
6
7final readonly class ManifestCatalog
8{
9    /**
10     * @param array<string, true> $entityIds
11     * @param array<string, true> $ignoredEntityIds
12     * @param array<string, true> $actionNames
13     */
14    private function __construct(
15        private array $entityIds,
16        private array $ignoredEntityIds,
17        private array $actionNames,
18    ) {}
19
20    /**
21     * @param list<string> $entityIds
22     * @param list<string> $ignoredEntityIds
23     * @param list<string> $actionNames
24     */
25    public static function fromLists(array $entityIds, array $ignoredEntityIds, array $actionNames): self
26    {
27        return new self(
28            array_fill_keys($entityIds, true),
29            array_fill_keys($ignoredEntityIds, true),
30            array_fill_keys($actionNames, true),
31        );
32    }
33
34    public function knowsEntity(string $entityId): bool
35    {
36        return isset($this->entityIds[$entityId]) || isset($this->ignoredEntityIds[$entityId]);
37    }
38
39    public function isIgnoredEntity(string $entityId): bool
40    {
41        return isset($this->ignoredEntityIds[$entityId]);
42    }
43
44    /** @return list<string> */
45    public function listKnownEntityIds(): array
46    {
47        return array_map(strval(...), [...array_keys($this->entityIds), ...array_keys($this->ignoredEntityIds)]);
48    }
49
50    public function knowsAction(string $actionName): bool
51    {
52        return isset($this->actionNames[$actionName]);
53    }
54
55    /** @return list<string> */
56    public function listActionNames(): array
57    {
58        return array_map(strval(...), array_keys($this->actionNames));
59    }
60
61    public function computeHash(): string
62    {
63        return hash('xxh128', serialize([$this->entityIds, $this->ignoredEntityIds, $this->actionNames]));
64    }
65}