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

ViewPostAction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 5
dl 0
loc 66
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B __invoke() 0 27 4
A setSeoPage() 0 4 1
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\NewsBundle\Model\BlogInterface;
15
use Sonata\NewsBundle\Model\PostManagerInterface;
16
use Sonata\SeoBundle\Seo\SeoPageInterface;
17
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
20
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
21
22
final class ViewPostAction extends Controller
23
{
24
    /**
25
     * @var BlogInterface
26
     */
27
    private $blog;
28
29
    /**
30
     * @var PostManagerInterface
31
     */
32
    private $postManager;
33
34
    /**
35
     * @var SeoPageInterface|null
36
     */
37
    private $seoPage;
38
39
    public function __construct(BlogInterface $blog, PostManagerInterface $postManager)
40
    {
41
        $this->blog = $blog;
42
        $this->postManager = $postManager;
43
    }
44
45
    /**
46
     * @param string $permalink
47
     *
48
     * @throws NotFoundHttpException
49
     *
50
     * @return Response
51
     */
52
    public function __invoke($permalink)
53
    {
54
        $post = $this->postManager->findOneByPermalink($permalink, $this->blog);
0 ignored issues
show
Bug introduced by
The method findOneByPermalink() does not exist on Sonata\NewsBundle\Model\PostManagerInterface. Did you maybe mean findOneBy()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
55
56
        if (!$post || !$post->isPublic()) {
57
            throw new NotFoundHttpException('Unable to find the post');
58
        }
59
60
        if ($seoPage = $this->seoPage) {
61
            $seoPage
62
                ->setTitle($post->getTitle())
63
                ->addMeta('name', 'description', $post->getAbstract())
64
                ->addMeta('property', 'og:title', $post->getTitle())
65
                ->addMeta('property', 'og:type', 'blog')
66
                ->addMeta('property', 'og:url', $this->generateUrl('sonata_news_view', [
67
                    'permalink' => $this->blog->getPermalinkGenerator()->generate($post),
68
                ], UrlGeneratorInterface::ABSOLUTE_URL))
69
                ->addMeta('property', 'og:description', $post->getAbstract())
70
            ;
71
        }
72
73
        return $this->render('@SonataNews/Post/view.html.twig', [
74
            'post' => $post,
75
            'form' => false,
76
            'blog' => $this->blog,
77
        ]);
78
    }
79
80
    /**
81
     * @param null|SeoPageInterface $seoPage
82
     */
83
    public function setSeoPage(SeoPageInterface $seoPage = null)
84
    {
85
        $this->seoPage = $seoPage;
86
    }
87
}
88