Skip to content

Commit

Permalink
Merge pull request #324 from jeremykendall/develop
Browse files Browse the repository at this point in the history
Prepare 6.1.1 release
  • Loading branch information
nyamsprod authored Feb 18, 2022
2 parents d8b196b + 1df0801 commit e195ab7
Show file tree
Hide file tree
Showing 15 changed files with 2,569 additions and 954 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php: [ '7.4', '8.0' ]
php: [ '7.4', '8.0', '8.1' ]
composer-flags: [ '' ]
phpunit-flags: [ '--coverage-text' ]
steps:
Expand All @@ -23,8 +23,8 @@ jobs:
- run: composer update --no-progress ${{ matrix.composer-flags }}
- run: composer phpunit
- run: composer phpstan
if: ${{ matrix.php == '8.0' }}
if: ${{ matrix.php == '8.1' }}
- run: composer psalm
if: ${{ matrix.php == '8.0' }}
if: ${{ matrix.php == '8.1' }}
- run: composer phpcs
if: ${{ matrix.php == '8.0' }}
if: ${{ matrix.php == '8.1' }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ docs
build
.idea
.php_cs.cache
.php-cs-fixer.cache
.phpunit.result.cache
composer.lock
20 changes: 14 additions & 6 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,31 @@
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'concat_space' => ['spacing' => 'none'],
'global_namespace_import' => [
'import_classes' => true,
'import_constants' => true,
'import_functions' => true,
],
'list_syntax' => ['syntax' => 'short'],
'new_with_braces' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_phpdoc' => true,
'no_empty_comment' => true,
'no_leading_import_slash' => true,
'no_superfluous_phpdoc_tags' => true,
'no_superfluous_phpdoc_tags' => [
'allow_mixed' => true,
'remove_inheritdoc' => true,
'allow_unused_params' => false,
],
'no_trailing_comma_in_singleline_array' => true,
'no_unused_imports' => true,
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
'phpdoc_align' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => false,
'phpdoc_to_comment' => true,
'phpdoc_summary' => true,
'psr_autoloading' => true,
'return_type_declaration' => ['space_before' => 'none'],
Expand All @@ -36,7 +46,5 @@
'trailing_comma_in_multiline' => true,
'trim_array_spaces' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style' => true,
])
->setFinder($finder)
;
->setFinder($finder);
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

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

## 6.1.1 - 2022-02-18

### Added

- None

### Fixed

