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

Date::renderOneRangePart()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 4
dl 0
loc 7
ccs 6
cts 6
cp 1
crap 2
rs 10
c 0
b 0
f 0
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
4
 *
5
 * @link        http://github.com/seboettg/citeproc-php for the source repository
6
 * @copyright   Copyright (c) 2016 Sebastian Böttger.
7
 * @license     https://opensource.org/licenses/MIT
8
 */
9
10
namespace Seboettg\CiteProc\Rendering\Date;
11
12
use Exception;
13
use Seboettg\CiteProc\CiteProc;
14
use Seboettg\CiteProc\Exception\CiteProcException;
15
use Seboettg\CiteProc\Exception\InvalidStylesheetException;
16
use Seboettg\CiteProc\Rendering\Date\DateRange\DateRangeRenderer;
17
use Seboettg\CiteProc\Styles\AffixesTrait;
18
use Seboettg\CiteProc\Styles\DisplayTrait;
19
use Seboettg\CiteProc\Styles\FormattingTrait;
20
use Seboettg\CiteProc\Styles\TextCaseTrait;
21
use Seboettg\CiteProc\Util;
22
use Seboettg\Collection\ArrayList;
23
use SimpleXMLElement;
24
25
26
/**
27
 * Class Date
28
 * @package Seboettg\CiteProc\Rendering
1 ignored issue
show
Coding Style introduced by
There must be exactly one blank line before the tags in a doc comment
Loading history...
29
 *
30
 * @author Sebastian Böttger <[email protected]>
31
 */
