MergeableDriver::loadMetadataForClass()   B
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 8.6737
c 0
b 0
f 0
cc 5
eloc 12
nc 5
nop 1
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cubiche\Core\Metadata\Driver;
12
13
use Cubiche\Core\Collections\ArrayCollection\ArrayList;
14
use Cubiche\Core\Metadata\ClassMetadata;
15
use Cubiche\Core\Metadata\Exception\MappingException;
16
17
/**
18
 * MergeableDriver class.
19
 *
20
 * @author Ivannis Suárez Jerez <[email protected]>
21
 */
22
class MergeableDriver implements DriverInterface
23
{
24
    /**
25
     * @var DriverInterface[]
26
     */
27
    protected $drivers;
28
29
    /**
30
     * MergeableDriver constructor.
31
     *
32
     * @param array $drivers
33
     */
34
    public function __construct(array $drivers = array())
35
    {
36
        $this->drivers = new ArrayList();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Cubiche\Core\Collec...yCollection\ArrayList() of type object<Cubiche\Core\Coll...ayCollection\ArrayList> is incompatible with the declared type array<integer,object<Cub...river\DriverInterface>> of property $drivers.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
        foreach ($drivers as $driver) {
38
            $this->addDriver($driver);
39
        }
40
    }
41
42
    /**
43
     * @param DriverInterface $driver
44
     */
45
    public function addDriver(DriverInterface $driver)
46
    {
47
        $this->drivers->add($driver);
0 ignored issues
show
Bug introduced by
The method add cannot be called on $this->drivers (of type array<integer,object<Cub...river\DriverInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function loadMetadataForClass($className)
54
    {
55
        $classMetadata = null;
56
        /** @var $driver DriverInterface */
57
        foreach ($this->drivers->toArray() as $driver) {
0 ignored issues
show
Bug introduced by
The method toArray cannot be called on $this->drivers (of type array<integer,object<Cub...river\DriverInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
58
            try {
59
                $metadata = $driver->loadMetadataForClass($className);
60
            } catch (MappingException $e) {
61
                continue;
62
            }
63
64
            if ($metadata !== null) {
65
                if ($classMetadata === null) {
66
                    $classMetadata = new ClassMetadata($className);
67
                }
68
69
                $classMetadata->merge($metadata);
70
            }
71
        }
72
73
        return $classMetadata;
74
    }
75
76
    /**
77
     * {@inheritdoc}
78
     */
79
    public function getAllClassNames()
80
    {
81
        $classNames = [];
82
        /** @var $driver DriverInterface */
83
        foreach ($this->drivers->toArray() as $driver) {
0 ignored issues
show
Bug introduced by
The method toArray cannot be called on $this->drivers (of type array<integer,object<Cub...river\DriverInterface>>).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
84
            $classNames = array_merge($classNames, $driver->getAllClassNames());
85
        }
86
87
        return $classNames;
88
    }
89
}
90