Completed
Pull Request — master (#465)
by Marko
27:33
created

DailyPostArchiveAction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 72
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A __invoke() 0 46 2
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\IntlBundle\Templating\Helper\DateTimeHelper;
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\Translation\TranslatorInterface;
20
21
final class DailyPostArchiveAction extends AbstractPostArchiveAction
22
{
23
    /**
24
     * @var DateTimeHelper
25
     */
26
    private $dateTimeHelper;
27
28
    public function __construct(
29
        BlogInterface $blog,
30
        PostManagerInterface $postManager,
31
        TranslatorInterface $translator,
32
        DateTimeHelper $dateTimeHelper
33
    ) {
34
        parent::__construct($blog, $postManager, $translator);
35
36
        $this->dateTimeHelper = $dateTimeHelper;
37
    }
38
39
    /**
40
     * @param string $year
41
     * @param string $month
42
     * @param string $day
43
     *
44
     * @return Response
45
     */
46
    public function __invoke(Request $request, $year, $month, $day)
47
    {
48
        $date = $this->getPostManager()->getPublicationDateQueryParts(sprintf('%d-%d-%d', $year, $month, $day), 'day');
49
50
        if ($seoPage = $this->getSeoPage()) {
51
            $seoDescription = $this->getBlog()->getDescription();
52
            $seoFormat = $this->dateTimeHelper->format($date, 'MMMM');
0 ignored issues
show
Documentation introduced by
$date is of type array, but the function expects a object<DateTimeInterface>|string|integer.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
53
            $seoDate = $this->dataTimeHelper->formatDate($date);
0 ignored issues
show
Bug introduced by
The property dataTimeHelper does not seem to exist. Did you mean dateTimeHelper?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
54
55
            $seoPage
56
                ->setTitle($this->trans('archive_day.meta_title', [
57
                    '%title%' => $this->getBlog()->getTitle(),
58
                    '%year%' => $year,
59
                    '%month%' => $seoFormat,
60
                    '%day%' => $day,
61
                    '%date%' => $seoDate,
62
                ]))
63
                ->addMeta('property', 'og:title', $this->trans('archive_day.meta_title', [
64
                    '%title%' => $this->getBlog()->getTitle(),
65
                    '%year%' => $year,
66
                    '%month%' => $seoFormat,
67
                    '%day%' => $day,
68
                    '%date%' => $seoDate,
69
                ]))
70
                ->addMeta('name', 'description', $this->trans('archive_day.meta_description', [
71
                    '%title%' => $this->getBlog()->getTitle(),
72
                    '%year%' => $year,
73
                    '%month%' => $seoFormat,
74
                    '%day%' => $day,
75
                    '%description%' => $seoDescription,
76
                    '%date%' => $seoDate,
77
                ]))
78
                ->addMeta('property', 'og:description', $this->trans('archive_day.meta_description', [
79
                    '%title%' => $this->getBlog()->getTitle(),
80
                    '%year%' => $year,
81
                    '%month%' => $seoFormat,
82
                    '%day%' => $day,
83
                    '%date%' => $seoDate,
84
                    '%description%' => $seoDescription,
85
                ]));
86
        }
87
88
        return $this->renderArchive($request, [
89
            'date' => $date,
90
        ], []);
91
    }
92
}
93