Passed
Push — master ( 6714d8...c618ac )
by butschster
05:26 queued 16s
created

BootloaderRegistry::getBootloaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Boot\Bootloader;
6
7
/**
8
 * @psalm-import-type TClass from \Spiral\Boot\BootloadManagerInterface
9
 */
10
final class BootloaderRegistry implements BootloaderRegistryInterface
11
{
12
    /**
13
     * @param array<TClass>|array<TClass, array<string, mixed>> $systemBootloaders
14
     * @param array<TClass>|array<TClass, array<string, mixed>> $bootloaders
15
     */
16 423
    public function __construct(
17
        private array $systemBootloaders = [],
18
        private array $bootloaders = [],
19
    ) {
20 423
    }
21
22
    /**
23
     * @param TClass|array<TClass, array<string, mixed>> $bootloader
0 ignored issues
show
Bug introduced by
The type Spiral\Boot\Bootloader\TClass 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...
24
     */
25 2
    public function registerSystem(string|array $bootloader): void
26
    {
27 2
        if ($this->hasBootloader($bootloader)) {
28 1
            return;
29
        }
30
31 2
        \is_string($bootloader)
0 ignored issues
show
introduced by
The condition is_string($bootloader) is always false.
Loading history...
32 2
            ? $this->systemBootloaders[] = $bootloader
33 1
            : $this->systemBootloaders[\array_key_first($bootloader)] = $bootloader[\array_key_first($bootloader)]
34 2
        ;
35
    }
36
37
    /**
38
     * @param TClass|array<TClass, array<string, mixed>> $bootloader
39
     */
40 2
    public function register(string|array $bootloader): void
41
    {
42 2
        if ($this->hasBootloader($bootloader)) {
43 1
            return;
44
        }
45
46 2
        \is_string($bootloader)
0 ignored issues
show
introduced by
The condition is_string($bootloader) is always false.
Loading history...
47 2
            ? $this->bootloaders[] = $bootloader
48 1
            : $this->bootloaders[\array_key_first($bootloader)] = $bootloader[\array_key_first($bootloader)]
49 2
        ;
50
    }
51
52
    /**
53
     * @return array<TClass>|array<TClass, array<string, mixed>>
54
     */
55 422
    public function getSystemBootloaders(): array
56
    {
57 422
        return $this->systemBootloaders;
58
    }
59
60
    /**
61
     * @return array<TClass>|array<TClass, array<string, mixed>>
62
     */
63 422
    public function getBootloaders(): array
64
    {
65 422
        return $this->bootloaders;
66
    }
67
68
    /**
69
     * @param TClass|array<TClass, array<string, mixed>> $bootloader
70
     */
71 3
    private function hasBootloader(string|array $bootloader): bool
72
    {
73 3
        if (\is_array($bootloader)) {
0 ignored issues
show
introduced by
The condition is_array($bootloader) is always true.
Loading history...
74 2
            return false;
75
        }
76
77 3
        return
78 3
            \in_array($bootloader, $this->systemBootloaders, true) ||
79 3
            \in_array($bootloader, $this->bootloaders, true);
80
    }
81
}
82