ClassDependencies   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 17
eloc 27
dl 0
loc 97
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getImportedFqn() 0 3 1
A addInlineFqn() 0 3 1
A getImportedFqnHavingAlias() 0 9 3
A __construct() 0 3 1
A addImportedFqn() 0 3 1
A getInlineFqn() 0 3 1
A hasImportedFqn() 0 9 3
A getFqn() 0 3 1
A getDependencyList() 0 10 1
A getImportedFqnHavingLastPart() 0 9 3
A setFqn() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerowork\ClassDependenciesParser;
6
7
final class ClassDependencies
8
{
9
    private ?Fqn $fqn = null;
10
11
    /** @var array<string, ImportedFqn> */
12
    private array $importedFqn = [];
13
14
    /** @var array<string, Fqn> */
15
    private array $inlineFqn = [];
16
17 11
    public function __construct(
18
        public readonly string $filePath,
19
    ) {
20 11
    }
21
22 5
    public function setFqn(Fqn $fqn): void
23
    {
24 5
        $this->fqn = $fqn;
25
    }
26
27 9
    public function addImportedFqn(ImportedFqn $importedFqn): void
28
    {
29 9
        $this->importedFqn[(string) $importedFqn->fqn] = $importedFqn;
30
    }
31
32 6
    public function addInlineFqn(Fqn $fqn): void
33
    {
34 6
        $this->inlineFqn[(string) $fqn] = $fqn;
35
    }
36
37 3
    public function hasImportedFqn(Fqn $fqn): bool
38
    {
39 3
        foreach ($this->importedFqn as $import) {
40 3
            if ($import->fqn->equals($fqn)) {
41 1
                return true;
42
            }
43
        }
44
45 3
        return false;
46
    }
47
48 5
    public function getImportedFqnHavingLastPart(string $lastPart): ?ImportedFqn
49
    {
50 5
        foreach ($this->importedFqn as $import) {
51 5
            if ($import->fqn->getLastPart() === $lastPart) {
52 5
                return $import;
53
            }
54
        }
55
56 5
        return null;
57
    }
58
59 5
    public function getImportedFqnHavingAlias(string $alias): ?ImportedFqn
60
    {
61 5
        foreach ($this->importedFqn as $import) {
62 5
            if ($import->alias === $alias) {
63 2
                return $import;
64
            }
65
        }
66
67 5
        return null;
68
    }
69
70 5
    public function getFqn(): ?Fqn
71
    {
72 5
        return $this->fqn;
73
    }
74
75
    /**
76
     * @return array<string, ImportedFqn>
77
     */
78 1
    public function getImportedFqn(): array
79
    {
80 1
        return $this->importedFqn;
81
    }
82
83
    /**
84
     * @return array<string, Fqn>
85
     */
86 2
    public function getInlineFqn(): array
87
    {
88 2
        return $this->inlineFqn;
89
    }
90
91
    /**
92
     * @return list<string>
0 ignored issues
show
Bug introduced by
The type Jerowork\ClassDependenciesParser\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
93
     */
94 5
    public function getDependencyList(): array
95
    {
96 5
        $dependencies = [
97 5
            ...array_keys(array_filter($this->importedFqn, static fn (ImportedFqn $fqcn): bool => $fqcn->isClass)),
98 5
            ...array_keys($this->inlineFqn),
99 5
        ];
100
101 5
        sort($dependencies);
102
103 5
        return $dependencies;
104
    }
105
}
106