Passed
Push — develop ( 9b8c4e...79e7ae )
by Andrea Marco
03:34 queued 14s
created

UseStatements::fromMethodAnnotations()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 6
c 1
b 0
f 0
nc 4
nop 0
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 4
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LaravelEnum\Services;
6
7
use Cerbero\Enum\Services\UseStatements as BaseUseStatements;
8
9
/**
10
 * The use statements collector.
11
 *
12
 * @property-read Inspector<\UnitEnum> $inspector
13
 */
14
final class UseStatements extends BaseUseStatements
15
{
16
    /**
17
     * Retrieve all the use statements.
18
     *
19
     * @return array<string, class-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, class-string> at position 4 could not be parsed: Unknown type name 'class-string' at position 4 in array<string, class-string>.
Loading history...
20
     */
21 1
    public function all(): array
22
    {
23 1
        return [
24 1
            ...$this->fromMethodAnnotations(),
25 1
            ...$this->existing(),
26 1
        ];
27
    }
28
29
    /**
30
     * Retrieve the use statements from the method annotations.
31
     *
32
     * @return array<string, class-string>
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<string, class-string> at position 4 could not be parsed: Unknown type name 'class-string' at position 4 in array<string, class-string>.
Loading history...
33
     */
34 1
    public function fromMethodAnnotations(): array
35
    {
36 1
        $useStatements = [];
37
38 1
        foreach ($this->inspector->methodAnnotations($this->includeExisting) as $annotation) {
39 1
            foreach ($annotation->namespaces as $namespace) {
40 1
                if (! $this->inspector->hasSameNamespace($namespace)) {
41 1
                    $useStatements[class_basename($namespace)] = $namespace;
42
                }
43
            }
44
        }
45
46 1
        return $useStatements;
47
    }
48
}
49