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

ArticlePublishListener   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 3
dl 0
loc 51
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A publish() 0 10 2
A unpublish() 0 8 2
A cancel() 0 4 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