Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

Kunstmaan/FixturesBundle/Populator/Populator.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\FixturesBundle\Populator;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Kunstmaan\FixturesBundle\Populator\Methods\MethodInterface;
7
8
class Populator
9
{
10
    /**
11
     * @var MethodInterface[]
12
     */
13
    private $populators;
14
15
    public function __construct()
16
    {
17
        $this->populators = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type array<integer,object<Kun...thods\MethodInterface>> of property $populators.

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...
18
    }
19
20
    public function populate($entity, $data)
21
    {
22
        foreach ($data as $property => $value) {
23
            foreach ($this->populators as $populator) {
24
                if ($populator->canSet($entity, $property, $value)) {
25
                    if ($value instanceof \Kunstmaan\FixturesBundle\Loader\Fixture) {
26
                        $populator->set($entity, $property, $value->getEntity());
27
                    } elseif (is_array($value)) {
28
                        foreach ($value as &$item) {
29
                            if ($item instanceof \Kunstmaan\FixturesBundle\Loader\Fixture) {
30
                                $item = $item->getEntity();
31
                            }
32
                        }
33
                        $populator->set($entity, $property, $value);
34
                    } else {
35
                        $populator->set($entity, $property, $value);
36
                    }
37
38
                    break;
39
                }
40
            }
41
        }
42
    }
43
44
    public function addPopulator(MethodInterface $populator, $alias)
45
    {
46
        $this->populators->set($alias, $populator);
0 ignored issues
show
The method set cannot be called on $this->populators (of type array<integer,object<Kun...thods\MethodInterface>>).

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...
47
48
        return $this;
49
    }
50
}
51