AssignSubscriptionTokenListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 3
dl 0
loc 26
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A assignToken() 0 8 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PH\Bundle\CoreBundle\EventListener;
6
7
use PH\Component\Core\Assigner\SubscriptionTokenAssignerInterface;
8
use PH\Component\Core\Model\SubscriptionInterface;
9
use Sylius\Component\Resource\Exception\UnexpectedTypeException;
10
use Symfony\Component\EventDispatcher\GenericEvent;
11
12
final class AssignSubscriptionTokenListener
13
{
14
    /**
15
     * @var SubscriptionTokenAssignerInterface
16
     */
17
    private $subscriptionTokenAssigner;
18
19
    public function __construct(SubscriptionTokenAssignerInterface $subscriptionTokenAssigner)
20
    {
21
        $this->subscriptionTokenAssigner = $subscriptionTokenAssigner;
22
    }
23
24
    /**
25
     * @param GenericEvent $event
26
     *
27
     * @throws \Sylius\Component\Resource\Exception\UnexpectedTypeException
28
     */
29
    public function assignToken(GenericEvent $event)
30
    {
31
        if (!($subject = $event->getSubject()) instanceof SubscriptionInterface) {
32
            throw new UnexpectedTypeException($subject, SubscriptionInterface::class);
33
        }
34
35
        $this->subscriptionTokenAssigner->assignTokenValue($subject);
36
    }
37
}
38