diff --git a/src/Entity/Note.php b/src/Entity/Note.php index 32bfbf0..6d8c407 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -70,7 +70,7 @@ class Note $terms = Term::fromNoteFields($note->fields); // If not defined, find them from the highlighted parts in the sentence - if (empty($note->terms)) { + if (empty($terms)) { // 1. Get all spans in the text preg_match_all( self::HIGHLIGHT_PATTERN, @@ -90,6 +90,8 @@ class Note } } + if (empty($terms)) dd($note); + // Set to null whatever is null $readings = array_map( fn($x) => in_array($x, ['_', '_', '']) ? null : $x, diff --git a/src/Entity/Term.php b/src/Entity/Term.php index 36a6374..486c30b 100644 --- a/src/Entity/Term.php +++ b/src/Entity/Term.php @@ -139,7 +139,7 @@ class Term return Term::fromVocabDefLine($kanji . $separator . $def); } - public static function fromNoteFields(array $fields): ?array + public static function fromNoteFields(array $fields): array { // -------------------- Trying to extract it with the modern syntax --- // 言葉: word @@ -159,7 +159,7 @@ class Term $kanjis = explode('|', $fields['VocabKanji']); $defs = explode('|', $fields['VocabDef']); // Number of legacy definitions is different from number of kanji - if (count($kanjis) !== count($defs)) return null; + if (count($kanjis) !== count($defs)) return []; $terms = []; foreach (array_combine($kanjis, $defs) as $kanji => $def) { @@ -167,6 +167,6 @@ class Term } // Search for nulls, if found, it's owari da - return in_array(null, $terms, true) ? null : $terms; + return in_array(null, $terms, true) ? [] : $terms; } }