Skip to content

Commit d8b196b

Browse files
authored
Merge pull request #314 from jeremykendall/develop
Release 6.1.0
2 parents 9b1595f + 8607e36 commit d8b196b

26 files changed

+366
-158
lines changed

.gitattributes

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
/.github export-ignore
66
/.gitignore export-ignore
77
/.php_cs export-ignore
8-
/phpstan.neon export-ignore
9-
/.travis.yml export-ignore
10-
/README.md export-ignore
8+
/phpstan.neon export-ignore
119
/phpunit.xml.dist export-ignore
10+
/psalm.xml export-ignore
1211
/CHANGELOG.md export-ignore
12+
/UPGRADING.md export-ignore
13+
/README.md export-ignore
1314
/**/*Test.php export-ignore

.github/workflows/build.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ jobs:
2323
- run: composer update --no-progress ${{ matrix.composer-flags }}
2424
- run: composer phpunit
2525
- run: composer phpstan
26-
if: ${{ matrix.php == '7.4' }}
26+
if: ${{ matrix.php == '8.0' }}
2727
- run: composer psalm
28-
if: ${{ matrix.php == '7.4' }}
28+
if: ${{ matrix.php == '8.0' }}
2929
- run: composer phpcs
30-
if: ${{ matrix.php == '7.4' }}
30+
if: ${{ matrix.php == '8.0' }}

.php_cs renamed to .php-cs-fixer.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
->in(__DIR__.'/src')
55
;
66

