Skip to content

Commit 6ad41ef

Browse files
Ant Brownxurizaemon
Ant Brown
authored andcommitted
#139: Check YEAR_BASE key exists before using
1 parent a18c741 commit 6ad41ef

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

src/Plugin/Field/FieldFormatter/EDTFFormatter.php

+19-17
Original file line numberDiff line numberDiff line change
@@ -241,24 +241,26 @@ protected function formatDate($edtf_text) {
241241
];
242242
$unspecified_count = 0;
243243

244-
if (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XXXX') !== FALSE) {
245-
$unspecified['fullyear'] = TRUE;
246-
$unspecified_count++;
247-
}
248-
elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XXX') !== FALSE) {
249-
$unspecified['century'] = TRUE;
250-
$unspecified_count++;
251-
}
252-
elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XX') !== FALSE) {
253-
$unspecified['decade'] = TRUE;
254-
$unspecified_count++;
255-
}
256-
elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'X') !== FALSE) {
257-
$unspecified['year'] = TRUE;
258-
$unspecified_count++;
259-
}
244+
if (array_key_exists(EDTFUtils::YEAR_BASE, $parsed_date)) {
245+
if (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XXXX') !== FALSE) {
246+
$unspecified['fullyear'] = TRUE;
247+
$unspecified_count++;
248+
}
249+
elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XXX') !== FALSE) {
250+
$unspecified['century'] = TRUE;
251+
$unspecified_count++;
252+
}
253+
elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'XX') !== FALSE) {
254+
$unspecified['decade'] = TRUE;
255+
$unspecified_count++;
256+
}
257+
elseif (strpos($parsed_date[EDTFUtils::YEAR_BASE], 'X') !== FALSE) {
258+
$unspecified['year'] = TRUE;
259+
$unspecified_count++;
260+
}
260261

261-
$year = $parsed_date[EDTFUtils::YEAR_BASE];
262+
$year = $parsed_date[EDTFUtils::YEAR_BASE];
263+
}
262264

263265
if (array_key_exists(EDTFUtils::MONTH, $parsed_date)) {
264266
if (strpos($parsed_date[EDTFUtils::MONTH], 'X') !== FALSE) {

0 commit comments

Comments
 (0)