Skip to content

Commit

Permalink
Improve PHP static analysis fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamsprod committed Apr 7, 2021
1 parent d7ddb2a commit 283e458
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .php_cs
Expand Up @@ -24,7 +24,7 @@ return PhpCsFixer\Config::create()
'phpdoc_no_empty_return' => true,
'phpdoc_order' => true,
'phpdoc_scalar' => true,
'phpdoc_to_comment' => true,
'phpdoc_to_comment' => false,
'phpdoc_summary' => true,
'psr0' => true,
'psr4' => true,
Expand Down
2 changes: 1 addition & 1 deletion psalm.xml
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<psalm
errorLevel="3"
errorLevel="1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
Expand Down
10 changes: 5 additions & 5 deletions src/Domain.php
Expand Up @@ -45,7 +45,7 @@ final class Domain implements DomainName
private const REGEXP_URI_DELIMITERS = '/[:\/?#\[\]@ ]/';

/**
* @var array<string>
* @var array<int, string>
*/
private array $labels;

Expand Down Expand Up @@ -176,7 +176,7 @@ private function domainToUnicode(string $domain): string
*/
public function getIterator(): Iterator
{
foreach ($this->labels as $offset => $label) {
foreach ($this->labels as $label) {
yield $label;
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ public function label(int $key): ?string
}

/**
* @return array<int>
* @return list<int>
*/
public function keys(string $label = null): array
{
Expand All @@ -228,7 +228,7 @@ public function keys(string $label = null): array
}

/**
* @return array<string>
* @return array<int, string>
*/
public function labels(): array
{
Expand Down Expand Up @@ -274,7 +274,7 @@ public function toUnicode(): self
/**
* Filter a subdomain to update the domain part.
*
* @param string|object $domain a domain
* @param string|object|null $domain a domain
*
* @throws TypeError if the domain can not be converted
*/
Expand Down
8 changes: 4 additions & 4 deletions src/DomainName.php
Expand Up @@ -36,7 +36,7 @@ public function label(int $key): ?string;
/**
* Returns the object labels.
*
* @return array<string>
* @return array<int, string>
*/
public function labels(): array;

Expand All @@ -63,7 +63,7 @@ public function getIterator(): Iterator;
*
* @see ::withLabel
*
* @param mixed $label a domain label
* @param string|null|object $label a domain label
*/
public function prepend($label): self;

Expand All @@ -72,7 +72,7 @@ public function prepend($label): self;
*
* @see ::withLabel
*
* @param mixed $label a domain label
* @param string|null|object $label a domain label
*/
public function append($label): self;

Expand All @@ -85,7 +85,7 @@ public function append($label): self;
* If $key is non-negative, the added label will be the label at $key position from the start.
* If $key is negative, the added label will be the label at $key position from the end.
*
* @param mixed $label a domain label
* @param string|null|object $label a domain label
*
* @throws CannotProcessHost If the key is out of bounds
* @throws CannotProcessHost If the label is converted to the NULL value
Expand Down
4 changes: 2 additions & 2 deletions src/DomainTest.php
Expand Up @@ -338,7 +338,7 @@ public function testAppend(string $raw, string $append, string $expected): void
}

/**
* @return iterable<array{0:string, 1:string, 2:string}>
* @return iterable<array-key, array{0:string, 1:string, 2:string}>
*/
public function validAppend(): iterable
{
Expand All @@ -359,7 +359,7 @@ public function testPrepend(string $raw, string $prepend, string $expected): voi
}

/**
* @return iterable<array{0:string, 1:string, 2:string}>
* @return iterable<array-key, array{0:string, 1:string, 2:string}>
*/
public function validPrepend(): iterable
{
Expand Down
14 changes: 12 additions & 2 deletions src/Idna.php
Expand Up @@ -75,9 +75,14 @@ public static function toAscii(string $domain, int $options): IdnaInfo

self::supportsIdna();

/**
* @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 */
/**
* @var array{errors: int, isTransitionalDifferent: bool, result: string} $idnaInfo
*/
return self::createIdnaInfo($domain, $idnaInfo);
}

Expand All @@ -96,9 +101,14 @@ public static function toUnicode(string $domain, int $options): IdnaInfo

self::supportsIdna();

/**
* @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 */
/**
* @var array{errors: int, isTransitionalDifferent: bool, result: string} $idnaInfo
*/
return self::createIdnaInfo($domain, $idnaInfo);
}

Expand Down
2 changes: 1 addition & 1 deletion src/ResolvedDomainTest.php
Expand Up @@ -540,7 +540,7 @@ public function testWithSecondLevelDomain(
}

/**
* @return iterable<array{host:string|null, publicSuffix:string|null, sld:string|null, expectedSld:string|null, expectedHost:string|null}>
* @return iterable<array-key, array{host:string|null, publicSuffix:string|null, sld:string|null, expectedSld:string|null, expectedHost:string|null}>
*/
public function withSldWorksProvider(): iterable
{
Expand Down
5 changes: 4 additions & 1 deletion src/Rules.php
Expand Up @@ -157,7 +157,9 @@ private static function addRule(array $list, array $ruleParts): array

$list[$rule] = $list[$rule] ?? ($isDomain ? [] : ['!' => '']);
if ($isDomain && [] !== $ruleParts) {
$list[$rule] = self::addRule($list[$rule], $ruleParts);
/** @var array<array-key, array> $tmpList */
$tmpList = $list[$rule];
$list[$rule] = self::addRule($tmpList, $ruleParts);
}

return $list;
Expand Down Expand Up @@ -307,6 +309,7 @@ private function getEffectiveTopLevelDomainFromSection(DomainName $domain, strin
}

$matches[] = $label;
/** @var array<array-key, mixed> $rules */
$rules = $rules[$label];
}

Expand Down
5 changes: 1 addition & 4 deletions src/Storage/TimeToLive.php
Expand Up @@ -58,10 +58,7 @@ public static function fromNow(DateTimeInterface $date): DateInterval

$now = new DateTimeImmutable('NOW', $timezone);

/** @var DateInterval $diff */
$diff = $now->diff($date, false);

return $diff;
return $now->diff($date, false);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/TopLevelDomains.php
Expand Up @@ -186,7 +186,7 @@ public function isEmpty(): bool
*/
public function getIterator(): Iterator
{
foreach ($this->records as $tld => $int) {
foreach ($this->records as $tld => $_) {
yield $tld;
}
}
Expand Down

0 comments on commit 283e458

Please sign in to comment.