Skip to content

Commit a4deb87

Browse files
committed
refactor!: Throw on JSON failures
1 parent 70fc06a commit a4deb87

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/MicrodataParser.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ public function __construct(MicrodataDOMDocument $dom, callable $absoluteUriHand
3838
/**
3939
* Extracts and converts microdata to associative array.
4040
*
41+
* @throws \JsonException
42+
*
4143
* @return mixed[]
4244
*/
4345
public function toArray(): array
4446
{
4547
// Somewhat hacky way to convert deep objects
46-
return json_decode(json_encode($this->extractMicrodata()), true);
48+
return json_decode(json_encode($this->extractMicrodata(), \JSON_THROW_ON_ERROR), true, flags: \JSON_THROW_ON_ERROR);
4749
}
4850

4951
/**
@@ -55,15 +57,15 @@ public function toObject(): stdClass
5557
}
5658

5759
/**
58-
* Extracts and converts microdata to json using \json_encode().
60+
* Extracts and converts microdata to JSON using \json_encode().
5961
*
60-
* @return false|string
62+
* @see json_encode() to description of parameters
6163
*
62-
* @see \json_encode() to description of parameters and return values
64+
* @throws \JsonException
6365
*/
64-
public function toJSON(int $options = 0, int $depth = 512): bool|string
66+
public function toJSON(int $options = 0, int $depth = 512): string
6567
{
66-
return json_encode($this->extractMicrodata(), $options, $depth);
68+
return json_encode($this->extractMicrodata(), $options | \JSON_THROW_ON_ERROR, $depth);
6769
}
6870

6971
protected function extractMicrodata(): stdClass

0 commit comments

Comments
 (0)