- [#321](https://github.com/jeremykendall/php-domain-parser/issues/321) improve resolving private domain suffix. `Rules::getPrivateDomain` will now throw if the domain name does not contain a "private" TLD.

### Deprecated

- None

### Removed

- None

## 6.1.0 - 2021-06-19

### Added
Expand Down
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@
"ext-json": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"friendsofphp/php-cs-fixer": "^v3.5.0",
"guzzlehttp/guzzle": "^7.0",
"guzzlehttp/psr7": "^1.6",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-phpunit": "^0.12",
"phpstan/phpstan-strict-rules": "^0.12",
"phpunit/phpunit": "^9.3",
"psalm/plugin-phpunit": "^0.15.0",
"guzzlehttp/psr7": "^1.6||^2.0",
"phpstan/phpstan": "^1.4.6.",
"phpstan/phpstan-phpunit": "^1.0.0",
"phpstan/phpstan-strict-rules": "^1.1.0",
"phpunit/phpunit": "^9.5.13",
"psalm/plugin-phpunit": "^0.15.2",
"psr/http-factory": "^1.0",
"psr/simple-cache": "^1.0",
"symfony/cache": "^v5.0",
"vimeo/psalm": "^4.3"
"vimeo/psalm": "^4.20"
},
"suggest": {
"psr/http-client-implementation": "To use the storage functionnality which depends on PSR-18",
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,12 @@ includes:
- vendor/phpstan/phpstan-phpunit/rules.neon
parameters:
ignoreErrors:
- message: '#has no value type specified in iterable type array.#'
path: src/Rules.php
- message: '#has parameter \$(properties|rules|list|tmpList) with no value type specified in iterable type array.#'
path: src/Rules.php
- message: "#Cannot access offset '!' on mixed.#"
path: src/Rules.php
- message: '#Variable \$line on left side of \?\? always exists and is not nullable.#'
path: src/Rules.php
reportUnmatchedIgnoredErrors: true
1 change: 0 additions & 1 deletion src/DomainName.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public function withLabel(int $key, $label): self;
* If $key is non-negative, the removed label will be the label at $key position from the start.
* If $key is negative, the removed label will be the label at $key position from the end.
*
* @param int ...$keys
*
* @throws CannotProcessHost If the key is out of bounds
*/
Expand Down
3 changes: 2 additions & 1 deletion src/DomainTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Pdp;

use PHPUnit\Framework\TestCase;
use stdClass;
use TypeError;

/**
Expand Down Expand Up @@ -314,7 +315,7 @@ public function withLabelWorksProvider(): iterable
public function testWithLabelFailsWithTypeError(): void
{
$this->expectException(TypeError::class);
Domain::fromIDNA2008('example.com')->withLabel(1, new \stdClass());
Domain::fromIDNA2008('example.com')->withLabel(1, new stdClass());
}

public function testWithLabelFailsWithInvalidKey(): void
Expand Down
4 changes: 2 additions & 2 deletions src/Idna.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function toAscii(string $domain, int $options): IdnaInfo

self::supportsIdna();

/** @param-out array{errors: int, isTransitionalDifferent: bool, result: string} $idnaInfo */
/* @param-out array{errors: int, isTransitionalDifferent: bool, result: string} $idnaInfo */
idn_to_ascii($domain, $options, INTL_IDNA_VARIANT_UTS46, $idnaInfo);

/** @var array{result:string, isTransitionalDifferent:bool, errors:int} $idnaInfo */
Expand All @@ -124,7 +124,7 @@ public static function toUnicode(string $domain, int $options): IdnaInfo

self::supportsIdna();

/** @param-out array{errors: int, isTransitionalDifferent: bool, result: string} $idnaInfo */
/* @param-out array{errors: int, isTransitionalDifferent: bool, result: string} $idnaInfo */
idn_to_utf8($domain, $options, INTL_IDNA_VARIANT_UTS46, $idnaInfo);

/** @var array{result:string, isTransitionalDifferent:bool, errors:int} $idnaInfo */
Expand Down
19 changes: 12 additions & 7 deletions src/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ final class Rules implements PublicSuffixList
/**
* PSL rules as a multidimensional associative array.
*
* @var array<string, array<array>>
* @var array{ICANN_DOMAINS: array<array>, PRIVATE_DOMAINS: array<array>}
*/
private array $rules;

/**
* @param array<string, array<array>> $rules
* @param array{ICANN_DOMAINS: array<array>, PRIVATE_DOMAINS: array<array>} $rules
*/
private function __construct(array $rules)
{
Expand Down Expand Up @@ -84,7 +84,7 @@ public static function fromString($content): self
/**
* Convert the Public Suffix List into an associative, multidimensional array.
*
* @return array<string, array<array>>
* @return array{ICANN_DOMAINS: array<array>, PRIVATE_DOMAINS: array<array>}
*/
private static function parse(string $content): array
{
Expand Down Expand Up @@ -165,7 +165,7 @@ private static function addRule(array $list, array $ruleParts): array
}

/**
* @param array{rules:array<string, array<array>>} $properties
* @param array{rules:array{ICANN_DOMAINS: array<array>, PRIVATE_DOMAINS: array<array>}} $properties
*/
public static function __set_state(array $properties): self
{
Expand Down Expand Up @@ -290,18 +290,23 @@ private function getPublicSuffixLengthFromSection(DomainName $domain, string $se
$labelCount = 0;
foreach ($domain->toAscii() as $label) {
//match exception rule
if (isset($rules[$label], $rules[$label]['!'])) {
if (isset($rules[$label]['!'])) {
break;
}

//match wildcard rule
if (isset($rules['*'])) {
if (array_key_exists('*', $rules)) {
++$labelCount;
break;
}

//no match found
if (!isset($rules[$label])) {
if (!array_key_exists($label, $rules)) {
// for private domain suffix MUST be fully matched else no suffix is found
// https://github.com/jeremykendall/php-domain-parser/issues/321
if (self::PRIVATE_DOMAINS === $section && [] !== $rules) {
$labelCount = 0;
}
break;
}

Expand Down
18 changes: 18 additions & 0 deletions src/RulesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -593,4 +593,22 @@ public function effectiveTLDProvider(): iterable
],
];
}

public function testIssue321Success(): void
{
$result = self::$rules->resolve('node857-gelofesta.users.scale.virtualcloud.com.br');
self::assertSame('users.scale.virtualcloud.com.br', $result->suffix()->value());
self::assertTrue($result->suffix()->isPrivate());

$result = self::$rules->resolve('clientportal.virtualcloud.com.br');
self::assertSame('com.br', $result->suffix()->value());
self::assertTrue($result->suffix()->isICANN());
}

public function testIssue321Failure(): void
{
$this->expectException(UnableToResolveDomain::class);

self::$rules->getPrivateDomain('clientportal.virtualcloud.com.br');
}
}
12 changes: 7 additions & 5 deletions src/Storage/PublicSuffixListPsr16CacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Pdp\Storage;

use DateInterval;
use DateTimeImmutable;
use InvalidArgumentException;
use Pdp\Rules;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -54,7 +56,7 @@ public function testItReturnsNullIfTheCacheContentCannotBeConvertedToTheCorrectI
$cache = $this->createStub(CacheInterface::class);
$cache->method('get')->willReturn('{"foo":"bar"}');

$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new \DateTimeImmutable('+1 DAY'));
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new DateTimeImmutable('+1 DAY'));

self::assertNull($pslCache->fetch('http://www.example.com'));
}
Expand All @@ -65,7 +67,7 @@ public function testItCanStoreAPublicSuffixListInstance(): void
$cache->method('set')->willReturn(true);

$psl = Rules::fromPath(dirname(__DIR__, 2).'/test_data/public_suffix_list.dat');
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new \DateInterval('P1D'));
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new DateInterval('P1D'));

