Completed
Push — master ( 37876c...34238f )
by Marko
9s
created

MonthlyPostArchiveAction::__invoke()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 34
rs 9.376
cc 2
nc 2
nop 3
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 MonthlyPostArchiveAction 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
     *
45
     * @return Response
46
     */
47
    public function __invoke(Request $request, $year, $month)
48
    {
49
        $date = $this->getPostManager()->getPublicationDateQueryParts(sprintf('%d-%d-%d', $year, $month, 1), 'month');
50
51
        if ($seoPage = $this->getSeoPage()) {
52
            $seoPage
53
                ->setTitle($this->trans('archive_month.meta_title', [
54
                    '%title%' => $this->getBlog()->getTitle(),
55
                    '%year%' => $year,
56
                    '%month%' => $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...
57
                ]))
58
                ->addMeta('property', 'og:title', $this->trans('archive_month.meta_title', [
59
                    '%title%' => $this->getBlog()->getTitle(),
60
                    '%year%' => $year,
61
                    '%month%' => $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...
62
                ]))
63
                ->addMeta('name', 'description', $this->trans('archive_month.meta_description', [
64
                    '%title%' => $this->getBlog()->getTitle(),
65
                    '%year%' => $year,
66
                    '%month%' => $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...
67
                    '%description%' => $this->getBlog()->getDescription(),
68
                ]))
69
                ->addMeta('property', 'og:description', $this->trans('archive_month.meta_description', [
70
                    '%title%' => $this->getBlog()->getTitle(),
71
                    '%year%' => $year,
72
                    '%month%' => $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...
73
                    '%description%' => $this->getBlog()->getDescription(),
74
                ]));
75
        }
76
77
        return $this->renderArchive($request, [
78
            'date' => $date,
79
        ], []);
80
    }
81
}
82