Test Setup Failed
Push — master ( a3a234...e290ee )
by Gerhard
15:04 queued 07:19
created

ProductSubscriber::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
/**
3
 * UserSubscriber.php
4
 *
5
 * @since 25/09/16
6
 * @author gseidel
7
 */
8
9
namespace Enhavo\Bundle\ShopBundle\EventListener;
10
11
use Enhavo\Bundle\ShopBundle\Entity\Product;
12
use Enhavo\Bundle\ShopBundle\Entity\ProductOption;
13
use Enhavo\Bundle\ShopBundle\Manager\ProductManager;
14
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
15
use Symfony\Component\EventDispatcher\GenericEvent;
16
17
class ProductSubscriber implements EventSubscriberInterface
18
{
19
    /** @var ProductManager */
20
    private $productManager;
21
22
    public function __construct(ProductManager $productManager)
23
    {
24
        $this->productManager = $productManager;
25
    }
26
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public static function getSubscribedEvents()
31
    {
32
        return [
33
            'sylius.product.pre_create' => 'onPreSave',
34
            'sylius.product.pre_update' => 'onPreSave',
35
        ];
36
    }
37
38
    public function onPreSave(GenericEvent $event)
39
    {
40
        $subject = $event->getSubject();
41
        if ($subject instanceof Product && $subject->getCode() === null) {
42
            $subject->setCode($this->productManager->generateCode());
0 ignored issues
show
Bug introduced by
The call to generateCode() misses a required argument $name.

This check looks for function calls that miss required arguments.

Loading history...
43
        }
44
    }
45
}
46