Passed
Push — master ( 02a778...9f9faf )
by Sebastian
06:11
created

DateRangeRenderer::getRenderer()   B

Complexity

Conditions 8
Paths 8

Size

Total Lines 27
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 22
CRAP Score 8.0368

Importance

Changes 0
Metric Value
cc 8
eloc 24
c 0
b 0
f 0
nc 8
nop 1
dl 0
loc 27
ccs 22
cts 24
cp 0.9167
crap 8.0368
rs 8.4444
1
<?php
2
/*
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
 * citeproc-php: DateRangeParser.php
4
 * User: Sebastian Böttger <[email protected]>
5
 * created at 03.11.19, 20:00
6
 */
7
8
namespace Seboettg\CiteProc\Rendering\Date\DateRange;
9
10
use Seboettg\CiteProc\Rendering\Date\DatePart;
11
use Seboettg\CiteProc\Rendering\Date\DateTime;
12
use Seboettg\CiteProc\Rendering\Date\Date;
13
use Seboettg\Collection\ArrayList;
14
15
/**
16
 * Class DatePartRenderer
17
 * @package Seboettg\CiteProc\Rendering\Date\DateRange
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
18
 */
4 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
19
abstract class DateRangeRenderer {
0 ignored issues
show
Coding Style introduced by
Opening brace of a class must be on the line after the definition
Loading history...
20
21
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
22
     * @var Date
23
     */
24
    protected $parentDateObject;
25
26
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
27
     * @param Date $dateObject
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
28
     * @param int $toRender
3 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 2 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
29
     * @return DateRangeRenderer
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
30
     */
31 1
    public static function factory(Date $dateObject, $toRender)
32
    {
33 1
        $className = self::getRenderer($toRender);
34 1
        return new $className($dateObject);
35
    }
36
37
    /**
38
     * DatePartRenderer constructor.
39
     * @param Date $parentDateObject
2 ignored issues
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
Coding Style introduced by
Missing parameter comment
Loading history...
40
     */
41 1
    public function __construct(Date $parentDateObject)
42
    {
43 1
        $this->parentDateObject = $parentDateObject;
44 1
    }
45
46 1
    private static function getRenderer($toRender)
1 ignored issue
show
Coding Style introduced by
Private method name "DateRangeRenderer::getRenderer" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function getRenderer()
Loading history...
47
    {
48 1
        $className = "";
49
        switch ($toRender) {
50 1
            case Date::DATE_RANGE_STATE_DAY:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
51 1
                $className = "DayRenderer";
52 1
                break;
53 1
            case Date::DATE_RANGE_STATE_MONTH:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
54 1
                $className = "MonthRenderer";
55 1
                break;
56 1
            case Date::DATE_RANGE_STATE_YEAR:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
57 1
                $className = "YearRenderer";
58 1
                break;
59 1
            case Date::DATE_RANGE_STATE_MONTHDAY:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
60 1
                $className = "MonthDayRenderer";
61 1
                break;
62 1
            case Date::DATE_RANGE_STATE_YEARDAY:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
63
                $className = "YearDayRenderer";
64
                break;
65 1
            case Date::DATE_RANGE_STATE_YEARMONTH:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
66 1
                $className = "YearMonthRenderer";
67 1
                break;
68 1
            case Date::DATE_RANGE_STATE_YEARMONTHDAY:
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 8 spaces, found 12
Loading history...
69 1
                $className = "YearMonthDayRenderer";
70 1
                break;
71
        }
72 1
        return __NAMESPACE__ . "\\" . $className;
73
    }
74
75
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
76
     * @param ArrayList<DatePart> $dateParts
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
77
     * @param DateTime $from
3 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
78
     * @param DateTime $to
3 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 12 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
79
     * @param $delimiter
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
80
     * @return string
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
81
     */
82
    public abstract function parseDateRange(ArrayList $dateParts, DateTime $from, DateTime $to, $delimiter);
83
84
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
85
     * @param DatePart $datePart
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
86
     * @param DateTime $from
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
87
     * @param DateTime $to
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
88
     * @param $delimiter
2 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
89
     * @return string
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
90
     */
91 1
    protected function renderOneRangePart(DatePart $datePart, DateTime $from, DateTime $to, $delimiter)
92
    {
93 1
        $prefix = $datePart->renderPrefix();
94 1
        $from = $datePart->renderWithoutAffixes($from, $this->parentDateObject);
95 1
        $to = $datePart->renderWithoutAffixes($to, $this->parentDateObject);
96 1
        $suffix = !empty($to) ? $datePart->renderSuffix() : "";
97 1
        return $prefix . $from . $delimiter . $to . $suffix;
98
    }
99
100 1
    protected function renderDateParts($dateParts, $from, $to, $delimiter)
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function renderDateParts()
Loading history...
101
    {
102 1
        $ret = "";
103 1
        foreach ($dateParts as $datePart) {
104 1
            if (is_array($datePart)) {
105
106 1
                $renderedFrom  = $datePart[0]->render($from, $this->parentDateObject);
107 1
                $renderedFrom .= $datePart[1]->renderPrefix();
108 1
                $renderedFrom .= $datePart[1]->renderWithoutAffixes($from, $this->parentDateObject);
109 1
                $renderedTo  = $datePart[0]->renderWithoutAffixes($to, $this->parentDateObject);
110 1
                $renderedTo .= $datePart[0]->renderSuffix();
111 1
                $renderedTo .= $datePart[1]->render($to, $this->parentDateObject);
112 1
                $ret .= $renderedFrom . $delimiter . $renderedTo;
113
            } else {
114 1
                $ret .= $datePart->render($from, $this->parentDateObject);
115
            }
116
        }
117 1
        return $ret;
118
    }
119
}
120