Skip to content

Commit bb16849

Browse files
committed
#51: Removed union types in method parameters (temporarily for PHP 7.4 support) and replaced them with corresponding type check; added tests
1 parent 0a54f93 commit bb16849

File tree

14 files changed

+74
-13
lines changed

14 files changed

+74
-13
lines changed

src/Endpoints/Block.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,12 @@ public function children(): BlockCollection
7878
* @return FiveamCode\LaravelNotionApi\Entities\Blocks\Block
7979
* @throws HandlingException
8080
*/
81-
public function append(array|BlockEntity $appendices): BlockEntity
81+
public function append($appendices): BlockEntity
8282
{
83+
if(!is_array($appendices) && !$appendices instanceof BlockEntity) {
84+
throw new HandlingException('$appendices must be an array or instance of BlockEntity');
85+
}
86+
8387
if (!is_array($appendices)) {
8488
$appendices = [$appendices];
8589
}

src/Entities/Blocks/Block.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,10 @@ private static function mapTypeToClass(string $type): string
224224
return Block::class;
225225
}
226226
}
227+
228+
protected static function assertValidTextContent($textContent) {
229+
if(!is_array($textContent) && !is_string($textContent)) {
230+
throw new HandlingException('$textContent content must be a string.');
231+
}
232+
}
227233
}

src/Entities/Blocks/BulletedListItem.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
class BulletedListItem extends TextBlock
1010
{
11-
public static function create(array|string $textContent): BulletedListItem
11+
public static function create($textContent): BulletedListItem
1212
{
13+
self::assertValidTextContent($textContent);
14+
1315
$bulletedListItem = new BulletedListItem();
1416
TextBlock::createTextBlock($bulletedListItem, $textContent);
1517
return $bulletedListItem;

src/Entities/Blocks/HeadingOne.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
class HeadingOne extends TextBlock
1010
{
11-
public static function create(array|string $textContent): HeadingOne
11+
public static function create($textContent): HeadingOne
1212
{
13+
self::assertValidTextContent($textContent);
14+
1315
$headingOne = new HeadingOne();
1416
TextBlock::createTextBlock($headingOne, $textContent);
1517
return $headingOne;

src/Entities/Blocks/HeadingThree.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
class HeadingThree extends TextBlock
1010
{
11-
public static function create(array|string $textContent): HeadingThree
11+
public static function create($textContent): HeadingThree
1212
{
13+
self::assertValidTextContent($textContent);
14+
1315
$headingThree = new HeadingThree();
1416
HeadingThree::createTextBlock($headingThree, $textContent);
1517
return $headingThree;

src/Entities/Blocks/HeadingTwo.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
class HeadingTwo extends TextBlock
1010
{
11-
public static function create(array|string $textContent): HeadingTwo
11+
public static function create($textContent): HeadingTwo
1212
{
13+
self::assertValidTextContent($textContent);
14+
1315
$headingTwo = new HeadingTwo();
1416
HeadingTwo::createTextBlock($headingTwo, $textContent);
1517
return $headingTwo;

src/Entities/Blocks/NumberedListItem.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
class NumberedListItem extends TextBlock
1010
{
11-
public static function create(array|string $textContent): NumberedListItem
11+
public static function create($textContent): NumberedListItem
1212
{
13+
self::assertValidTextContent($textContent);
14+
1315
$numberedListItem = new NumberedListItem();
1416
TextBlock::createTextBlock($numberedListItem, $textContent);
1517
return $numberedListItem;

src/Entities/Blocks/Paragraph.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
class Paragraph extends TextBlock
1010
{
11-
public static function create(array|string $textContent): Paragraph
11+
public static function create($textContent): Paragraph
1212
{
13+
self::assertValidTextContent($textContent);
14+
1315
$paragraph = new Paragraph();
1416
TextBlock::createTextBlock($paragraph, $textContent);
1517
return $paragraph;

src/Entities/Blocks/TextBlock.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
*/
1212
class TextBlock extends Block implements Modifiable
1313
{
14-
protected static function createTextBlock(TextBlock $textBlock, array|string $textContent): TextBlock
14+
protected static function createTextBlock(TextBlock $textBlock, $textContent): TextBlock
1515
{
16+
self::assertValidTextContent($textContent);
17+
1618
if (is_string($textContent)) {
1719
$textContent = [$textContent];
1820
}

src/Entities/Blocks/ToDo.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
*/
99
class ToDo extends TextBlock
1010
{
11-
public static function create(array|string $textContent): ToDo
11+
public static function create($textContent): ToDo
1212
{
13+
self::assertValidTextContent($textContent);
14+
1315
$toDo = new ToDo();
1416
TextBlock::createTextBlock($toDo, $textContent);
1517
return $toDo;

0 commit comments

Comments
 (0)