Completed
Pull Request — master (#465)
by Marko
27:33
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
/*
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 MonthlyPostArchiveAction 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
     *
43
     * @return Response
44
     */
45
    public function __invoke(Request $request, $year, $month)
46
    {
47
        $date = $this->getPostManager()->getPublicationDateQueryParts(sprintf('%d-%d-%d', $year, $month, 1), 'month');
48
49
        if ($seoPage = $this->getSeoPage()) {
50
            $seoPage
51
                ->setTitle($this->trans('archive_month.meta_title', [
52
                    '%title%' => $this->getBlog()->getTitle(),
53
                    '%year%' => $year,
54
                    '%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...
55
                ]))
56
                ->addMeta('property', 'og:title', $this->trans('archive_month.meta_title', [
57
                    '%title%' => $this->getBlog()->getTitle(),
58
                    '%year%' => $year,
59
                    '%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...
60
                ]))
61
                ->addMeta('name', 'description', $this->trans('archive_month.meta_description', [
62
                    '%title%' => $this->getBlog()->getTitle(),
63
                    '%year%' => $year,
64
                    '%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...
65
                    '%description%' => $this->getBlog()->getDescription(),
66
                ]))
67
                ->addMeta('property', 'og:description', $this->trans('archive_month.meta_description', [
68
                    '%title%' => $this->getBlog()->getTitle(),
69
                    '%year%' => $year,
70
                    '%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...
71
                    '%description%' => $this->getBlog()->getDescription(),
72
                ]));
73
        }
74
75
        return $this->renderArchive($request, [
76
            'date' => $date,
77
        ], []);
78
    }
79
}
80