BusinessEntityResolver::addResolver()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Victoire\Bundle\BusinessEntityBundle\Resolver;
4
5
use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessEntity;
6
use Victoire\Bundle\BusinessEntityBundle\Entity\BusinessProperty;
7
use Victoire\Bundle\CoreBundle\Entity\EntityProxy;
8
9
/*
10
 * Class BusinessEntityResolver.
11
 */
12
class BusinessEntityResolver implements BusinessEntityResolverInterface
0 ignored issues
show
introduced by
You must use "/**" style comments for a class comment
Loading history...
13
{
14
    private $resolvers;
15
16
    public function __construct()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
17
    {
18
        $this->resolvers = [];
19
    }
20
21
    public function addResolver($resolver, $type)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
22
    {
23
        $this->resolvers[$type] = $resolver;
24
    }
25
26
    public function getBusinessEntity(EntityProxy $entityProxy)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
27
    {
28
        return $this->findResolver($entityProxy->getBusinessEntity())->getBusinessEntity($entityProxy);
29
    }
30
31
    public function getBusinessEntities(BusinessEntity $businessEntity)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
32
    {
33
        return $this->findResolver($businessEntity)->getBusinessEntities($businessEntity);
34
    }
35
36
    public function searchBusinessEntities(BusinessEntity $businessEntity, BusinessProperty $businessProperty, $filter)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
37
    {
38
        return $this->findResolver($businessEntity)->searchBusinessEntities($businessEntity, $businessProperty, $filter);
39
    }
40
41
    protected function findResolver(BusinessEntity $businessEntity)
42
    {
43
        if (array_key_exists($businessEntity->getType(), $this->resolvers)) {
44
            return $this->resolvers[$businessEntity->getType()];
45
        } else {
46
            throw new \Exception(sprintf('there is no resolver for %s type', $businessEntity->getType()));
47
        }
48
    }
49
}
50