DailyPostArchiveAction::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NewsBundle\Action;
15
16
use Sonata\IntlBundle\Templating\Helper\DateTimeHelper;
17
use Sonata\NewsBundle\Model\BlogInterface;
18
use Sonata\NewsBundle\Model\PostManagerInterface;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpFoundation\Response;
21
use Symfony\Component\Translation\TranslatorInterface;
22
23
final class DailyPostArchiveAction extends AbstractPostArchiveAction
24
{
25
    /**
26
     * @var DateTimeHelper
27
     */
28
    private $dateTimeHelper;
29
30
    public function __construct(
31
        BlogInterface $blog,
32
        PostManagerInterface $postManager,
33
        TranslatorInterface $translator,
34
        DateTimeHelper $dateTimeHelper
35
    ) {
36
        parent::__construct($blog, $postManager, $translator);
37
38
        $this->dateTimeHelper = $dateTimeHelper;
39
    }
40
41
    /**
42
     * @param string $year
43
     * @param string $month
44
     * @param string $day
45
     *
46
     * @return Response
47
     */
48
    public function __invoke(Request $request, $year, $month, $day)
49
    {
50
        $date = $this->getPostManager()->getPublicationDateQueryParts(sprintf('%d-%d-%d', $year, $month, $day), 'day');
51
52
        if ($seoPage = $this->getSeoPage()) {
53
            $seoDescription = $this->getBlog()->getDescription();
54
            $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...
55
            $seoDate = $this->dateTimeHelper->formatDate($date);
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...
56
57
            $seoPage
58
                ->addTitle($this->trans('archive_day.meta_title', [
59
                    '%title%' => $this->getBlog()->getTitle(),
60
                    '%year%' => $year,
61
                    '%month%' => $seoFormat,
62
                    '%day%' => $day,
63
                    '%date%' => $seoDate,
64
                ]))
65
                ->addMeta('property', 'og:title', $this->trans('archive_day.meta_title', [
66
                    '%title%' => $this->getBlog()->getTitle(),
67
                    '%year%' => $year,
68
                    '%month%' => $seoFormat,
69
                    '%day%' => $day,
70
                    '%date%' => $seoDate,
71
                ]))
72
                ->addMeta('name', 'description', $this->trans('archive_day.meta_description', [
73
                    '%title%' => $this->getBlog()->getTitle(),
74
                    '%year%' => $year,
75
                    '%month%' => $seoFormat,
76
                    '%day%' => $day,
77
                    '%description%' => $seoDescription,
78
                    '%date%' => $seoDate,
79
                ]))
80
                ->addMeta('property', 'og:description', $this->trans('archive_day.meta_description', [
81
                    '%title%' => $this->getBlog()->getTitle(),
82
                    '%year%' => $year,
83
                    '%month%' => $seoFormat,
84
                    '%day%' => $day,
85
                    '%date%' => $seoDate,
86
                    '%description%' => $seoDescription,
87
                ]));
88
        }
89
90
        return $this->renderArchive($request, [
91
            'date' => $date,
92
        ], []);
93
    }
94
}
95