Skip to content

Commit efaf27c

Browse files
committed
Add functions for "whole bible"
1 parent 37851d0 commit efaf27c

File tree

3 files changed

+74
-4
lines changed

3 files changed

+74
-4
lines changed

src/ScripturNum.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,4 +1338,21 @@ public function toSqlInclusive(string $columnRef): string
13381338

13391339
return "( " . implode(" AND ", $r) . " )";
13401340
}
1341+
1342+
1343+
/**
1344+
* Get a ScripturNumArray representing the whole Bible.
1345+
*
1346+
* @return ScripturNumArray
1347+
* @throws ScripturNumException -- would only be thrown if there's something peculiar with a custom Bible class.
1348+
* @since 2.1.0
1349+
*/
1350+
public static function getWholeBible(): ScripturNumArray
1351+
{
1352+
$sna = new ScripturNumArray();
1353+
foreach (ScripturNum::getBookNames() as $bookNames) {
1354+
$sna[] = new ScripturNum($bookNames[0]);
1355+
}
1356+
return $sna;
1357+
}
13411358
}

src/ScripturNumArray.php

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ class ScripturNumArray implements ArrayAccess, Iterator, Countable
2424
protected $hasMultiplePassagesFromAChapter = false;
2525

2626

27+
/**
28+
* Constructor
29+
*
30+
* @param array $initialValues An array of initial values to add to the container. These can be ScripturNum objects
31+
* or strings/integers that can be parsed into ScripturNum objects.
32+
*/
2733
public function __construct($initialValues = [])
2834
{
2935
foreach ($initialValues as $k => $i) {
@@ -61,7 +67,8 @@ protected function sort()
6167

6268
/**
6369
* @return void
64-
*/
70+
* @noinspection PhpDocMissingThrowsInspection
71+
*/
6572
protected function combineAdjacents()
6673
{
6774
$prev = null;
@@ -103,15 +110,15 @@ protected function sortAndCombineIfNeeded()
103110
}
104111

105112
/**
106-
* Whether a offset exists
113+
* Whether an offset exists
107114
* @link https://php.net/manual/en/arrayaccess.offsetexists.php
108115
*
109116
* @param mixed $offset
110117
* An offset to check for.
111118
*
112119
* @return bool true on success or false on failure.
113120
*
114-
* The return value will be casted to boolean if non-boolean was returned.
121+
* The return value will be cast to boolean if non-boolean was returned.
115122
*/
116123
public function offsetExists($offset): bool
117124
{
@@ -220,7 +227,7 @@ public function key()
220227
/**
221228
* Checks if current position is valid
222229
* @link https://php.net/manual/en/iterator.valid.php
223-
* @return bool The return value will be casted to boolean and then evaluated.
230+
* @return bool The return value will be cast to boolean and then evaluated.
224231
* Returns true on success or false on failure.
225232
*/
226233
public function valid(): bool
@@ -260,6 +267,15 @@ public function count(): int
260267
return count($this->container);
261268
}
262269

270+
/**
271+
* Subtract a passage from this array of passages.
272+
*
273+
* @since 2.1.0
274+
*
275+
* @param ScripturNum $other
276+
* @return ScripturNumArray
277+
* @throws ScripturNumException
278+
*/
263279
public function remove(ScripturNum $other): ScripturNumArray
264280
{
265281
$result = new ScripturNumArray();
@@ -278,6 +294,15 @@ public function remove(ScripturNum $other): ScripturNumArray
278294
return $result;
279295
}
280296

297+
/**
298+
* Subtract all passages in another ScripturNumArray from this array of passages.
299+
*
300+
* @since 2.1.0
301+
*
302+
* @param ScripturNumArray $others
303+
* @return ScripturNumArray
304+
* @throws ScripturNumException
305+
*/
281306
public function removeAll(ScripturNumArray $others): ScripturNumArray
282307
{
283308
$this->sortAndCombineIfNeeded();

tests/ScripturNumPublicTests.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,4 +1082,32 @@ public function test_remove_overlapStart()
10821082
$this->assertCount(1, $result);
10831083
$this->assertEquals("Exodus 21", (string)$result);
10841084
}
1085+
1086+
/**
1087+
* @throws ScripturNumException
1088+
*/
1089+
public function test_getWholeBible()
1090+
{
1091+
$s = ScripturNum::getWholeBible();
1092+
$this->assertCount(66, $s);
1093+
$this->assertEquals("Revelation", (string)$s[65]);
1094+
}
1095+
1096+
public function test_wholeBibleMinusBook()
1097+
{
1098+
$whole = ScripturNum::getWholeBible();
1099+
$toRemove = new ScripturNum("Exodus");
1100+
$result = $whole->remove($toRemove);
1101+
$this->assertCount(65, $result);
1102+
$this->assertEquals("Leviticus", (string)$result[1]);
1103+
}
1104+
1105+
public function test_wholeBibleMinusChapter()
1106+
{
1107+
$whole = ScripturNum::getWholeBible();
1108+
$toRemove = new ScripturNum("Exodus 1");
1109+
$result = $whole->remove($toRemove);
1110+
$this->assertCount(66, $result);
1111+
$this->assertEquals("Exodus 2-40", (string)$result[1]);
1112+
}
10851113
}

0 commit comments

Comments
 (0)