AbstractResourceType::setObjectManager()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace DoS\ResourceBundle\Form\Type;
4
5
use Doctrine\Common\Persistence\ObjectManager;
6
use Doctrine\Common\Persistence\ObjectRepository;
7
use Sylius\Bundle\ResourceBundle\Form\Type\AbstractResourceType as BaseAbstractResourceType;
8
9
abstract class AbstractResourceType extends BaseAbstractResourceType
10
{
11
    /**
12
     * @var string
13
     */
14
    protected $name;
15
16
    /**
17
     * @var ObjectManager
18
     */
19
    protected $manager;
20
21
    /**
22
     * @var ObjectRepository
23
     */
24
    protected $repository;
25
26
    /**
27
     * @param ObjectManager|null $manager
28
     */
29
    public function setObjectManager(ObjectManager $manager = null)
30
    {
31
        $this->manager = $manager;
32
        $this->repository = $manager->getRepository($this->dataClass);
0 ignored issues
show
Bug introduced by
It seems like $manager is not always an object, but can also be of type null. Maybe add an additional type check?

If a variable is not always an object, we recommend to add an additional type check to ensure your method call is safe:

function someFunction(A $objectMaybe = null)
{
    if ($objectMaybe instanceof A) {
        $objectMaybe->doSomething();
    }
}
Loading history...
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function __construct($dataClass, array $validationGroups = array(), $name = null)
39
    {
40
        parent::__construct($dataClass, $validationGroups);
41
42
        $this->name = $name;
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getName()
49
    {
50
        return $this->name;
51
    }
52
}
53