3 ignored issues
show
Coding Style introduced by
Missing @category 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...
32
class Date
33
{
34
35
    use AffixesTrait,
0 ignored issues
show
Bug introduced by
The trait Seboettg\CiteProc\Styles\AffixesTrait requires the property $single which is not provided by Seboettg\CiteProc\Rendering\Date\Date.
Loading history...
36
        DisplayTrait,
37
        FormattingTrait,
38
        TextCaseTrait;
39
40
    // bitmask: ymd
41
    const DATE_RANGE_STATE_NONE         = 0; // 000
42
    const DATE_RANGE_STATE_DAY          = 1; // 001
43
    const DATE_RANGE_STATE_MONTH        = 2; // 010
44
    const DATE_RANGE_STATE_MONTHDAY     = 3; // 011
45
    const DATE_RANGE_STATE_YEAR         = 4; // 100
46
    const DATE_RANGE_STATE_YEARDAY      = 5; // 101
47
    const DATE_RANGE_STATE_YEARMONTH    = 6; // 110
48
    const DATE_RANGE_STATE_YEARMONTHDAY = 7; // 111
49
50
    private static $localizedDateFormats = [
0 ignored issues
show
Coding Style introduced by
Private member variable "localizedDateFormats" must be prefixed with an underscore
Loading history...
51
        'numeric',
52
        'text'
53
    ];
54
55
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
56
     * @var ArrayList
57
     */
58
    private $dateParts;
0 ignored issues
show
Coding Style introduced by
Private member variable "dateParts" must be prefixed with an underscore
Loading history...
59
60
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
61
     * @var string
62
     */
63
    private $form = "";
0 ignored issues
show
Coding Style introduced by
Private member variable "form" must be prefixed with an underscore
Loading history...
64
65
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
66
     * @var string
67
     */
68
    private $variable = "";
0 ignored issues
show
Coding Style introduced by
Private member variable "variable" must be prefixed with an underscore
Loading history...
69
70
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
71
     * @var string
72
     */
73
    private $datePartsAttribute = "";
0 ignored issues
show
Coding Style introduced by
Private member variable "datePartsAttribute" must be prefixed with an underscore
Loading history...
74
75
    /**
76
     * Date constructor.
77
     * @param SimpleXMLElement $node
3 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...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
78
     * @throws InvalidStylesheetException
1 ignored issue
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
79
     */
80 67
    public function __construct(SimpleXMLElement $node)
81
    {
82 67
        $this->dateParts = new ArrayList();
83
84
        /** @var SimpleXMLElement $attribute */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
85 67
        foreach ($node->attributes() as $attribute) {
86 67
            switch ($attribute->getName()) {
87 67
                case 'form':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
88 34
                    $this->form = (string) $attribute;
89 34
                    break;
90 67
                case 'variable':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
91 67
                    $this->variable = (string) $attribute;
92 67
                    break;
93 40
                case 'date-parts':
0 ignored issues
show
Coding Style introduced by
Line indented incorrectly; expected 12 spaces, found 16
Loading history...
94 67
                    $this->datePartsAttribute = (string) $attribute;
95
            }
96
        }
97
        /** @var SimpleXMLElement $child */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
98 67
        foreach ($node->children() as $child) {
99 51
            if ($child->getName() === "date-part") {
100 51
                $datePartName = (string) $child->attributes()["name"];
101 51
                $this->dateParts->set($this->form . "-" . $datePartName, Util\Factory::create($child));
102
            }
103
        }
104
105 67
        $this->initAffixesAttributes($node);
106 67
        $this->initDisplayAttributes($node);
107 67
        $this->initFormattingAttributes($node);
108 67
        $this->initTextCaseAttributes($node);
109 67
    }
110
111
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
112
     * @param $data
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...
113
     * @return string
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
114
     * @throws InvalidStylesheetException
1 ignored issue
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
115
     * @throws Exception
1 ignored issue
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
116
     */
117 60
    public function render($data)
118
    {
119 60
        $ret = "";
120 60
        $var = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $var is dead and can be removed.
Loading history...
121 60
        if (isset($data->{$this->variable})) {
122 56
            $var = $data->{$this->variable};
123
        } else {
124 6
            return "";
125
        }
126
127
        try {
128 56
            $this->prepareDatePartsInVariable($data, $var);
129 2
        } catch (CiteProcException $e) {
130 2
            if (isset($data->{$this->variable}->{'raw'}) &&
131 1
                !preg_match("/(\p{L}+)\s?([\-\-&,])\s?(\p{L}+)/u", $data->{$this->variable}->{'raw'})) {
0 ignored issues
show
Coding Style introduced by
Each line in a multi-line IF statement must begin with a boolean operator
Loading history...
Coding Style introduced by
Closing parenthesis of a multi-line IF statement must be on a new line
Loading history...
132 1
                return $this->addAffixes($this->format($this->applyTextCase($data->{$this->variable}->{'raw'})));
133
            } else {
134 1
                if (isset($data->{$this->variable}->{'string-literal'})) {
135 1
                    return $this->addAffixes($this->format($this->applyTextCase($data->{$this->variable}->{'string-literal'})));
136
                }
137
            }
138
        }
139
140 55
        $form = $this->form;
141 55
        $dateParts = !empty($this->datePartsAttribute) ? explode("-", $this->datePartsAttribute) : [];
142 55
        $this->prepareDatePartsChildren($dateParts, $form);
143
144
145
        // No date-parts in date-part attribute defined, take into account that the defined date-part children will be used.
146 55
        if (empty($this->datePartsAttribute) && $this->dateParts->count() > 0) {
147
            /** @var DatePart $part */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
148 43
            foreach ($this->dateParts as $part) {
149 43
                $dateParts[] = $part->getName();
150
            }
151
        }
152
153
        /* cs:date may have one or more cs:date-part child elements (see Date-part). The attributes set on
154
        these elements override those specified for the localized date formats (e.g. to get abbreviated months for all
155
        locales, the form attribute on the month-cs:date-part element can be set to “short”). These cs:date-part
156
        elements do not affect which, or in what order, date parts are rendered. Affixes, which are very
157
        locale-specific, are not allowed on these cs:date-part elements. */
158
159 55
        if ($this->dateParts->count() > 0) {
160 54
            if (!isset($var->{'date-parts'})) { // ignore empty date-parts
161
                return "";
162
            }
163
164 54
            if (count($data->{$this->variable}->{'date-parts'}) === 1) {
165 52
                $data_ = $this->createDateTime($data->{$this->variable}->{'date-parts'});
166 52
                $ret .= $this->iterateAndRenderDateParts($dateParts, $data_);
167 2
            } else if (count($var->{'date-parts'}) === 2) { //date range
168 2
                $data_ = $this->createDateTime($var->{'date-parts'});
169 2
                $from = $data_[0];
170 2
                $to = $data_[1];
171 2
                $interval = $to->diff($from);
172 2
                $delimiter = "";
173 2
                $toRender = 0;
174 2
                if ($interval->y > 0 && in_array('year', $dateParts)) {
175 1
                    $toRender |= self::DATE_RANGE_STATE_YEAR;
176 1
                    $delimiter = $this->dateParts->get($this->form . "-year")->getRangeDelimiter();
177
                }
178 2
                if ($interval->m > 0 && $from->getMonth() - $to->getMonth() !== 0 && in_array('month', $dateParts)) {
179 1
                    $toRender |= self::DATE_RANGE_STATE_MONTH;
180 1
                    $delimiter = $this->dateParts->get($this->form . "-month")->getRangeDelimiter();
181
                }
182 2
                if ($interval->d > 0 && $from->getDay() - $to->getDay() !== 0 && in_array('day', $dateParts)) {
183 1
                    $toRender |= self::DATE_RANGE_STATE_DAY;
184 1
                    $delimiter = $this->dateParts->get($this->form . "-day")->getRangeDelimiter();
185
                }
186 2
                if ($toRender === self::DATE_RANGE_STATE_NONE) {
187 1
                    $ret .= $this->iterateAndRenderDateParts($dateParts, $data_);
188
                } else {
189 1
                    $ret .= $this->renderDateRange($toRender, $from, $to, $delimiter);
190
                }
191
            }
192
193 54
            if (isset($var->raw) && preg_match("/(\p{L}+)\s?([\-\-&,])\s?(\p{L}+)/u", $var->raw, $matches)) {
194
                return $matches[1] . $matches[2] . $matches[3];
195
            }
196
        }
197
        // fallback:
198
        // When there are no dateParts children, but date-parts attribute in date
199
        // render numeric
200 1
        else if (!empty($this->datePartsAttribute)) {
0 ignored issues
show
Coding Style introduced by
Expected "} else if (...) \n"; found "\n // fallback:\n // When there are no dateParts children, but date-parts attribute in date\n // render numeric\n else if (...) {\n"
Loading history...
201 1
            $data = $this->createDateTime($var->{'date-parts'});
202 1
            $ret = $this->renderNumeric($data[0]);
203
        }
204
205 55
        return !empty($ret) ? $this->addAffixes($this->format($this->applyTextCase($ret))) : "";
206
    }
207
208
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
209
     * @param array $dates
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...
210
     * @return array
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
211
     * @throws Exception
1 ignored issue
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
212
     */
213 55
    private function createDateTime($dates)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::createDateTime" must be prefixed with an underscore
Loading history...
214
    {
215 55
        $data = [];
216 55
        foreach ($dates as $date) {
217 55
            $date = $this->cleanDate($date);
218 55
            if ($date[0] < 1000) {
219 1
                $dateTime = new DateTime(0, 0, 0);
220 1
                $dateTime->setDay(0)->setMonth(0)->setYear(0);
221 1
                $data[] = $dateTime;
222
            }
223 55
            $dateTime = new DateTime($date[0], array_key_exists(1, $date) ? $date[1] : 1, array_key_exists(2, $date) ? $date[2] : 1);
224 55
            if (!array_key_exists(1, $date)) {
225 28
                $dateTime->setMonth(0);
226
            }
227 55
            if (!array_key_exists(2, $date)) {
228 33
                $dateTime->setDay(0);
229
            }
230 55
            $data[] = $dateTime;
231
        }
232
233 55
        return $data;
234
    }
235
236
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
237
     * @param int $toRender
3 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 6 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...
238
     * @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...
239
     * @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...
240
     * @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...
241
     * @return string
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
242
     */
243 1
    private function renderDateRange($toRender, DateTime $from, DateTime $to, $delimiter)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::renderDateRange" must be prefixed with an underscore
Loading history...
244
    {
245 1
        $datePartRenderer = DateRangeRenderer::factory($this, $toRender);
246 1
        return $datePartRenderer->parseDateRange($this->dateParts, $from, $to, $delimiter);
247
    }
248
249
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
250
     * @param string $format
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...
251
     * @return bool
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
252
     */
253 16
    private function hasDatePartsFromLocales($format)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::hasDatePartsFromLocales" must be prefixed with an underscore
Loading history...
254
    {
255 16
        $dateXml = CiteProc::getContext()->getLocale()->getDateXml();
256 16
        return !empty($dateXml[$format]);
257
    }
258
259
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
260
     * @param string $format
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...
261
     * @return array
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
262
     */
263 16
    private function getDatePartsFromLocales($format)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::getDatePartsFromLocales" must be prefixed with an underscore
Loading history...
264
    {
265 16
        $ret = [];
266
        // date parts from locales
267 16
        $dateFromLocale_ = CiteProc::getContext()->getLocale()->getDateXml();
268 16
        $dateFromLocale = $dateFromLocale_[$format];
269
270
        // no custom date parts within the date element (this)?
271 16
        if (!empty($dateFromLocale)) {
272
273 16
            $dateForm = array_filter(is_array($dateFromLocale) ? $dateFromLocale : [$dateFromLocale], function($element) use ($format) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
274
                /** @var SimpleXMLElement $element */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
275 16
                $dateForm = (string) $element->attributes()["form"];
276 16
                return $dateForm === $format;
277 16
            });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
278
279
            //has dateForm from locale children (date-part elements)?
280 16
            $localeDate = array_pop($dateForm);
281
282 16
            if ($localeDate instanceof SimpleXMLElement && $localeDate->count() > 0) {
283 16
                foreach ($localeDate as $child) {
284 16
                    $ret[] = $child;
285
                }
286
            }
287
        }
288 16
        return $ret;
289
    }
