Completed
Push — master ( 63d470...84e35a )
by Adam
18:27
created

InvoiceDoctrineSubscriber::getSubscribedEvents()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 * 
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 * 
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Bundle\InvoiceBundle\EventListener;
14
15
use Doctrine\Common\EventSubscriber;
16
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
17
use WellCommerce\Bundle\AppBundle\Entity\Shop;
18
19
/**
20
 * Class InvoiceDoctrineSubscriber
21
 *
22
 * @author  Adam Piotrowski <[email protected]>
23
 */
24
class InvoiceDoctrineSubscriber implements EventSubscriber
25
{
26
    public function getSubscribedEvents()
27
    {
28
        return [
29
            'prePersist',
30
        ];
31
    }
32
    
33
    public function preUpdate(LifecycleEventArgs $args)
34
    {
35
        $this->onShopDataBeforeSave($args);
36
    }
37
    
38
    public function prePersist(LifecycleEventArgs $args)
39
    {
40
        $this->onShopDataBeforeSave($args);
41
    }
42
    
43
    public function onShopDataBeforeSave(LifecycleEventArgs $args)
44
    {
45
        $entity = $args->getObject();
46
        
47
        if ($entity instanceof Shop) {
48
            if (null === $entity->getInvoiceMaturity()) {
49
                $entity->setInvoiceMaturity(7);
50
            }
51
            
52
            if (null === $entity->getInvoiceProcessor()) {
53
                $entity->setInvoiceProcessor('generic');
54
            }
55
        }
56
    }
57
}
58