Skip to content

Commit 84c87c3

Browse files
committed
Remove JsonSerializable interface
1 parent de59724 commit 84c87c3

File tree

9 files changed

+4
-155
lines changed

9 files changed

+4
-155
lines changed

README.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,14 +140,10 @@ $topLevelDomains->getIANADomain('com');
140140
To instantiate each domain resolver you can use the following named constructor:
141141

142142
- `fromString`: instantiate the resolver from a inline string representing the data source;
143-
- `fromJsonString`: instantiate the resolver from a json string representing the data source;
144143
- `fromPath`: instantiate the resolver from a local path or online URL by relying on `fopen`;
145144

146145
**If the instantiation does not work an exception will be thrown.**
147146

148-
Once instantiated, you can always convert the data source in a json encoded string as both
149-
resolver exposes the `JsonSerialize` method.
150-
151147
**WARNING:**
152148

153149
**You should never resolve domain name this way in production, without, at

src/PublicSuffixList.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,8 @@
44

55
namespace Pdp;
66

7-
use JsonSerializable;
8-
9-
interface PublicSuffixList extends DomainNameResolver, JsonSerializable
7+
interface PublicSuffixList extends DomainNameResolver
108
{
11-
/**
12-
* Returns an array representation of the Public Suffix List Rules JSON serializable.
13-
*
14-
* @return array<string, array<array>>
15-
*/
16-
public function jsonSerialize(): array;
17-
189
/**
1910
* Returns PSL info for a given domain against the PSL rules for cookie domain detection.
2011
*

src/Storage/ResourceUri.php renamed to src/ResourceUri.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Pdp\Storage;
5+
namespace Pdp;
66

77
interface ResourceUri
88
{

src/Rules.php

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Pdp;
66

7-
use JsonException;
87
use SplTempFileObject;
98
use TypeError;
109
use function array_pop;
@@ -13,16 +12,13 @@
1312
use function fclose;
1413
use function fopen;
1514
use function gettype;
16-
use function is_array;
1715
use function is_object;
1816
use function is_string;
19-
use function json_decode;
2017
use function method_exists;
2118
use function preg_match;
2219
use function stream_get_contents;
2320
use function strpos;
2421
use function substr;
25-
use const JSON_THROW_ON_ERROR;
2622

2723
final class Rules implements PublicSuffixList
2824
{
@@ -190,21 +186,6 @@ private static function addRule(array $list, array $ruleParts): array
190186
return $list;
191187
}
192188

193-
public static function fromJsonString(string $jsonString): self
194-
{
195-
try {
196-
$data = json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR);
197-
} catch (JsonException $exception) {
198-
throw UnableToLoadPublicSuffixList::dueToInvalidJson($exception);
199-
}
200-
201-
if (!is_array($data[self::ICANN_DOMAINS]) || !is_array($data[self::PRIVATE_DOMAINS])) {
202-
throw UnableToLoadPublicSuffixList::dueToCorruptedSection();
203-
}
204-
205-
return new self($data);
206-
}
207-
208189
/**
209190
* @param array{rules:array{ICANN_DOMAINS:array,PRIVATE_DOMAINS:array}} $properties
210191
*/
@@ -213,14 +194,6 @@ public static function __set_state(array $properties): self
213194
return new self($properties['rules']);
214195
}
215196

216-
/**
217-
* @return array<string, array<array>>
218-
*/
219-
public function jsonSerialize(): array
220-
{
221-
return $this->rules;
222-
}
223-
224197
/**
225198
* @param mixed $host a type that supports instantiating a Domain from.
226199
*/

src/RulesTest.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -61,40 +61,6 @@ public function testFromStringThrowsOnTypeError(): void
6161
Rules::fromString(new DateTimeImmutable());
6262
}
6363