290
291
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
292
     * @return string
293
     */
294 28
    public function getVariable()
295
    {
296 28
        return $this->variable;
297
    }
298
299
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
300
     * @param $data
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...
301
     * @param $var
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...
302
     * @throws CiteProcException
1 ignored issue
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
303
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
304 56
    private function prepareDatePartsInVariable($data, $var)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::prepareDatePartsInVariable" must be prefixed with an underscore
Loading history...
305
    {
306 56
        if (!isset($data->{$this->variable}->{'date-parts'}) || empty($data->{$this->variable}->{'date-parts'})) {
307 7
            if (isset($data->{$this->variable}->raw) && !empty($data->{$this->variable}->raw)) {
308
                // try to parse date parts from "raw" attribute
309 6
                $var->{'date-parts'} = Util\DateHelper::parseDateParts($data->{$this->variable});
310
            } else {
311 1
                throw new CiteProcException("No valid date format");
312
            }
313
        }
314 55
    }
315
316
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
317
     * @param $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...
318
     * @param string $form
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...
319
     * @throws InvalidStylesheetException
1 ignored issue
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
320
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
321 55
    private function prepareDatePartsChildren($dateParts, $form)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::prepareDatePartsChildren" must be prefixed with an underscore
Loading history...
322
    {
323
        /* Localized date formats are selected with the optional form attribute, which must set to either “numeric”
324
        (for fully numeric formats, e.g. “12-15-2005”), or “text” (for formats with a non-numeric month, e.g.
325
        “December 15, 2005”). Localized date formats can be customized in two ways. First, the date-parts attribute may
326
        be used to show fewer date parts. The possible values are:
327
            - “year-month-day” - (default), renders the year, month and day
328
            - “year-month” - renders the year and month
329
            - “year” - renders the year */
330
331 55
        if ($this->dateParts->count() < 1 && in_array($form, self::$localizedDateFormats)) {
332 16
            if ($this->hasDatePartsFromLocales($form)) {
333 16
                $datePartsFromLocales = $this->getDatePartsFromLocales($form);
334 16
                array_filter($datePartsFromLocales, function(SimpleXMLElement $item) use ($dateParts) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
335 16
                    return in_array($item["name"], $dateParts);
336 16
                });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
337
338 16
                foreach ($datePartsFromLocales as $datePartNode) {
339 16
                    $datePart = $datePartNode["name"];
340 16
                    $this->dateParts->set("$form-$datePart", Util\Factory::create($datePartNode));
341
                }
342
            } else { //otherwise create default date parts
343
                foreach ($dateParts as $datePart) {
344
                    $this->dateParts->add("$form-$datePart", new DatePart(new SimpleXMLElement('<date-part name="' . $datePart . '" form="' . $form . '" />')));
345
                }
346
            }
347
        }
