| Total Complexity | 109 |
| Total Lines | 510 |
| Duplicated Lines | 0 % |
| Coverage | 93.75% |
| Changes | 0 | ||
Complex classes like Date often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Date, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class Date |
||
| 29 | { |
||
| 30 | |||
| 31 | use AffixesTrait, |
||
| 32 | DisplayTrait, |
||
| 33 | FormattingTrait, |
||
| 34 | TextCaseTrait; |
||
| 35 | |||
| 36 | // ymd |
||
| 37 | const DATE_RANGE_STATE_NONE = 0; // 000 |
||
| 38 | const DATE_RANGE_STATE_DAY = 1; // 001 |
||
| 39 | const DATE_RANGE_STATE_MONTH = 2; // 010 |
||
| 40 | const DATE_RANGE_STATE_MONTHDAY = 3; // 011 |
||
| 41 | const DATE_RANGE_STATE_YEAR = 4; // 100 |
||
| 42 | const DATE_RANGE_STATE_YEARDAY = 5; // 101 |
||
| 43 | const DATE_RANGE_STATE_YEARMONTH = 6; // 110 |
||
| 44 | const DATE_RANGE_STATE_YEARMONTHDAY = 7; // 111 |
||
| 45 | |||
| 46 | private static $localizedDateFormats = [ |
||
| 47 | 'numeric', |
||
| 48 | 'text' |
||
| 49 | ]; |
||
| 50 | |||
| 51 | /** |
||
|
1 ignored issue
–
show
|
|||
| 52 | * @var ArrayList |
||
| 53 | */ |
||
| 54 | private $dateParts; |
||
| 55 | |||
| 56 | /** |
||
|
1 ignored issue
–
show
|
|||
| 57 | * @var string |
||
| 58 | */ |
||
| 59 | private $form = ""; |
||
| 60 | |||
| 61 | /** |
||
|
1 ignored issue
–
show
|
|||
| 62 | * @var string |
||
| 63 | */ |
||
| 64 | private $variable = ""; |
||
| 65 | |||
| 66 | /** |
||
|
1 ignored issue
–
show
|
|||
| 67 | * @var string |
||
| 68 | */ |
||
| 69 | private $datePartsAttribute = ""; |
||
| 70 | |||
| 71 | /** |
||
| 72 | * Date constructor. |
||
| 73 | * @param \SimpleXMLElement $node |
||
|
3 ignored issues
–
show
|
|||
| 74 | * @throws \Seboettg\CiteProc\Exception\InvalidStylesheetException |
||
|
1 ignored issue
–
show
|
|||
| 75 | */ |
||
| 76 | 56 | public function __construct(\SimpleXMLElement $node) |
|
| 105 | 56 | } |
|
| 106 | |||
| 107 | /** |
||
|
1 ignored issue
–
show
|
|||
| 108 | * @param $data |
||
|
1 ignored issue
–
show
|
|||
| 109 | * @return string |
||
|
1 ignored issue
–
show
|
|||
| 110 | * @throws \Seboettg\CiteProc\Exception\InvalidStylesheetException |
||
|
1 ignored issue
–
show
|
|||
| 111 | * @throws \Exception |
||
|
1 ignored issue
–
show
|
|||
| 112 | */ |
||
| 113 | 49 | public function render($data) |
|
| 114 | { |
||
| 115 | 49 | $ret = ""; |
|
| 116 | 49 | $var = null; |
|
| 117 | 49 | if (isset($data->{$this->variable})) { |
|
| 118 | 48 | $var = $data->{$this->variable}; |
|
| 119 | } else { |
||
| 120 | 7 | return ""; |
|
| 121 | } |
||
| 122 | |||
| 123 | try { |
||
| 124 | 48 | $this->prepareDatePartsInVariable($data, $var); |
|
| 125 | 1 | } catch (CiteProcException $e) { |
|
| 126 | 1 | if (!preg_match("/(\p{L}+)\s?([\-\-\&,])\s?(\p{L}+)/u", $data->{$this->variable}->raw)) { |
|
| 127 | 1 | return $this->addAffixes($this->format($this->applyTextCase($data->{$this->variable}->raw))); |
|
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | 48 | $form = $this->form; |
|
| 132 | 48 | $dateParts = !empty($this->datePartsAttribute) ? explode("-", $this->datePartsAttribute) : []; |
|
| 133 | 48 | $this->prepareDatePartsChildren($dateParts, $form); |
|
| 134 | |||
| 135 | |||
| 136 | // No date-parts in date-part attribute defined, take into account that the defined date-part children will be used. |
||
| 137 | 48 | if (empty($this->datePartsAttribute) && $this->dateParts->count() > 0) { |
|
| 138 | /** @var DatePart $part */ |
||
|
3 ignored issues
–
show
|
|||
| 139 | 36 | foreach ($this->dateParts as $part) { |
|
| 140 | 36 | $dateParts[] = $part->getName(); |
|
| 141 | } |
||
| 142 | } |
||
| 143 | |||
| 144 | /* cs:date may have one or more cs:date-part child elements (see Date-part). The attributes set on |
||
| 145 | these elements override those specified for the localized date formats (e.g. to get abbreviated months for all |
||
| 146 | locales, the form attribute on the month-cs:date-part element can be set to “short”). These cs:date-part |
||
| 147 | elements do not affect which, or in what order, date parts are rendered. Affixes, which are very |
||
| 148 | locale-specific, are not allowed on these cs:date-part elements. */ |
||
| 149 | |||
| 150 | 48 | if ($this->dateParts->count() > 0) { |
|
| 151 | |||
| 152 | /* if (isset($var->raw) && !preg_match("/(\p{L}+)\s?([\-\-\&,])\s?(\p{L}+)/u", $var->raw) && $this->dateParts->count() > 0) { |
||
| 153 | //$var->{"date-parts"} = []; |
||
| 154 | } else*/ |
||
| 155 | 47 | if (!isset($var->{'date-parts'})) { // ignore empty date-parts |
|
| 156 | return ""; |
||
| 157 | } |
||
| 158 | |||
| 159 | 47 | if (count($data->{$this->variable}->{'date-parts'}) === 1) { |
|
| 160 | 46 | $data_ = $this->createDateTime($data->{$this->variable}->{'date-parts'}); |
|
| 161 | /** @var DatePart $datePart */ |
||
|
3 ignored issues
–
show
|
|||
| 162 | 46 | foreach ($this->dateParts as $key => $datePart) { |
|
| 163 | /** @noinspection PhpUnusedLocalVariableInspection */ |
||
|
3 ignored issues
–
show
|
|||
| 164 | 46 | list($f, $p) = explode("-", $key); |
|
| 165 | 46 | if (in_array($p, $dateParts)) { |
|
| 166 | 46 | $ret .= $datePart->render($data_[0], $this); |
|
| 167 | } |
||
| 168 | } |
||
| 169 | 2 | } else if (count($var->{'date-parts'}) === 2) { //date range |
|
| 170 | 2 | $data_ = $this->createDateTime($var->{'date-parts'}); |
|
| 171 | 2 | $from = $data_[0]; |
|
| 172 | 2 | $to = $data_[1]; |
|
| 173 | 2 | $interval = $to->diff($from); |
|
| 174 | 2 | $delim = ""; |
|
| 175 | 2 | $toRender = 0; |
|
| 176 | 2 | if ($interval->y > 0 && in_array('year', $dateParts)) { |
|
| 177 | 1 | $toRender |= self::DATE_RANGE_STATE_YEAR; |
|
| 178 | 1 | $delim = $this->dateParts->get($this->form . "-year")->getRangeDelimiter(); |
|
| 179 | } |
||
| 180 | 2 | if ($interval->m > 0 && $from->getMonth() - $to->getMonth() !== 0 && in_array('month', $dateParts)) { |
|
| 181 | 1 | $toRender |= self::DATE_RANGE_STATE_MONTH; |
|
| 182 | 1 | $delim = $this->dateParts->get($this->form . "-month")->getRangeDelimiter(); |
|
| 183 | } |
||
| 184 | 2 | if ($interval->d > 0 && $from->getDay() - $to->getDay() !== 0 && in_array('day', $dateParts)) { |
|
| 185 | 1 | $toRender |= self::DATE_RANGE_STATE_DAY; |
|
| 186 | 1 | $delim = $this->dateParts->get($this->form . "-day")->getRangeDelimiter(); |
|
| 187 | } |
||
| 188 | 2 | if ($toRender === self::DATE_RANGE_STATE_NONE) { |
|
| 189 | 1 | foreach ($this->dateParts as $key => $datePart) { |
|
| 190 | /** @noinspection PhpUnusedLocalVariableInspection */ |
||
|
3 ignored issues
–
show
|
|||
| 191 | 1 | list($f, $p) = explode("-", $key); |
|
| 192 | 1 | if (in_array($p, $dateParts)) { |
|
| 193 | 1 | $ret .= $datePart->render($data_[0], $this); |
|
| 194 | } |
||
| 195 | } |
||
| 196 | } else { |
||
| 197 | 1 | $ret = $this->renderDateRange($toRender, $from, $to, $delim); |
|
| 198 | } |
||
| 199 | } |
||
| 200 | |||
| 201 | 47 | if (isset($var->raw) && preg_match("/(\p{L}+)\s?([\-\-\&,])\s?(\p{L}+)/u", $var->raw, $matches)) { |
|
| 202 | return $matches[1] . $matches[2] . $matches[3]; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | // fallback: |
||
| 206 | // When there are no dateParts children, but date-parts attribute in date |
||
| 207 | // render numeric |
||
| 208 | 1 | else if (!empty($this->datePartsAttribute)) { |
|
| 209 | 1 | $data = $this->createDateTime($var->{'date-parts'}); |
|
| 210 | 1 | $ret = $this->renderNumeric($data[0]); |
|
| 211 | } |
||
| 212 | |||
| 213 | 48 | return !empty($ret) ? $this->addAffixes($this->format($this->applyTextCase($ret))) : ""; |
|
| 214 | } |
||
| 215 | |||
| 216 | /** |
||
|
1 ignored issue
–
show
|
|||
| 217 | * @param array $dates |
||
|
2 ignored issues
–
show
|
|||
| 218 | * @return array |
||
|
1 ignored issue
–
show
|
|||
| 219 | * @throws \Exception |
||
|
1 ignored issue
–
show
|
|||
| 220 | */ |
||
| 221 | 48 | private function createDateTime($dates) |
|
|
1 ignored issue
–
show
|
|||
| 222 | { |
||
| 223 | 48 | $data = []; |
|
| 224 | 48 | foreach ($dates as $date) { |
|
| 225 | 48 | $date = $this->cleanDate($date); |
|
| 226 | 48 | if ($date[0] < 1000) { |
|
| 227 | 1 | $dateTime = new DateTime(0, 0, 0); |
|
| 228 | 1 | $dateTime->setDay(0)->setMonth(0)->setYear(0); |
|
| 229 | 1 | $data[] = $dateTime; |
|
| 230 | } |
||
| 231 | 48 | $dateTime = new DateTime($date[0], array_key_exists(1, $date) ? $date[1] : 1, array_key_exists(2, $date) ? $date[2] : 1); |
|
| 232 | 48 | if (!array_key_exists(1, $date)) { |
|
| 233 | 26 | $dateTime->setMonth(0); |
|
| 234 | } |
||
| 235 | 48 | if (!array_key_exists(2, $date)) { |
|
| 236 | 31 | $dateTime->setDay(0); |
|
| 237 | } |
||
| 238 | 48 | $data[] = $dateTime; |
|
| 239 | } |
||
| 240 | |||
| 241 | 48 | return $data; |
|
| 242 | } |
||
| 243 | |||
| 244 | /** |
||
|
1 ignored issue
–
show
|
|||
| 245 | * @param integer $differentParts |
||
|
3 ignored issues
–
show
|
|||
| 246 | * @param DateTime $from |
||
|
2 ignored issues
–
show
|
|||
| 247 | * @param DateTime $to |
||
|
2 ignored issues
–
show
|
|||
| 248 | * @param $delim |
||
|
1 ignored issue
–
show
|
|||
| 249 | * @return string |
||
|
1 ignored issue
–
show
|
|||
| 250 | */ |
||
| 251 | 1 | private function renderDateRange($differentParts, DateTime $from, DateTime $to, $delim) |
|
|
1 ignored issue
–
show
|
|||
| 252 | { |
||
| 253 | 1 | $ret = ""; |
|
| 254 | 1 | $dateParts_ = []; |
|
| 255 | switch ($differentParts) { |
||
| 256 | 1 | case self::DATE_RANGE_STATE_YEAR: |
|
| 257 | 1 | foreach ($this->dateParts as $key => $datePart) { |
|
| 258 | 1 | if (strpos($key, "year") !== false) { |
|
| 259 | 1 | $ret .= $this->renderOneRangePart($datePart, $from, $to, $delim); |
|
| 260 | } |
||
| 261 | 1 | if (strpos($key, "month") !== false) { |
|
| 262 | 1 | $day = !empty($d = $from->getMonth()) ? $d : ""; |
|
| 263 | 1 | $ret .= $day; |
|
| 264 | } |
||
| 265 | 1 | if (strpos($key, "day") !== false) { |
|
| 266 | 1 | $day = !empty($d = $from->getDay()) ? $datePart->render($from, $this) : ""; |
|
| 267 | 1 | $ret .= $day; |
|
| 268 | } |
||
| 269 | } |
||
| 270 | 1 | break; |
|
| 271 | 1 | case self::DATE_RANGE_STATE_MONTH: |
|
| 272 | /** |
||
|
1 ignored issue
–
show
|
|||
| 273 | * @var string $key |
||
| 274 | * @var DatePart $datePart |
||
| 275 | */ |
||
| 276 | 1 | foreach ($this->dateParts as $key => $datePart) { |
|
| 277 | 1 | if (strpos($key, "year") !== false) { |
|
| 278 | 1 | $ret .= $datePart->render($from, $this); |
|
| 279 | } |
||
| 280 | 1 | if (strpos($key, "month")) { |
|
| 281 | 1 | $ret .= $this->renderOneRangePart($datePart, $from, $to, $delim); |
|
| 282 | } |
||
| 283 | 1 | if (strpos($key, "day") !== false) { |
|
| 284 | 1 | $day = !empty($d = $from->getDay()) ? $datePart->render($from, $this) : ""; |
|
| 285 | 1 | $ret .= $day; |
|
| 286 | } |
||
| 287 | } |
||
| 288 | 1 | break; |
|
| 289 | 1 | case self::DATE_RANGE_STATE_DAY: |
|
| 290 | /** |
||
|
1 ignored issue
–
show
|
|||
| 291 | * @var string $key |
||
| 292 | * @var DatePart $datePart |
||
| 293 | */ |
||
| 294 | 1 | foreach ($this->dateParts as $key => $datePart) { |
|
| 295 | 1 | if (strpos($key, "year") !== false) { |
|
| 296 | 1 | $ret .= $datePart->render($from, $this); |
|
| 297 | } |
||
| 298 | 1 | if (strpos($key, "month") !== false) { |
|
| 299 | 1 | $ret .= $datePart->render($from, $this); |
|
| 300 | } |
||
| 301 | 1 | if (strpos($key, "day")) { |
|
| 302 | 1 | $ret .= $this->renderOneRangePart($datePart, $from, $to, $delim); |
|
| 303 | } |
||
| 304 | } |
||
| 305 | 1 | break; |
|
| 306 | 1 | case self::DATE_RANGE_STATE_YEARMONTHDAY: |
|
| 307 | 1 | $i = 0; |
|
| 308 | 1 | foreach ($this->dateParts as $datePart) { |
|
| 309 | 1 | if ($i === $this->dateParts->count() - 1) { |
|
| 310 | 1 | $ret .= $datePart->renderPrefix(); |
|
| 311 | 1 | $ret .= $datePart->renderWithoutAffixes($from, $this); |
|
| 312 | } else { |
||
| 313 | 1 | $ret .= $datePart->render($from, $this); |
|
| 314 | } |
||
| 315 | 1 | ++$i; |
|
| 316 | } |
||
| 317 | 1 | $ret .= $delim; |
|
| 318 | 1 | $i = 0; |
|
| 319 | 1 | foreach ($this->dateParts as $datePart) { |
|
| 320 | 1 | if ($i == 0) { |
|
| 321 | 1 | $ret .= $datePart->renderWithoutAffixes($to, $this); |
|
| 322 | 1 | $ret .= $datePart->renderSuffix(); |
|
| 323 | } else { |
||
| 324 | 1 | $ret .= $datePart->render($to, $this); |
|
| 325 | } |
||
| 326 | 1 | ++$i; |
|
| 327 | } |
||
| 328 | 1 | break; |
|
| 329 | 1 | case self::DATE_RANGE_STATE_YEARMONTH: |
|
| 330 | 1 | $dp = $this->dateParts->toArray(); |
|
| 331 | 1 | $i = 0; |
|
| 332 | 1 | $dateParts_ = []; |
|
| 333 | 1 | array_walk($dp, function($datePart, $key) use (&$i, &$dateParts_, $differentParts) { |
|
| 334 | 1 | if (strpos($key, "year") !== false || strpos($key, "month") !== false) { |
|
| 335 | 1 | $dateParts_["yearmonth"][] = $datePart; |
|
| 336 | } |
||
| 337 | 1 | if (strpos($key, "day") !== false) { |
|
| 338 | 1 | $dateParts_["day"] = $datePart; |
|
| 339 | } |
||
| 340 | 1 | }); |
|
| 341 | 1 | break; |
|
| 342 | 1 | case self::DATE_RANGE_STATE_YEARDAY: |
|
| 343 | $dp = $this->dateParts->toArray(); |
||
| 344 | $i = 0; |
||
| 345 | $dateParts_ = []; |
||
| 346 | array_walk($dp, function($datePart, $key) use (&$i, &$dateParts_, $differentParts) { |
||
| 347 | if (strpos($key, "year") !== false || strpos($key, "day") !== false) { |
||
| 348 | $dateParts_["yearday"][] = $datePart; |
||
| 349 | } |
||
| 350 | if (strpos($key, "month") !== false) { |
||
| 351 | $dateParts_["month"] = $datePart; |
||
| 352 | } |
||
| 353 | }); |
||
| 354 | break; |
||
| 355 | 1 | case self::DATE_RANGE_STATE_MONTHDAY: |
|
| 356 | 1 | $dp = $this->dateParts->toArray(); |
|
| 357 | 1 | $i = 0; |
|
| 358 | 1 | $dateParts_ = []; |
|
| 359 | 1 | array_walk($dp, function($datePart, $key) use (&$i, &$dateParts_, $differentParts) { |
|
| 360 | //$bit = sprintf("%03d", decbin($differentParts)); |
||
| 361 | 1 | if (strpos($key, "month") !== false || strpos($key, "day") !== false) { |
|
| 362 | 1 | $dateParts_["monthday"][] = $datePart; |
|
| 363 | } |
||
| 364 | 1 | if (strpos($key, "year") !== false) { |
|
| 365 | 1 | $dateParts_["year"] = $datePart; |
|
| 366 | } |
||
| 367 | 1 | }); |
|
| 368 | 1 | break; |
|
| 369 | } |
||
| 370 | switch ($differentParts) { |
||
| 371 | 1 | case self::DATE_RANGE_STATE_YEARMONTH: |
|
| 372 | 1 | case self::DATE_RANGE_STATE_YEARDAY: |
|
| 373 | 1 | case self::DATE_RANGE_STATE_MONTHDAY: |
|
| 374 | /** |
||
|
1 ignored issue
–
show
|
|||
| 375 | * @var $key |
||
| 376 | * @var DatePart $datePart */ |
||
|
1 ignored issue
–
show
|
|||
| 377 | 1 | foreach ($dateParts_ as $key => $datePart) { |
|
| 378 | 1 | if (is_array($datePart)) { |
|
| 379 | |||
| 380 | 1 | $f = $datePart[0]->render($from, $this); |
|
| 381 | 1 | $f .= $datePart[1]->renderPrefix(); |
|
| 382 | 1 | $f .= $datePart[1]->renderWithoutAffixes($from, $this); |
|
| 383 | 1 | $t = $datePart[0]->renderWithoutAffixes($to, $this); |
|
| 384 | 1 | $t .= $datePart[0]->renderSuffix(); |
|
| 385 | 1 | $t .= $datePart[1]->render($to, $this); |
|
| 386 | 1 | $ret .= $f . $delim . $t; |
|
| 387 | } else { |
||
| 388 | 1 | $ret .= $datePart->render($from, $this); |
|
| 389 | } |
||
| 390 | } |
||
| 391 | 1 | break; |
|
| 392 | } |
||
| 393 | 1 | return $ret; |
|
| 394 | } |
||
| 395 | |||
| 396 | /** |
||
|
1 ignored issue
–
show
|
|||
| 397 | * @param $datePart |
||
|
1 ignored issue
–
show
|
|||
| 398 | * @param DateTime $from |
||
|
2 ignored issues
–
show
|
|||
| 399 | * @param DateTime $to |
||
|
2 ignored issues
–
show
|
|||
| 400 | * @param $delim |
||
|
1 ignored issue
–
show
|
|||
| 401 | * @return string |
||
|
1 ignored issue
–
show
|
|||
| 402 | */ |
||
| 403 | 1 | protected function renderOneRangePart(DatePart $datePart, $from, $to, $delim) |
|
| 410 | } |
||
| 411 | |||
| 412 | /** |
||
|
1 ignored issue
–
show
|
|||
| 413 | * @param string $format |
||
|
2 ignored issues
–
show
|
|||
| 414 | * @return bool |
||
|
1 ignored issue
–
show
|
|||
| 415 | */ |
||
| 416 | 15 | private function hasDatePartsFromLocales($format) |
|
|
1 ignored issue
–
show
|
|||
| 417 | { |
||
| 418 | 15 | $dateXml = CiteProc::getContext()->getLocale()->getDateXml(); |
|
| 419 | 15 | return !empty($dateXml[$format]); |
|
| 420 | } |
||
| 421 | |||
| 422 | /** |
||
|
1 ignored issue
–
show
|
|||
| 423 | * @param string $format |
||
|
2 ignored issues
–
show
|
|||
| 424 | * @return array |
||
|
1 ignored issue
–
show
|
|||
| 425 | */ |
||
| 426 | 15 | private function getDatePartsFromLocales($format) |
|
|
1 ignored issue
–
show
|
|||
| 427 | { |
||
| 428 | 15 | $ret = []; |
|
| 429 | // date parts from locales |
||
| 430 | 15 | $dateFromLocale_ = CiteProc::getContext()->getLocale()->getDateXml(); |
|
| 431 | 15 | $dateFromLocale = $dateFromLocale_[$format]; |
|
| 432 | |||
| 433 | // no custom date parts within the date element (this)? |
||
| 434 | 15 | if (!empty($dateFromLocale)) { |
|
| 435 | |||
| 436 | 15 | $dateForm = array_filter(is_array($dateFromLocale) ? $dateFromLocale : [$dateFromLocale], function($element) use ($format) { |
|
| 437 | /** @var \SimpleXMLElement $element */ |
||
|
3 ignored issues
–
show
|
|||
| 438 | 15 | $dateForm = (string) $element->attributes()["form"]; |
|
| 439 | 15 | return $dateForm === $format; |
|
| 440 | 15 | }); |
|
| 441 | |||
| 442 | //has dateForm from locale children (date-part elements)? |
||
| 443 | 15 | $localeDate = array_pop($dateForm); |
|
| 444 | |||
| 445 | 15 | if ($localeDate instanceof \SimpleXMLElement && $localeDate->count() > 0) { |
|
| 446 | 15 | foreach ($localeDate as $child) { |
|
| 447 | 15 | $ret[] = $child; |
|
| 448 | } |
||
| 449 | } |
||
| 450 | } |
||
| 451 | 15 | return $ret; |
|
| 452 | } |
||
| 453 | |||
| 454 | /** |
||
|
1 ignored issue
–
show
|
|||
| 455 | * @return string |
||
| 456 | */ |
||
| 457 | 26 | public function getVariable() |
|
| 458 | { |
||
| 459 | 26 | return $this->variable; |
|
| 460 | } |
||
| 461 | |||
| 462 | /** |
||
|
1 ignored issue
–
show
|
|||
| 463 | * @param $data |
||
|
1 ignored issue
–
show
|
|||
| 464 | * @param $var |
||
|
1 ignored issue
–
show
|
|||
| 465 | * @throws CiteProcException |
||
|
1 ignored issue
–
show
|
|||
| 466 | */ |
||
| 467 | 48 | private function prepareDatePartsInVariable($data, $var) |
|
|
1 ignored issue
–
show
|
|||
| 468 | { |
||
| 469 | 48 | if (!isset($data->{$this->variable}->{'date-parts'}) || empty($data->{$this->variable}->{'date-parts'})) { |
|
| 470 | 4 | if (isset($data->{$this->variable}->raw) && !empty($data->{$this->variable}->raw)) { |
|
| 471 | //try { |
||
| 472 | // try to parse date parts from "raw" attribute |
||
| 473 | 4 | $var->{'date-parts'} = Util\DateHelper::parseDateParts($data->{$this->variable}); |
|
| 474 | //} catch (CiteProcException $e) { |
||
| 475 | // if (!preg_match("/(\p{L}+)\s?([\-\-\&,])\s?(\p{L}+)/u", $data->{$this->variable}->raw)) { |
||
| 476 | // return $this->addAffixes($this->format($this->applyTextCase($data->{$this->variable}->raw))); |
||
| 477 | // } |
||
| 478 | //} |
||
| 479 | } else { |
||
| 480 | throw new CiteProcException("No valid date format"); |
||
| 481 | //return ""; |
||
| 482 | } |
||
| 483 | } |
||
| 484 | 48 | } |
|
| 485 | |||
| 486 | /** |
||
|
1 ignored issue
–
show
|
|||
| 487 | * @param $dateParts |
||
|
1 ignored issue
–
show
|
|||
| 488 | * @param string $form |
||
|
3 ignored issues
–
show
|
|||
| 489 | * @throws \Seboettg\CiteProc\Exception\InvalidStylesheetException |
||
|
1 ignored issue
–
show
|
|||
| 490 | */ |
||
| 491 | 48 | private function prepareDatePartsChildren($dateParts, $form) |
|
| 515 | } |
||
| 516 | } |
||
| 517 | } |
||
| 518 | 48 | } |
|
| 519 | |||
| 520 | |||
| 521 | 1 | private function renderNumeric(DateTime $date) |
|
|
1 ignored issue
–
show
|
|||
| 522 | { |
||
| 523 | 1 | return $date->renderNumeric(); |
|
| 524 | } |
||
| 525 | |||
| 526 | 11 | public function getForm() |
|
| 527 | { |
||
| 528 | 11 | return $this->form; |
|
| 529 | } |
||
| 530 | |||
| 531 | 48 | private function cleanDate($date) |
|
| 538 | } |
||
| 539 | } |