Completed
Push — 3.x ( fe4009...05c76d )
by Grégoire
03:50
created

TagPostArchiveAction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 33
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A __invoke() 0 13 3
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\NewsBundle\Action;
13
14
use Sonata\ClassificationBundle\Model\TagManagerInterface;
15
use Sonata\NewsBundle\Model\BlogInterface;
16
use Sonata\NewsBundle\Model\PostManagerInterface;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
20
21
final class TagPostArchiveAction extends AbstractPostArchiveAction
22
{
23
    /**
24
     * @var TagManagerInterface
25
     */
26
    private $tagManager;
27
28
    public function __construct(BlogInterface $blog, PostManagerInterface $postManager, TagManagerInterface $tagManager)
29
    {
30
        parent::__construct($blog, $postManager);
31
32
        $this->tagManager = $tagManager;
33
    }
34
35
    /**
36
     * @param string $tag
37
     *
38
     * @return Response
39
     */
40
    public function __invoke(Request $request, $tag)
41
    {
42
        $tag = $this->tagManager->findOneBy([
43
            'slug' => $tag,
44
            'enabled' => true,
45
        ]);
46
47
        if (!$tag || !$tag->getEnabled()) {
48
            throw new NotFoundHttpException('Unable to find the tag');
49
        }
50
51
        return $this->renderArchive($request, ['tag' => $tag->getSlug()], ['tag' => $tag]);
52
    }
53
}
54