From 6fc6307f6ebd4002b24b7fe8b48e97bcbf8f9668 Mon Sep 17 00:00:00 2001 From: Dendy Faist Date: Thu, 6 Feb 2025 19:10:08 +0900 Subject: [PATCH] chore: Move vocabDef parsing from Note to Term --- src/Entity/Note.php | 19 ++----------------- src/Entity/Term.php | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/Entity/Note.php b/src/Entity/Note.php index be7bde6..bd44a8f 100644 --- a/src/Entity/Note.php +++ b/src/Entity/Note.php @@ -67,7 +67,7 @@ class Note $note->mediaInfo = $note->parseMediaInfo($note->fields['Notes']); // Set VocabKanji field - $terms = self::parseVocabDef($note->fields['VocabDef']); + $terms = Term::fromVocabDef($note->fields['VocabDef']); if (null !== $terms) { $note->terms = $terms; } else { @@ -97,7 +97,7 @@ class Note . $separator . $note->fields['VocabDef']; - $terms = self::parseVocabDef($note->fields['VocabDef']); + $terms = Term::fromVocabDef($note->fields['VocabDef']); $note->terms = $terms ?? dd($note->fields['VocabDef']); } @@ -161,21 +161,6 @@ class Note ]; } - public static function parseVocabDef(string $vocabDef): ?array - { - if (mb_trim($vocabDef) === '') return null; - - $terms = []; - foreach (preg_split('|
|', $vocabDef) as $line) { - $term = Term::fromVocabDefLine(strip_tags($line)); - // Error parsing term, can't parse using vocabDef - if (null === $term) return null; - $terms[] = $term; - }; - - return $terms; - } - public function parseMediaInfo(string $notes): ?array { $matches = null; diff --git a/src/Entity/Term.php b/src/Entity/Term.php index 78750ff..df8e70d 100644 --- a/src/Entity/Term.php +++ b/src/Entity/Term.php @@ -49,7 +49,7 @@ class Term return $ret; } - public static function fromVocabDefLine(string $vocabDefLine): ?Term + private static function fromVocabDefLine(string $vocabDefLine): ?Term { $term = new Term(); @@ -126,4 +126,19 @@ class Term dd("Unexpected error, couldn't parse definition line", $vocabDefLine); } + + public static function fromVocabDef(string $vocabDef): ?array + { + if (mb_trim($vocabDef) === '') return null; + + $terms = []; + foreach (preg_split('|
|', $vocabDef) as $line) { + $term = self::fromVocabDefLine(strip_tags($line)); + // Error parsing term, can't parse using vocabDef + if (null === $term) return null; + $terms[] = $term; + }; + + return $terms; + } }