From 797c64504c1ce3057871615304ee00ff6806ee79 Mon Sep 17 00:00:00 2001 From: aB0t Date: Thu, 13 Jul 2023 14:31:29 +0200 Subject: [PATCH] update 2023-07-13 14:31:29 --- .../README.md | 9 +++++ .../code.php | 40 ++++++++++++++++++- .../code.power | 40 ++++++++++++++++++- 3 files changed, 87 insertions(+), 2 deletions(-) diff --git a/src/4a4c786d-51f4-421a-aa61-262dfd071880/README.md b/src/4a4c786d-51f4-421a-aa61-262dfd071880/README.md index 3fa2e11..f132110 100644 --- a/src/4a4c786d-51f4-421a-aa61-262dfd071880/README.md +++ b/src/4a4c786d-51f4-421a-aa61-262dfd071880/README.md @@ -17,6 +17,7 @@ class Chapter << (F,LightGreen) >> #Green { # StringHelper $stringHelper # array $chapters # array $validVerses + # array $sequential + __construct(Load $load, Config $config, ...) + getBookName(?string $abbreviation = null, ?int $book = null, ...) : string + getChapterNumber(?string $abbreviation = null, ?int $book = null, ...) : string @@ -45,6 +46,7 @@ class Chapter << (F,LightGreen) >> #Green { - wordNumberArrayToString(array $wordNumberArray) : string - buildWordArray(array $verses, array $words) : array - wordArrayToString(array $wordArray) : string + - isSequential(array $arr) : bool } note right of Chapter::__construct @@ -327,6 +329,13 @@ note left of Chapter::wordArrayToString since: 2.0.1 return: string end note + +note right of Chapter::isSequential + Check if an array values is sequential. + + since: 2.0.1 + return: bool +end note @enduml ``` diff --git a/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php b/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php index 5eafb36..b8589f8 100644 --- a/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php +++ b/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php @@ -73,6 +73,14 @@ final class Chapter */ protected array $validVerses = []; + /** + * The check if words are sequential + * + * @var array + * @since 2.0.1 + */ + protected array $sequential = []; + /** * Constructor * @@ -704,8 +712,15 @@ final class Chapter * @return bool True on success * @since 2.0.1 */ - private function isValidWordNumber($verseNumber, $wordNumber): bool + private function isValidWordNumber(int $verseNumber, int $wordNumber): bool { + // we add the next word number to check sequential selection of words + $this->sequential[$verseNumber][$wordNumber] = $wordNumber; + if (count($this->sequential[$verseNumber]) > 1 && !$this->isSequential($this->sequential[$verseNumber])) + { + return false; + } + $verse_text = $this->get()->verse_text_array ?? null; if (($verse_text = $this->processVersesArray()) === null) @@ -856,6 +871,7 @@ final class Chapter { $array = array_map('trim', explode('-', $str)); sort($array); + return $array; } else @@ -969,6 +985,28 @@ final class Chapter } return implode(' ', $word_number); + } + + /** + * Check if an array values is sequential. + * + * @param array $arr The number array. + * + * @return bool true if sequential + * @since 2.0.1 + */ + private function isSequential(array $arr): bool + { + $arr = array_values($arr); // Reset keys + for ($i = 0, $len = count($arr) - 1; $i < $len; $i++) + { + if ($arr[$i] + 1 !== $arr[$i + 1]) + { + return false; + } + } + + return true; } } diff --git a/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.power b/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.power index ecb938d..6ecf03d 100644 --- a/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.power +++ b/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.power @@ -46,6 +46,14 @@ */ protected array $validVerses = []; + /** + * The check if words are sequential + * + * @var array + * @since 2.0.1 + */ + protected array $sequential = []; + /** * Constructor * @@ -677,8 +685,15 @@ * @return bool True on success * @since 2.0.1 */ - private function isValidWordNumber($verseNumber, $wordNumber): bool + private function isValidWordNumber(int $verseNumber, int $wordNumber): bool { + // we add the next word number to check sequential selection of words + $this->sequential[$verseNumber][$wordNumber] = $wordNumber; + if (count($this->sequential[$verseNumber]) > 1 && !$this->isSequential($this->sequential[$verseNumber])) + { + return false; + } + $verse_text = $this->get()->verse_text_array ?? null; if (($verse_text = $this->processVersesArray()) === null) @@ -829,6 +844,7 @@ { $array = array_map('trim', explode('-', $str)); sort($array); + return $array; } else @@ -942,4 +958,26 @@ } return implode(' ', $word_number); + } + + /** + * Check if an array values is sequential. + * + * @param array $arr The number array. + * + * @return bool true if sequential + * @since 2.0.1 + */ + private function isSequential(array $arr): bool + { + $arr = array_values($arr); // Reset keys + for ($i = 0, $len = count($arr) - 1; $i < $len; $i++) + { + if ($arr[$i] + 1 !== $arr[$i + 1]) + { + return false; + } + } + + return true; } \ No newline at end of file