self::assertTrue($pslCache->remember('http://www.example.com', $psl));
}
Expand All @@ -76,7 +78,7 @@ public function testItReturnsFalseIfItCantStoreAPublicSuffixListInstance(): void
$cache->method('set')->willReturn(false);

$psl = Rules::fromPath(dirname(__DIR__, 2).'/test_data/public_suffix_list.dat');
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new \DateInterval('P1D'));
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new DateInterval('P1D'));

self::assertFalse($pslCache->remember('http://www.example.com', $psl));
}
Expand All @@ -89,7 +91,7 @@ public function testItReturnsFalseIfItCantCacheAPublicSuffixListInstance(): void
$cache->method('set')->will(self::throwException($exception));

$psl = Rules::fromPath(dirname(__DIR__, 2).'/test_data/public_suffix_list.dat');
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new \DateInterval('P1D'));
$pslCache = new PublicSuffixListPsr16Cache($cache, 'pdp_', new DateInterval('P1D'));

self::assertFalse($pslCache->remember('http://www.example.com', $psl));
}
Expand Down Expand Up @@ -120,7 +122,7 @@ public function testItCanDeleteTheCachedDatabase(): void
$cache = $this->createStub(CacheInterface::class);
$cache->method('delete')->willReturn(true);

$instance = new PublicSuffixListPsr16Cache($cache, 'pdp_', new \DateInterval('P1D'));
$instance = new PublicSuffixListPsr16Cache($cache, 'pdp_', new DateInterval('P1D'));
self::assertTrue($instance->forget($uri));
}

Expand Down
4 changes: 1 addition & 3 deletions src/TopLevelDomainList.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public function version(): string;
*/
public function lastUpdated(): DateTimeImmutable;

/**
* {@inheritdoc}
*/

public function count(): int;

/**
Expand Down
6 changes: 3 additions & 3 deletions src/TopLevelDomainsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public function testGetTopLevelDomain($tld): void
}

/**
* @return iterable<string,array>
* @return iterable<string,array<object|string>>
*/
public function validDomainProvider(): iterable
{
Expand Down Expand Up @@ -286,7 +286,7 @@ public function testGetTopLevelDomainWithUnregisteredTLD(): void
}

/**
* @return iterable<string,array>
* @return iterable<string,array<string|object>>
*/
public function validTldProvider(): iterable
{
Expand All @@ -312,7 +312,7 @@ public function __toString(): string
}

/**
* @return iterable<string,array>
* @return iterable<string,array<object|string|null>>
*/
public function invalidTldProvider(): iterable
{
Expand Down
Loading

0 comments on commit e195ab7

Please sign in to comment.