Passed
Push — master ( be26f5...010014 )
by Mr
02:17
created

FixtureTarget::getKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the daikon-cqrs/boot project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Daikon\Boot\Fixture;
10
11
use Daikon\Interop\Assertion;
12
use Daikon\MessageBus\MessageBusInterface;
13
14
final class FixtureTarget implements FixtureTargetInterface
15
{
16
    private string $key;
17
18
    private bool $enabled;
19
20
    private FixtureLoaderInterface $fixtureLoader;
21
22
    private MessageBusInterface $messageBus;
23
24
    private ?FixtureList $fixtureList;
0 ignored issues
show
Bug introduced by
The type Daikon\Boot\Fixture\FixtureList 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...
25
26
    public function __construct(
27
        string $key,
28
        bool $enabled,
29
        FixtureLoaderInterface $fixtureLoader,
30
        MessageBusInterface $messageBus
31
    ) {
32
        $this->key = $key;
33
        $this->enabled = $enabled;
34
        $this->fixtureLoader = $fixtureLoader;
35
        $this->messageBus = $messageBus;
36
    }
37
38
    public function import(FixtureInterface $fixture): bool
39
    {
40
        Assertion::true($this->isEnabled(), sprintf("Fixture '%s' is not enabled.", $fixture->getName()));
41
42
        $index = $this->getFixtureList()->find($fixture);
43
44
        if ($index !== false) {
45
            $fixture($this->messageBus);
46
        }
47
48
        return $index !== false;
49
    }
50
51
    public function getKey(): string
52
    {
53
        return $this->key;
54
    }
55
56
    public function isEnabled(): bool
57
    {
58
        return $this->enabled === true;
59
    }
60
61
    public function getFixtureList(): FixtureList
62
    {
63
        if (!isset($this->fixtureList)) {
64
            //@todo fix fixture class loading to avoid this
65
            $this->fixtureList = $this->fixtureLoader->load();
66
        }
67
        return $this->fixtureList;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->fixtureList could return the type null which is incompatible with the type-hinted return Daikon\Boot\Fixture\FixtureList. Consider adding an additional type-check to rule them out.
Loading history...
68
    }
69
}
70