Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 9 additions & 14 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,11 @@ jobs:
runs-on: ubuntu-22.04
strategy:
matrix:
php: ['8.1', '8.2', '8.3', '8.4']
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
stability: [prefer-lowest, prefer-stable]
include:
- php: '8.4'
flags: "--ignore-platform-req=php"
phpunit-flags: '--no-coverage'
stability: prefer-stable
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
Expand All @@ -37,7 +32,7 @@ jobs:
id: composer-cache
run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v4
- uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.stability }}-${{ matrix.flags }}-${{ hashFiles('**/composer.lock') }}
Expand All @@ -50,16 +45,16 @@ jobs:

- name: Run Unit tests with coverage
run: composer phpunit -- ${{ matrix.phpunit-flags }}
if: ${{ matrix.php == '8.3' || matrix.php == '8.2' || matrix.php == '8.1'}}
if: ${{ matrix.php != '8.5' }}

- name: Run Unit tests without coverage
run: composer phpunit:min
if: ${{ matrix.php == '8.4'}}
- name: Run Unit tests without coverage
run: vendor/bin/phpunit --no-coverage
if: ${{ matrix.php == '8.5' }}

- name: Run static analysis
run: composer phpstan
if: ${{ matrix.php == '8.3' && matrix.stability == 'prefer-stable'}}
if: ${{ matrix.php == '8.4' && matrix.stability == 'prefer-stable'}}

- name: Run Coding style rules
run: composer phpcs:fix
if: ${{ matrix.php == '8.3' && matrix.stability == 'prefer-stable'}}
if: ${{ matrix.php == '8.4' && matrix.stability == 'prefer-stable'}}
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
$config = new PhpCsFixer\Config();

return $config
->setUnsupportedPhpVersionAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@PSR12' => true,
Expand Down
21 changes: 12 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,22 @@
"ext-filter": "*"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.65.0",
"guzzlehttp/guzzle": "^7.9.2",
"guzzlehttp/psr7": "^1.6 || ^2.7.0",
"phpstan/phpstan": "^1.12.13",
"friendsofphp/php-cs-fixer": "^3.91.3",
"guzzlehttp/guzzle": "^7.10.0",
"guzzlehttp/psr7": "^1.6 || ^2.8.0",
"phpstan/phpstan": "^1.12.32",
"phpstan/phpstan-phpunit": "^1.4.2",
"phpstan/phpstan-strict-rules": "^1.6.1",
"phpunit/phpunit": "^10.5.15 || ^11.5.1",
"phpstan/phpstan-strict-rules": "^1.6.2",
"phpunit/phpunit": "^10.5.15 || ^11.5.1 || ^12.5.2",
"psr/http-factory": "^1.1.0",
"psr/simple-cache": "^1.0.1 || ^2.0.0",
"symfony/cache": "^v5.0.0 || ^6.4.16",
"symfony/var-dumper": "^v6.4.18 || ^7.2"
"symfony/cache": "^v5.0.0 || ^6.4.16 || ^v7.4.1 || ^v8.0.0",
"symfony/var-dumper": "^v6.4.18 || ^7.4 || ^v8.0.0",
"league/uri-polyfill" : ">=7.7.0"
},
"suggest": {
"ext-uri": "to use the PHP native URI class",
"league/uri-polyfill" : "Needed to backport the PHP URI extension for older versions of PHP",
"psr/http-client-implementation": "To use the storage functionality which depends on PSR-18",
"psr/http-factory-implementation": "To use the storage functionality which depends on PSR-17",
"psr/simple-cache-implementation": "To use the storage functionality which depends on PSR-16",
Expand All @@ -70,7 +73,7 @@
}
},
"scripts": {
"phpcs": "PHP_CS_FIXER_IGNORE_ENV=1 php-cs-fixer fix -vvv --diff --dry-run --allow-risky=yes --ansi",
"phpcs": "php-cs-fixer fix -vvv --diff --dry-run --allow-risky=yes --ansi",
"phpcs:fix": "php-cs-fixer fix -vvv --allow-risky=yes --ansi",
"phpstan": "phpstan analyse -c phpstan.neon --ansi --memory-limit=192M",
"phpunit": "XDEBUG_MODE=coverage phpunit --coverage-text",
Expand Down
28 changes: 14 additions & 14 deletions src/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use SplFileObject;
use SplTempFileObject;
use Stringable;
use Uri\Rfc3986\Uri;
use Uri\WhatWg\Url;

use function array_key_exists;
use function array_pop;
Expand Down Expand Up @@ -158,7 +160,7 @@ public static function __set_state(array $properties): self
return new self($properties['rules']);
}