348 55
    }
349
350
351 1
    private function renderNumeric(DateTime $date)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::renderNumeric" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function renderNumeric()
Loading history...
352
    {
353 1
        return $date->renderNumeric();
354
    }
355
356 12
    public function getForm()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function getForm()
Loading history...
357
    {
358 12
        return $this->form;
359
    }
360
361 55
    private function cleanDate($date)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::cleanDate" must be prefixed with an underscore
Loading history...
Coding Style introduced by
Missing doc comment for function cleanDate()
Loading history...
362
    {
363 55
        $ret = [];
364 55
        foreach ($date as $key => $datePart) {
365 55
            $ret[$key] = Util\NumberHelper::extractNumber(Util\StringHelper::removeBrackets($datePart));
366
        }
367 55
        return $ret;
368
    }
369
370
    /**
1 ignored issue
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
371
     * @param array $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...
372
     * @param array $data_
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...
373
     * @return string
1 ignored issue
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
374
     */
375 53
    private function iterateAndRenderDateParts(array $dateParts, array $data_)
1 ignored issue
show
Coding Style introduced by
Private method name "Date::iterateAndRenderDateParts" must be prefixed with an underscore
Loading history...
376
    {
377 53
        $ret = "";
378
        /** @var DatePart $datePart */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
379 53
        foreach ($this->dateParts as $key => $datePart) {
380
            /** @noinspection PhpUnusedLocalVariableInspection */
3 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
381 53
            list($f, $p) = explode("-", $key);
382 53
            if (in_array($p, $dateParts)) {
383 53
                $ret .= $datePart->render($data_[0], $this);
384
            }
385
        }
386 53
        return $ret;
387
    }
388
}
389