YearMonthRenderer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseDateRange() 0 21 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\Pair;
15
use function Seboettg\Collection\Map\emptyMap;
16
use function Seboettg\Collection\Map\mapOf;
17
use function Seboettg\Collection\Map\pair;
18
19
class YearMonthRenderer extends DateRangeRenderer
20
{
21
    public function parseDateRange(
22
        ListInterface $datePartsList,
23
        DateTime $from,
24
        DateTime $to,
25
        string $delimiter
26
    ): string {
27
        $dp = $datePartsList->toArray();
28
        $dateParts = [];
29
        array_walk($dp, function (Pair $datePartPair) use (&$dateParts) {
30
            $datePart = $datePartPair->getValue();
31
            $key = $datePartPair->getKey();
32
            if (strpos($key, "year") !== false || strpos($key, "month") !== 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

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