7-
return PhpCsFixer\Config::create()
7+
$config = new PhpCsFixer\Config();
8+
9+
return $config
810
->setRules([
911
'@PSR2' => true,
1012
'array_syntax' => ['syntax' => 'short'],
@@ -16,24 +18,22 @@
1618
'no_leading_import_slash' => true,
1719
'no_superfluous_phpdoc_tags' => true,
1820
'no_trailing_comma_in_singleline_array' => true,
19-
'no_superfluous_phpdoc_tags' => true,
2021
'no_unused_imports' => true,
2122
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
2223
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
2324
'phpdoc_align' => true,
2425
'phpdoc_no_empty_return' => true,
2526
'phpdoc_order' => true,
2627
'phpdoc_scalar' => true,
27-
'phpdoc_to_comment' => true,
28+
'phpdoc_to_comment' => false,
2829
'phpdoc_summary' => true,
29-
'psr0' => true,
30-
'psr4' => true,
30+
'psr_autoloading' => true,
3131
'return_type_declaration' => ['space_before' => 'none'],
3232
'single_blank_line_before_namespace' => true,
3333
'single_quote' => true,
3434
'space_after_semicolon' => true,
3535
'ternary_operator_spaces' => true,
36-
'trailing_comma_in_multiline_array' => true,
36+
'trailing_comma_in_multiline' => true,
3737
'trim_array_spaces' => true,
3838
'whitespace_after_comma_in_array' => true,
3939
'yoda_style' => true,

CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,29 @@
22

33
All Notable changes to `PHP Domain Parser` starting from the **5.x** series will be documented in this file
44

5+
## 6.1.0 - 2021-06-19
6+
7+
### Added
8+
9+
- `TimeToLive::until`
10+
- `TimeToLive::fromDurationString`
11+
12+
### Fixed
13+
14+
- `.gitattributes` files to be filter out.
15+
- `TimeToLive` marked as internal
16+
- `Host::toUnicode` method MUST never throw exceptions on conversion according to RFC3490.
17+
- `UnableToResolveDomain` typo in the exception message
18+
19+
### Deprecated
20+
21+
- `TimeToLive::fromDateTimeInterface` use `TimeToLive::fromNow`
22+
- `TimeToLive::fromScalar` use `TimeToLive::convert`
23+
24+
### Removed
25+
26+
- None
27+
528
## 6.0.0 - 2020-12-13
629

730
### Added

README.md

+41-22
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ For the [Public Suffix List](http://publicsuffix.org/) you need to use the
6060
~~~php
6161
<?php
6262
use Pdp\Rules;
63+
use Pdp\Domain;
6364

6465
$publicSuffixList = Rules::fromPath('/path/to/cache/public-suffix-list.dat');
66+
$domain = Domain::fromIDNA2008('www.PreF.OkiNawA.jP');
6567

66-
$result = $publicSuffixList->resolve('www.PreF.OkiNawA.jP');
68+
$result = $publicSuffixList->resolve($domain);
6769
echo $result->domain()->toString(); //display 'www.pref.okinawa.jp';
6870
echo $result->subDomain()->toString(); //display 'www';
6971
echo $result->secondLevelDomain()->toString(); //display 'pref';
@@ -76,11 +78,15 @@ For the [IANA Top Level Domain List](https://www.iana.org/domains/root/files),
7678
the `Pdp\TopLevelDomains` class is use instead:
7779

7880
~~~php
81+
<?php
82+
83+
use Pdp\Domain;
7984
use Pdp\TopLevelDomains;
8085

8186
$topLevelDomains = TopLevelDomains::fromPath('/path/to/cache/tlds-alpha-by-domain.txt');
87+
$domain = Domain::fromIDNA2008('www.PreF.OkiNawA.jP');
8288

83-
$result = $topLevelDomains->resolve('www.PreF.OkiNawA.jP');
89+
$result = $topLevelDomains->resolve($domain);
8490
echo $result->domain()->toString(); //display 'www.pref.okinawa.jp';
8591
echo $result->suffix()->toString(); //display 'jp';
8692
echo $result->secondLevelDomain()->toString(); //display 'okinawa';
@@ -109,31 +115,38 @@ These methods resolve the domain against their respective data source using
109115
the same rules as the `resolve` method but will instead throw an exception
110116
if no valid effective TLD is found or if the submitted domain is invalid.
111117

118+
**All these methods expect as their sole argument a `Pdp\Host` implementing
119+
object, but other types (ie: `string`, `null` and stringable objects) are
120+
supported with predefined conditions as explained in the remaining document.**
121+
112122
~~~php
113-
<?php
123+
<?php
124+
125+
use Pdp\Domain;
114126
use Pdp\Rules;
115127
use Pdp\TopLevelDomains;
116128

117129
$publicSuffixList = Rules::fromPath('/path/to/cache/public-suffix-list.dat');
130+
$domain = Domain::fromIDNA2008('qfdsf.unknownTLD');
118131

119-
$publicSuffixList->getICANNDomain('qfdsf.unknownTLD');
132+
$publicSuffixList->getICANNDomain($domain);
120133
// will throw because `.unknownTLD` is not part of the ICANN section
121134

122-
$result = $publicSuffixList->getCookieDomain('qfdsf.unknownTLD');
135+
$result = $publicSuffixList->getCookieDomain($domain);
123136
$result->suffix()->value(); // returns 'unknownTLD'
124137
$result->suffix()->isKnown(); // returns false
125138
// will not throw because the domain syntax is correct.
126139

127-
$publicSuffixList->getCookieDomain('com');
140+
$publicSuffixList->getCookieDomain(Domain::fromIDNA2008('com'));
128141
// will not throw because the domain syntax is invalid (ie: does not support public suffix)
129142

130-
$result = $publicSuffixList->resolve('com');
143+
$result = $publicSuffixList->resolve(Domain::fromIDNA2008('com'));
131144
$result->suffix()->value(); // returns null
132145
$result->suffix()->isKnown(); // returns false
133146
// will not throw but its public suffix value equal to NULL
134147

135148
$topLevelDomains = TopLevelDomains::fromPath('/path/to/cache/public-suffix-list.dat');
136-
$topLevelDomains->getIANADomain('com');
149+
$topLevelDomains->getIANADomain(Domain::fromIDNA2008('com'));
137150
// will not throw because the domain syntax is invalid (ie: does not support public suffix)
138151
~~~
139152

@@ -171,10 +184,12 @@ The `Pdp\ResolvedDomain` decorates the `Pdp\Domain` class resolved but also
171184
gives access as separate methods to the domain different components.
172185

173186
~~~php
187+
use Pdp\Domain;
174188
use Pdp\TopLevelDomains;
175189

190+
$domain = Domain::fromIDNA2008('www.PreF.OkiNawA.jP');
176191
/** @var TopLevelDomains $topLevelDomains */
177-
$result = $topLevelDomains->resolve('www.PreF.OkiNawA.jP');
192+
$result = $topLevelDomains->resolve($domain);
178193
echo $result->domain()->toString(); //display 'www.pref.okinawa.jp';
179194
echo $result->suffix()->toString(); //display 'jp';
180195
echo $result->secondLevelDomain()->toString(); //display 'okinawa';
@@ -188,14 +203,15 @@ You can modify the returned `Pdp\ResolvedDomain` instance using the following me
188203
~~~php
189204
<?php
190205

206+
use Pdp\Domain;
191207
use Pdp\Rules;
192208

193209
/** @var Rules $publicSuffixList */
194-
$result = $publicSuffixList->resolve('shop.example.com');
210+
$result = $publicSuffixList->resolve(Domain::fromIDNA2008('shop.example.com'));
195211
$altResult = $result
196-
->withSubDomain('foo.bar')
197-
->withSecondLevelDomain('test')
198-
->withSuffix('example');
212+
->withSubDomain(Domain::fromIDNA2008('foo.bar'))
213+
->withSecondLevelDomain(Domain::fromIDNA2008('test'))
214+
->withSuffix(Domain::fromIDNA2008('example'));
199215

200216
echo $result->domain()->toString(); //display 'shop.example.com';
201217
$result->suffix()->isKnown(); //return true;
@@ -217,10 +233,11 @@ origin.
217233

218234
~~~php
219235
<?php
236+
use Pdp\Domain;
220237
use Pdp\Rules;
221238

222239
/** @var Rules $publicSuffixList */
223-
$suffix = $publicSuffixList->resolve('example.github.io')->suffix();
240+
$suffix = $publicSuffixList->resolve(Domain::fromIDNA2008('example.github.io'))->suffix();
224241

225242
echo $suffix->domain()->toString(); //display 'github.io';
226243
$suffix->isICANN(); //will return false
@@ -274,11 +291,12 @@ manipulating domain labels. You can access the object using the following method
274291
`Domain` objects usage are explain in the next section.
275292

276293
~~~php
277-
<?php
294+
<?php
295+
use Pdp\Domain;
278296
use Pdp\Rules;
279297

280298
/** @var Rules $publicSuffixList */
281-
$result = $publicSuffixList->resolve('www.bbc.co.uk');
299+
$result = $publicSuffixList->resolve(Domain::from2008('www.bbc.co.uk'));
282300
$domain = $result->domain();
283301
echo $domain->toString(); // display 'www.bbc.co.uk'
284302
count($domain); // returns 4
@@ -303,10 +321,11 @@ following methods:
303321

304322
~~~php
305323
<?php
324+
use Pdp\Domain;
306325
use Pdp\Rules;
307326

308327
/** @var Rules $publicSuffixList */
309-
$domain = $publicSuffixList->resolve('www.ExAmpLE.cOM')->domain();
328+
$domain = $publicSuffixList->resolve(Domain::from2008('www.ExAmpLE.cOM'))->domain();
310329

311330
$newDomain = $domain
312331
->withLabel(1, 'com') //replace 'example' by 'com'
@@ -540,8 +559,9 @@ Testing
540559
`pdp-domain-parser` has:
541560

542561
- a [PHPUnit](https://phpunit.de) test suite
543-
- a coding style compliance test suite using [PHP CS Fixer](http://cs.sensiolabs.org/).
544-
- a code analysis compliance test suite using [PHPStan](https://github.com/phpstan/phpstan).
562+
- a code analysis compliance test suite using [PHPStan](https://phpstan.org).
563+
- a code analysis compliance test suite using [Psalm](https://psalm.dev).
564+
- a coding style compliance test suite using [PHP CS Fixer](https://cs.symfony.com).
545565

546566
To run the tests, run the following command from the project folder.
547567

@@ -570,10 +590,9 @@ The MIT License (MIT). Please see [License File](LICENSE) for more information.
570590
Attribution
571591
-------
572592

573-
Portions of the `Pdp\Converter` and `Pdp\Rules` are derivative works of the PHP
593+
Portions of the `Pdp\Rules` class are derivative works of the PHP
574594
[registered-domain-libs](https://github.com/usrflo/registered-domain-libs).
575-
Those parts of this codebase are heavily commented, and I've included a copy of
576-
the Apache Software Foundation License 2.0 in this project.
595+
I've included a copy of the Apache Software Foundation License 2.0 in this project.
577596

578597
[ico-github-actions-build]: https://img.shields.io/github/workflow/status/jeremykendall/php-domain-parser/Build?style=flat-square
579598
[ico-packagist]: https://img.shields.io/packagist/dt/jeremykendall/php-domain-parser.svg?style=flat-square

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
],
4242
"require": {
4343
"php": "^7.4 || ^8.0",
44+
"ext-filter": "*",
4445
"ext-intl": "*",
4546
"ext-json": "*"
4647
},
@@ -71,7 +72,8 @@
7172
},
7273
"scripts": {
7374
"phpcs": "php-cs-fixer fix -vvv --diff --dry-run --allow-risky=yes --ansi",
74-
"phpstan": "phpstan analyse -l max -c phpstan.neon src --ansi",
75+
"phpcs:fix": "php-cs-fixer fix -vvv --allow-risky=yes --ansi",
76+
"phpstan": "phpstan analyse -l max -c phpstan.neon src --memory-limit=256M --ansi",
7577
"psalm": "psalm --show-info=true",
7678
"phpunit": "phpunit --coverage-text",
7779
"test": [
@@ -83,6 +85,7 @@
8385
},
8486
"scripts-descriptions": {
8587
"phpcs": "Runs coding style test suite",
88+
"phpcs:fix": "Fix the package coding style",
8689
"phpstan": "Runs complete codebase static analysis",
8790
"psalm": "Runs complete codebase static analysis",
8891
"phpunit": "Runs unit and functional testing",

phpstan.neon

-1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,4 @@ includes:
44
- vendor/phpstan/phpstan-phpunit/rules.neon
55
parameters:
66
ignoreErrors:
7-
- '#should be covariant with return type#'
87
reportUnmatchedIgnoredErrors: true

psalm.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
22
<psalm
3-
errorLevel="3"
3+
errorLevel="1"
44
resolveFromConfigFile="true"
55
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
66
xmlns="https://getpsalm.org/schema/config"

src/Domain.php

+13-5
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class Domain implements DomainName
4545
private const REGEXP_URI_DELIMITERS = '/[:\/?#\[\]@ ]/';
4646

4747
/**
48-
* @var array<string>
48+
* @var array<int, string>
4949
*/
5050
private array $labels;
5151

@@ -176,7 +176,7 @@ private function domainToUnicode(string $domain): string
176176
*/
177177
public function getIterator(): Iterator
178178
{
179-
foreach ($this->labels as $offset => $label) {
179+
foreach ($this->labels as $label) {
180180
yield $label;
181181
}
182182
}
@@ -216,7 +216,7 @@ public function label(int $key): ?string
216216
}
217217

218218
/**
219-
* @return array<int>
219+
* @return list<int>
220220
*/
221221
public function keys(string $label = null): array
222222
{
@@ -228,13 +228,17 @@ public function keys(string $label = null): array
228228
}
229229

230230
/**
231-
* @return array<string>
231+
* @return array<int, string>
232232
*/
233233
public function labels(): array
234234
{
235235
return $this->labels;
236236
}
237237

238+
/**
239+
* @psalm-suppress MoreSpecificReturnType
240+
* @psalm-suppress LessSpecificReturnStatement
241+
*/
238242
public function toAscii(): self
239243
{
240244
if (null === $this->domain) {
@@ -249,6 +253,10 @@ public function toAscii(): self
249253
return new self($this->type, $domain);
250254
}
251255

256+
/**
257+
* @psalm-suppress MoreSpecificReturnType
258+
* @psalm-suppress LessSpecificReturnStatement
259+
*/
252260
public function toUnicode(): self
253261
{
254262
if (null === $this->domain) {
@@ -266,7 +274,7 @@ public function toUnicode(): self
266274
/**
267275
* Filter a subdomain to update the domain part.
268276
*
269-
* @param string|object $domain a domain
277+
* @param string|object|null $domain a domain
270278
*
271279
* @throws TypeError if the domain can not be converted
272280
*/

0 commit comments

Comments
 (0)