Completed
Push — master ( 3ef484...ea5778 )
by Paweł
08:46
created

ArticlePublishListener::unpublish()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Superdesk Web Publisher Content 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\ContentBundle\EventListener;
18
19
use SWP\Bundle\ContentBundle\Event\ArticleEvent;
20
use SWP\Bundle\ContentBundle\Model\ArticleInterface;
21
use SWP\Bundle\ContentBundle\Service\ArticleServiceInterface;
22
23
final class ArticlePublishListener
24
{
25
    /**
26
     * @var ArticleServiceInterface
27
     */
28
    private $articleService;
29
30
    /**
31
     * ArticlePublishListener constructor.
32
     *
33
     * @param ArticleServiceInterface $articleService
34
     */
35
    public function __construct(ArticleServiceInterface $articleService)
36
    {
37
        $this->articleService = $articleService;
38
    }
39
40
    /**
41
     * @param ArticleEvent $event
42
     */
43
    public function publish(ArticleEvent $event)
44
    {
45
        $article = $event->getArticle();
46
47
        if ($article->isPublished()) {
48
            return;
49
        }
50
51
        $this->articleService->publish($article);
52
    }
53
54
    /**
55
     * @param ArticleEvent $event
56
     */
57
    public function unpublish(ArticleEvent $event)
58
    {
59
        $article = $event->getArticle();
60
61
        if ($article->isPublished()) {
62
            $this->articleService->unpublish($article, ArticleInterface::STATUS_UNPUBLISHED);
63
        }
64
    }
65
66
    /**
67
     * @param ArticleEvent $event
68
     */
69
    public function cancel(ArticleEvent $event)
70
    {
71
        $this->articleService->unpublish($event->getArticle(), ArticleInterface::STATUS_CANCELED);
72
    }
73
}
74