64-
/**
65-
* @covers ::jsonSerialize
66-
* @covers ::fromJsonString
67-
*/
68-
public function testJsonMethods(): void
69-
{
70-
/** @var string $data */
71-
$data = json_encode(self::$rules);
72-
73-
self::assertEquals(self::$rules, Rules::fromJsonString($data));
74-
}
75-
76-
/**
77-
* @covers ::fromJsonString
78-
* @covers \Pdp\UnableToLoadPublicSuffixList
79-
*/
80-
public function testJsonStringFailsWithInvalidJson(): void
81-
{
82-
$this->expectException(UnableToLoadPublicSuffixList::class);
83-
84-
Rules::fromJsonString('');
85-
}
86-
87-
/**
88-
* @covers ::fromJsonString
89-
* @covers \Pdp\UnableToLoadPublicSuffixList
90-
*/
91-
public function testJsonStringFailsWithMissingIndexesCollection(): void
92-
{
93-
$this->expectException(UnableToLoadPublicSuffixList::class);
94-
95-
Rules::fromJsonString('{"ICANN_DOMAINS":"foo","PRIVATE_DOMAINS":"bar"}');
96-
}
97-
9864
public function testDomainInternalPhpMethod(): void
9965
{
10066
$generateRules = eval('return '.var_export(self::$rules, true).';');

src/Storage/PsrStorageFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Pdp\Storage;
66

7+
use Pdp\ResourceUri;
78
use Psr\Http\Client\ClientInterface;
89
use Psr\Http\Message\RequestFactoryInterface;
910
use Psr\SimpleCache\CacheInterface;

src/TopLevelDomainList.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@
88
use DateTimeImmutable;
99
use Iterator;
1010
use IteratorAggregate;
11-
use JsonSerializable;
1211

1312
/**
1413
* @extends IteratorAggregate<string>
1514
*/
16-
interface TopLevelDomainList extends Countable, DomainNameResolver, IteratorAggregate, JsonSerializable
15+
interface TopLevelDomainList extends Countable, DomainNameResolver, IteratorAggregate
1716
{
1817
/**
1918
* Returns the Version ID.
@@ -40,13 +39,6 @@ public function isEmpty(): bool;
4039
*/
4140
public function getIterator(): Iterator;
4241

43-
/**
44-
* Returns an array representation of the list.
45-
*
46-
* @return array{version:string, records:array<string>, lastUpdated:string}
47-
*/
48-
public function jsonSerialize(): array;
49-
5042
/**
5143
* Returns PSL info for a given domain against the PSL rules for ICANN domain detection.
5244
*

src/TopLevelDomains.php

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,21 @@
77
use DateTimeImmutable;
88
use DateTimeInterface;
99
use Iterator;
10-
use JsonException;
1110
use SplTempFileObject;
1211
use TypeError;
1312
use function array_flip;
14-
use function array_keys;
1513
use function count;
1614
use function fclose;
1715
use function fopen;
1816
use function gettype;
1917
use function in_array;
2018
use function is_object;
2119
use function is_string;
22-
use function json_decode;
2320
use function method_exists;
2421
use function preg_match;
2522
use function stream_get_contents;
2623
use function strpos;
2724
use function trim;
28-
use const JSON_THROW_ON_ERROR;
2925

3026
final class TopLevelDomains implements TopLevelDomainList
3127
{
@@ -185,24 +181,6 @@ private static function extractRootZone(string $content): string
185181
return $tld->toString();
186182
}
187183

188-
public static function fromJsonString(string $jsonString): self
189-
{
190-
try {
191-
$data = json_decode($jsonString, true, 512, JSON_THROW_ON_ERROR);
192-
} catch (JsonException $exception) {
193-
throw UnableToLoadTopLevelDomainList::dueToInvalidJson($exception);
194-
}
195-
196-
if (!isset($data['records'], $data['version'], $data['lastUpdated'])) {
197-
throw UnableToLoadTopLevelDomainList::dueToInvalidHashMap();
198-
}
199-
200-
/** @var DateTimeImmutable $lastUpdated */
201-
$lastUpdated = DateTimeImmutable::createFromFormat(DateTimeInterface::ATOM, $data['lastUpdated']);
202-
203-
return new self(array_flip($data['records']), $data['version'], $lastUpdated);
204-
}
205-
206184
/**
207185
* @param array{records:array<string, int>, version:string, lastUpdated:DateTimeImmutable} $properties
208186
*/
@@ -241,18 +219,6 @@ public function getIterator(): Iterator
241219
}
242220
}
243221

244-
/**
245-
* @return array{version:string, records:array<string>, lastUpdated:string}
246-
*/
247-
public function jsonSerialize(): array
248-
{
249-
return [
250-
'version' => $this->version,
251-
'records' => array_keys($this->records),
252-
'lastUpdated' => $this->lastUpdated->format(DateTimeInterface::ATOM),
253-
];
254-
}
255-
256222
/**
257223
* @param mixed $host a type that supports instantiating a Domain from.
258224
*/

src/TopLevelDomainsTest.php

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use PHPUnit\Framework\TestCase;
1010
use TypeError;
1111
use function dirname;
12-
use function json_encode;
1312

1413
/**
1514
* @coversDefaultClass \Pdp\TopLevelDomains
@@ -145,40 +144,6 @@ public function testSetState(): void
145144
self::assertEquals(self::$topLevelDomains, $topLevelDomains);
146145
}
147146

148-
/**
149-
* @covers ::jsonSerialize
150-
* @covers ::fromJsonString
151-
*/
152-
public function testJsonMethods(): void
153-
{
154-
/** @var string $data */
155-
$data = json_encode(self::$topLevelDomains);
156-
157-
self::assertEquals(self::$topLevelDomains, TopLevelDomains::fromJsonString($data));
158-
}
159-
160-
/**
161-
* @covers ::fromJsonString
162-
* @covers \Pdp\UnableToLoadTopLevelDomainList
163-
*/
164-
public function testJsonStringFailsWithInvalidJson(): void
165-
{
166-
$this->expectException(UnableToLoadTopLevelDomainList::class);
167-
168-
TopLevelDomains::fromJsonString('');
169-
}
170-
171-
/**
172-
* @covers ::fromJsonString
173-
* @covers \Pdp\UnableToLoadTopLevelDomainList
174-
*/
175-
public function testJsonStringFailsWithMissingIndexes(): void
176-
{
177-
$this->expectException(UnableToLoadTopLevelDomainList::class);
178-
179-
TopLevelDomains::fromJsonString('{"foo":"bar"}');
180-
}
181-
182147
public function testGetterProperties(): void
183148
{
184149
$topLevelDomains = TopLevelDomains::fromPath(dirname(__DIR__).'/test_data/root_zones.dat');
@@ -190,7 +155,6 @@ public function testGetterProperties(): void
190155
$topLevelDomains->lastUpdated()
191156
);
192157
self::assertFalse($topLevelDomains->isEmpty());
193-
self::assertArrayHasKey('lastUpdated', $topLevelDomains->jsonSerialize());
194158
}
195159

196160
public function testIterator(): void

0 commit comments

Comments
 (0)