Completed
Push — master ( 692aa1...25e5a7 )
by Paweł
60:22
created

ArticleTenantSubscriber::prePersist()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.2
c 0
b 0
f 0
cc 4
eloc 5
nc 3
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Core Bundle.
7
 *
8
 * Copyright 2017 Sourcefabric z.ú. and contributors.
9
 *
10
 * For the full copyright and license information, please see the
11
 * AUTHORS and LICENSE files distributed with this source code.
12
 *
13
 * @copyright 2017 Sourcefabric z.ú
14
 * @license http://www.superdesk.org/license
15
 */
16
17
namespace SWP\Bundle\CoreBundle\EventSubscriber;
18
19
use Doctrine\Common\EventSubscriber;
20
use Doctrine\Common\Persistence\Event\LifecycleEventArgs;
21
use Doctrine\ORM\Events;
22
use SWP\Bundle\CoreBundle\Model\ArticleInterface;
23
24
class ArticleTenantSubscriber implements EventSubscriber
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function getSubscribedEvents()
30
    {
31
        return [
32
            Events::prePersist,
33
        ];
34
    }
35
36
    /**
37
     * @param LifecycleEventArgs $args
38
     */
39
    public function prePersist(LifecycleEventArgs $args)
40
    {
41
        $entity = $args->getEntity();
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Persiste...eEventArgs::getEntity() has been deprecated.

This method has been deprecated.

Loading history...
42
43
        if ($entity instanceof ArticleInterface) {
44
            if (null !== $entity->getTenantCode() && !$entity->isPublishable()) {
45
                $entity->setTenantCode(null);
46
            }
47
        }
48
    }
49
}
50