public function resolve(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
public function resolve(DomainNameProvider|Host|Stringable|Url|Uri|string|int|null $host): ResolvedDomainName
{
try {
return $this->getCookieDomain($host);
Expand All @@ -169,7 +171,7 @@ public function resolve(DomainNameProvider|Host|Stringable|string|int|null $host
}
}

public function getCookieDomain(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
public function getCookieDomain(DomainNameProvider|Host|Stringable|Url|Uri|string|int|null $host): ResolvedDomainName
{
$domain = $this->validateDomain($host);
[$suffixLength, $section] = $this->resolveSuffix($domain->withoutRootLabel(), self::UNKNOWN_DOMAINS);
Expand All @@ -181,7 +183,7 @@ public function getCookieDomain(DomainNameProvider|Host|Stringable|string|int|nu
};
}

public function getICANNDomain(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
public function getICANNDomain(DomainNameProvider|Host|Stringable|Url|Uri|string|int|null $host): ResolvedDomainName
{
$domain = $this->validateDomain($host);
[$suffixLength, $section] = $this->resolveSuffix($domain, self::ICANN_DOMAINS);
Expand All @@ -192,7 +194,7 @@ public function getICANNDomain(DomainNameProvider|Host|Stringable|string|int|nul
return ResolvedDomain::fromICANN($domain, $suffixLength);
}

public function getPrivateDomain(DomainNameProvider|Host|Stringable|string|int|null $host): ResolvedDomainName
public function getPrivateDomain(DomainNameProvider|Host|Stringable|Url|Uri|string|int|null $host): ResolvedDomainName
{
$domain = $this->validateDomain($host);
[$suffixLength, $section] = $this->resolveSuffix($domain, self::PRIVATE_DOMAINS);
Expand All @@ -209,17 +211,15 @@ public function getPrivateDomain(DomainNameProvider|Host|Stringable|string|int|n
* @throws SyntaxError If the domain is invalid
* @throws UnableToResolveDomain If the domain can not be resolved
*/
private function validateDomain(DomainNameProvider|Host|Stringable|string|int|null $domain): DomainName
private function validateDomain(DomainNameProvider|Host|Stringable|Uri|Url|string|int|null $domain): DomainName
{
if ($domain instanceof DomainNameProvider) {
$domain = $domain->domain();
}

if (!$domain instanceof DomainName) {
$domain = Domain::fromIDNA2008($domain);
}

return $domain;
return match (true) {
$domain instanceof DomainNameProvider => $domain->domain(),
$domain instanceof Uri => Domain::fromIDNA2008($domain->getRawHost()),
$domain instanceof Url => Domain::fromIDNA2008($domain->getAsciiHost()),
$domain instanceof DomainName => $domain,
default => Domain::fromIDNA2008($domain),
};
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/SuffixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,15 @@ public function testToUnicodeReturnsSameInstance(): void
self::assertEquals($instance->toUnicode(), $instance);
}

/**
* @param list<string> $labels
*
* @throws CannotProcessHost
*/
#[DataProvider('countableProvider')]
public function testCountable(?string $domain, int $nbLabels): void
public function testCountable(?string $domain, int $nbLabels, array $labels = []): void
{
$domain = Suffix::fromUnknown($domain);

self::assertCount($nbLabels, $domain);
self::assertCount($nbLabels, Suffix::fromUnknown($domain));
}

/**
Expand Down