Originator   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 0
cbo 3
dl 0
loc 31
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B setOrigin() 0 25 4
1
<?php
2
3
namespace DoS\ResourceBundle\Originator;
4
5
use DoS\ResourceBundle\Model\OriginContextInterface;
6
use Sylius\Component\Originator\Model\OriginAwareInterface;
7
use Sylius\Component\Originator\Originator\Originator as BaseOriginator;
8
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
9
10
class Originator extends BaseOriginator
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function setOrigin(OriginAwareInterface $originAware, $origin)
16
    {
17
        if (!is_object($origin)) {
18
            throw new UnexpectedTypeException($origin, 'object');
19
        }
20
21
        /** @var \DoS\ResourceBundle\Model\OriginAwareInterface $originAware */
22
        if ($origin instanceof OriginContextInterface) {
23
            $originAware->setOriginAlias($origin->getOriginalAlias());
24
            $originAware->setOriginType($origin->getOriginalType());
25
            $originAware->setOriginId($origin->getId());
26
27
            return;
28
        }
29
30
        if (null === $id = $this->accessor->getValue($origin, $this->identifier)) {
31
            throw new \InvalidArgumentException(sprintf(
32
                'Origin %s is not set.',
33
                $this->identifier
34
            ));
35
        }
36
37
        $originAware->setOriginId($id);
38
        $originAware->setOriginType(get_class($origin));
39
    }
40
}
41