Passed
Pull Request — master (#1017)
by Maxim
12:07
created

CanBootedChecker   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 6
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A canInitialize() 0 8 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Boot\BootloadManager\Checker;
6
7
use Spiral\Boot\Attribute\BootloadConfig;
8
use Spiral\Boot\Bootloader\BootloaderInterface;
9
use Spiral\Boot\BootloadManager\ClassesRegistry;
10
11
final class CanBootedChecker implements BootloaderCheckerInterface
12
{
13 521
    public function __construct(
14
        private readonly ClassesRegistry $bootloaders,
15
    ) {
16 521
    }
17
18 500
    public function canInitialize(BootloaderInterface|string $bootloader, ?BootloadConfig $config = null): bool
19
    {
20 500
        $ref = new \ReflectionClass($bootloader);
21
22 500
        return !$this->bootloaders->isBooted($ref->getName())
23 500
            && !$ref->isAbstract()
24 500
            && !$ref->isInterface()
25 500
            && $ref->implementsInterface(BootloaderInterface::class);
26
    }
27
}
28