CommandsFactory::hydrateModelRegistry()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Nip\Records\Locator\Resolver\Commands;
5
6
use Nip\Records\Locator\Configuration\Configuration;
7
use Nip\Records\Locator\ModelLocator;
8
use Nip\Records\Registry\ModelRegistry;
9
10
/**
11
 * Class CommandsFactory
12
 * @package Nip\Records\Locator\Resolver\Commands
13
 */
14
class CommandsFactory
15
{
16
17
    /**
18
     * @param string $alias
19
     * @param ModelLocator $modelLocator
20
     * @return Command
21
     */
22 3
    public static function create($alias, $modelLocator = null)
23
    {
24 3
        $command = new Command();
25 3
        $command->setAlias($alias);
26 3
        $command->setInstantiator($modelLocator->getInstantiator());
0 ignored issues
show
Bug introduced by
The method getInstantiator() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        $command->setInstantiator($modelLocator->/** @scrutinizer ignore-call */ getInstantiator());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27 3
        $command = self::hydrateConfiguration($command, $modelLocator->getConfiguration());
28 3
        $command = self::hydrateModelRegistry($command, $modelLocator->getModelRegistry());
29 3
        return $command;
30
    }
31
32
    /**
33
     * @param string $alias
34
     * @param Configuration|null $configuration
35
     * @return Command
36
     */
37
    public static function createFromAlias($alias, $configuration = null)
38
    {
39
        $command = new Command();
40
        $command->setAlias($alias);
41
        return self::hydrateConfiguration($command, $configuration);
42
    }
43
44
    /**
45
     * @param Command $command
46
     * @param Configuration|null $configuration
47
     * @return Command
48
     */
49 3
    protected static function hydrateConfiguration(Command $command, $configuration)
50
    {
51 3
        if ($configuration instanceof Configuration) {
52 3
            $command->setConfiguration($configuration);
53
        }
54 3
        return $command;
55
    }
56
57
    /**
58
     * @param Command $command
59
     * @param ModelRegistry|null $registry
60
     * @return Command
61
     */
62 3
    protected static function hydrateModelRegistry(Command $command, $registry)
63
    {
64 3
        if ($registry instanceof ModelRegistry) {
65 3
            $command->setModelRegistry($registry);
66
        }
67 3
        return $command;
68
    }
69
}
70