MonthDayRenderer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 19
rs 10
c 1
b 0
f 0
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseDateRange() 0 17 4
1
<?php
2
declare(strict_types=1);
3
/*
4
 * @link        http://github.com/seboettg/citeproc-php for the source repository
5
 * @copyright   Copyright (c) 2019 Sebastian Böttger.
6
 * @license     https://opensource.org/licenses/MIT
7
 */
8
9
namespace Seboettg\CiteProc\Rendering\Date\DateRange;
10
11
use Seboettg\CiteProc\Rendering\Date\DatePart;
12
use Seboettg\CiteProc\Rendering\Date\DateTime;
13
use Seboettg\Collection\Lists\ListInterface;
14
use Seboettg\Collection\Map\MapInterface;
15
use Seboettg\Collection\Map\Pair;
16
use function Seboettg\Collection\Lists\emptyList;
17
use function Seboettg\Collection\Lists\listOf;
18
use function Seboettg\Collection\Map\emptyMap;
19
use function Seboettg\Collection\Map\mapOf;
20
use function Seboettg\Collection\Map\pair;
21
22
class MonthDayRenderer extends DateRangeRenderer
23
{
24
    public function parseDateRange(ListInterface $datePartsList, DateTime $from, DateTime $to, string $delimiter): string
25
    {
26
        $dp = $datePartsList->toArray();
27
        $dateParts_ = [];
28
        array_walk($dp, function (Pair $datePartPair) use (&$dateParts_) {
29
            $datePart = $datePartPair->getValue();
30
            $key = $datePartPair->getKey();
31
            if (strpos($key, "month") !== false || strpos($key, "day") !== false) {
0 ignored issues
show
Bug introduced by
It seems like $key can also be of type boolean; however, parameter $haystack of strpos() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
            if (strpos(/** @scrutinizer ignore-type */ $key, "month") !== false || strpos($key, "day") !== false) {
Loading history...
32
                $dateParts_["monthday"][] = $datePart;
33
            }
34
            if (strpos($key, "year") !== false) {
35
                $dateParts_["year"] = $datePart;
36
            }
37
        });
38
        $datePartsMap = emptyMap();
39
        $datePartsMap->setArray($dateParts_);
40
        return $this->renderDateParts($datePartsMap->toList(), $from, $to, $delimiter);
41
    }
42
}
43