4
0

update 2023-07-13 14:31:29

This commit is contained in:
Robot 2023-07-13 14:31:29 +02:00
parent 06bf530db8
commit 797c64504c
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
3 changed files with 87 additions and 2 deletions

View File

@ -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
```

View File

@ -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;
}
}

View File

@ -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;
}