Skip to content

Commit 157ce84

Browse files
committed
[minor] locally cache decoded json
1 parent c860ff9 commit 157ce84

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/Browser/Json.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ final class Json
1616
{
1717
private string $source;
1818

19+
/** @var mixed */
20+
private $decoded;
21+
1922
public function __construct(string $source)
2023
{
2124
$this->source = $source;
@@ -126,11 +129,7 @@ public function search(string $selector)
126129
*/
127130
public function decoded()
128131
{
129-
if (empty($this->source)) {
130-
return null;
131-
}
132-
133-
return \json_decode($this->source, true, 512, \JSON_THROW_ON_ERROR);
132+
return $this->decoded ??= empty($this->source) ? null : \json_decode($this->source, true, 512, \JSON_THROW_ON_ERROR);
134133
}
135134

136135
/**

0 commit comments

Comments
 (0)