YearDayRenderer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A parseDateRange() 0 13 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 function Seboettg\Collection\Map\emptyMap;
16
use function Seboettg\Collection\Map\mapOf;
17
use function Seboettg\Collection\Map\pair;
18
19
class YearDayRenderer extends DateRangeRenderer
20
{
21
    public function parseDateRange(ListInterface $datePartsList, DateTime $from, DateTime $to, string $delimiter): string
22
    {
23
        $map = mapOf(pair(self::YEAR, emptyMap()), pair(self::MONTH, null));
24
        $i = 0;
25
        $datePartsList->forEach(function (string $key, DatePart $datePart) use ($map, &$i) {
26
            if (strpos($key, self::YEAR) !== false || strpos($key, self::DAY) !== false) {
27
                $map[self::YEARDAY][$i++] = $datePart;
28
            }
29
            if (strpos($key, self::MONTH) !== false) {
30
                $map[self::MONTH] = $datePart;
31
            }
32
        });
33
        return $this->renderDateParts($map, $from, $to, $delimiter);
0 ignored issues
show
Bug introduced by
$map of type anonymous//vendor/seboet...src/Map/Functions.php$0 is incompatible with the type Seboettg\Collection\Lists\ListInterface expected by parameter $dateParts of Seboettg\CiteProc\Render...erer::renderDateParts(). ( Ignorable by Annotation )

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

33
        return $this->renderDateParts(/** @scrutinizer ignore-type */ $map, $from, $to, $delimiter);
Loading history...
34
    }
35
}
36