Completed
Push — master ( 05e313...6af484 )
by Tim
13s
created

WeekViewHelper::getCwYear()   A

Complexity

Conditions 6
Paths 3

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.2222
c 0
b 0
f 0
cc 6
nc 3
nop 1
1
<?php
2
3
/**
4
 * Link to the week.
5
 */
6
declare(strict_types=1);
7
8
namespace HDNET\Calendarize\ViewHelpers\Link;
9
10
/**
11
 * Link to the week.
12
 */
13
class WeekViewHelper extends AbstractLinkViewHelper
14
{
15
    /**
16
     * Init arguments.
17
     */
18
    public function initializeArguments()
19
    {
20
        parent::initializeArguments();
21
        $this->registerArgument('date', \DateTime::class, '', true);
22
        $this->registerArgument('pageUid', 'int', '', false, 0);
23
    }
24
25
    /**
26
     * Render the link to the given day.
27
     *
28
     * @return string
29
     */
30
    public function render()
31
    {
32
        if (!\is_object($this->arguments['date'])) {
33
            $this->logger->error('Do not call week viewhelper without date');
34
35
            return $this->renderChildren();
36
        }
37
        $date = $this->arguments['date'];
38
        $additionalParams = [
39
            'tx_calendarize_calendar' => [
40
                'year' => $this->getCwYear($date),
41
                'week' => $date->format('W'),
42
            ],
43
        ];
44
45
        return parent::renderLink($this->getPageUid($this->arguments['pageUid']), $additionalParams);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (renderLink() instead of render()). Are you sure this is correct? If so, you might want to change this to $this->renderLink().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
46
    }
47
48
    /**
49
     * @param \DateTime $date
50
     * @return int
51
     */
52
    protected function getCwYear(\DateTime $date)
53
    {
54
        $year = (int)$date->format('Y');
55
        if ($date->format('m') === '01' && ($date->format('W') === '52' || $date->format('W') === '53')) {
56
            $year--;
57
        } else {
58
            if ($date->format('m') === '12' && $date->format('W') === '01') {
59
                $year++;
60
            }
61
        }
62
        return $year;
63
    }
64
}
65