ItemsPurchasedSubscriber   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 11
c 1
b 0
f 1
dl 0
loc 23
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getSubscribedEvents() 0 5 1
A addScript() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Setono\SyliusStrandsPlugin\EventListener;
6
7
use Setono\SyliusStrandsPlugin\Tag\Tags;
8
use Setono\TagBag\Tag\TagInterface;
9
use Setono\TagBag\Tag\TwigTag;
10
use Sylius\Component\Core\Model\OrderInterface;
11
use Symfony\Component\EventDispatcher\GenericEvent;
12
13
final class ItemsPurchasedSubscriber extends TagSubscriber
14
{
15
    public static function getSubscribedEvents(): array
16
    {
17
        return [
18
            'sylius.order.post_complete' => [
19
                'addScript',
20
            ],
21
        ];
22
    }
23
24
    public function addScript(GenericEvent $event): void
25
    {
26
        $order = $event->getSubject();
27
28
        if (!$order instanceof OrderInterface) {
29
            return;
30
        }
31
32
        $this->tagBag->addTag(
33
            (new TwigTag('@SetonoSyliusStrandsPlugin/Tag/items_purchased.js.twig', ['order' => $order]))
34
                ->setSection(TagInterface::SECTION_BODY_END)
35
                ->setName(Tags::TAG_ITEMS_PURCHASED)
36
        );
37
    }
38
}
39