GridFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 58
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A createGrid() 0 6 1
A doLoadGrid() 0 16 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Psi\Component\Grid;
6
7
use Metadata\MetadataFactory;
8
use Psi\Component\ObjectAgent\AgentFinder;
9
10
class GridFactory
11
{
12
    /**
13
     * @var AgentFinder
14
     */
15
    private $agentFinder;
16
17
    /**
18
     * @var GridMetadataFactory
19
     */
20
    private $metadataFactory;
21
22
    /**
23
     * @var ActionPerformer
24
     */
25
    private $actionPerformer;
26
27
    /**
28
     * @var GridViewFactory
29
     */
30
    private $gridViewFactory;
31
32
    public function __construct(
33
        AgentFinder $agentFinder,
34
        GridMetadataFactoryInterface $metadataFactory,
35
        GridViewFactory $gridViewFactory,
36
        ActionPerformer $actionPerformer
37
    ) {
38
        $this->agentFinder = $agentFinder;
39
        $this->metadataFactory = $metadataFactory;
0 ignored issues
show
Documentation Bug introduced by
$metadataFactory is of type object<Psi\Component\Gri...tadataFactoryInterface>, but the property $metadataFactory was declared to be of type object<Psi\Component\Grid\GridMetadataFactory>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
40
        $this->gridViewFactory = $gridViewFactory;
41
        $this->actionPerformer = $actionPerformer;
42
    }
43
44
    public function createGrid(string $classFqn, array $context = []): Grid
45
    {
46
        $context = new GridContext($classFqn, $context);
47
48
        return $this->doLoadGrid($context);
49
    }
50
51
    private function doLoadGrid(GridContext $context): Grid
52
    {
53
        // find the agent and get the grid metadata.
54
        $agent = $this->agentFinder->findFor($context->getClassFqn());
55
56
        $real = $agent->getCanonicalClassFqn($context->getClassFqn());
57
        $gridMetadata = $this->metadataFactory->getGridMetadata($real, $context->getVariant());
58
59
        return new Grid(
60
            $this->gridViewFactory,
61
            $this->actionPerformer,
62
            $agent,
63
            $context,
64
            $gridMetadata
65
        );
66
    }
67
}
68