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

ArticlePublishSubscriber::onPublish()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 10
Ratio 100 %

Importance

Changes 0
Metric Value
dl 10
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
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 SWP\Bundle\ContentBundle\ArticleEvents;
20
use SWP\Bundle\ContentBundle\Event\ArticleEvent;
21
use SWP\Bundle\CoreBundle\Model\ArticleInterface;
22
use Symfony\Component\DependencyInjection\ContainerInterface;
23
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
24
25
class ArticlePublishSubscriber implements EventSubscriberInterface
26
{
27
    /**
28
     * @var ContainerInterface
29
     */
30
    protected $container;
31
32
    /**
33
     * ArticlePublishSubscriber constructor.
34
     *
35
     * @param ContainerInterface $container
36
     */
37
    public function __construct(ContainerInterface $container)
38
    {
39
        $this->container = $container;
40
    }
41
42
    /**
43
     * {@inheritdoc}
44
     */
45
    public static function getSubscribedEvents()
46
    {
47
        return [
48
            ArticleEvents::POST_PUBLISH => 'onPublish',
49
        ];
50
    }
51
52
    /**
53
     * @param ArticleEvent $event
54
     */
55 View Code Duplication
    public function onPublish(ArticleEvent $event)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57
        /** @var ArticleInterface $article */
58
        $article = $event->getArticle();
59
60
        if (null === $article->getTenantCode()) {
61
            $tenantContext = $this->container->get('swp_multi_tenancy.tenant_context');
62
            $article->setTenantCode($tenantContext->getTenant()->getCode());
63
        }
64
    }
65
}
66