From 5685f6a4ce32c07b84674c8f15122ab9b6daaa59 Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Tue, 2 Jun 2026 21:51:39 +0200 Subject: [PATCH 1/4] =?UTF-8?q?ci(style):=20=F0=9F=A4=96=20introduce=20cod?= =?UTF-8?q?e=20style=20ruleset?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add PHP-CS-Fixer configuration and ruleset definition. --- .gitignore | 1 + .php-cs-fixer.dist.php | 83 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 .php-cs-fixer.dist.php diff --git a/.gitignore b/.gitignore index 0b2c910..b07de59 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ /vendor/ # Because this library will never be the root package, don't commit Composer's lock file. /composer.lock +/.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..11d6995 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,83 @@ +files() + ->name('*.php') + ->in(array_filter([ + __DIR__ . '/src', + __DIR__ . '/tests', + ], static function (string $path): bool { + return file_exists($path) && is_dir($path) && is_readable($path); + })) + ->append([ + __FILE__, + ]) + ->ignoreVCS(true); + +return (new PhpCsFixer\Config()) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setFinder($finder) + ->setUsingCache(true) + ->setRiskyAllowed(true) + ->setRules([ + + '@PER-CS' => true, + '@PER-CS:risky' => true, + + 'array_indentation' => true, + 'array_syntax' => ['syntax' => 'short'], + 'backtick_to_shell_exec' => true, + 'binary_operator_spaces' => true, + 'blank_line_before_statement' => false, + 'cast_spaces' => ['space' => 'single'], + 'class_attributes_separation' => ['elements' => [ + 'const' => 'none', + 'method' => 'one', + 'property' => 'none', + 'trait_import' => 'none', + 'case' => 'none', + ]], + 'concat_space' => ['spacing' => 'one'], + 'declare_strict_types' => true, + 'function_declaration' => [ + 'closure_function_spacing' => 'one', + 'closure_fn_spacing' => 'one', + ], + 'heredoc_indentation' => ['indentation' => 'same_as_start'], + 'mb_str_functions' => false, + 'method_argument_space' => [ + 'on_multiline' => 'ignore', + ], + 'modernize_strpos' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_blank_lines' => true, + // TODO: do not allow mixed on next major version (requires MSPV 8.0). + 'no_superfluous_phpdoc_tags' => ['remove_inheritdoc' => true, 'allow_mixed' => true], + 'no_unused_imports' => true, + 'no_whitespace_in_blank_line' => true, + 'nullable_type_declaration_for_default_null_value' => true, + 'ordered_imports' => ['imports_order' => ['class', 'function', 'const']], + 'phpdoc_line_span' => ['const' => 'single', 'method' => 'single', 'property' => 'single'], + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'protected_to_private' => true, + 'psr_autoloading' => true, + 'semicolon_after_instruction' => true, + 'single_quote' => true, + 'static_lambda' => true, + 'strict_param' => true, + 'ternary_operator_spaces' => true, + // TODO: trailing commas in `arguments` too, on next major version (requires MSPV 7.3). + // TODO: trailing commas in `parameters` too, on next major version (requires MSPV 8.0). + 'trailing_comma_in_multiline' => ['elements' => ['arrays']], + 'trim_array_spaces' => true, + 'void_return' => true, + 'yoda_style' => true, + + ]); From 10d3b71af1ada2d37becb147e6f82af0d78f14e6 Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Tue, 2 Jun 2026 21:52:48 +0200 Subject: [PATCH 2/4] =?UTF-8?q?ci(style):=20=F0=9F=A4=96=20check=20code=20?= =?UTF-8?q?style=20during=20CI=20and=20local=20testing?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add PHP-CS-Fixer CI jobs to GitHub Actions. Add PHP-CS-Fixer to local testing script. --- .../{testing.yaml => runtime-testing.yaml} | 2 +- .github/workflows/static-analysis.yaml | 27 ++++++++++++++++--- tests/local.sh | 27 ++++++++++++++----- 3 files changed, 45 insertions(+), 11 deletions(-) rename .github/workflows/{testing.yaml => runtime-testing.yaml} (97%) diff --git a/.github/workflows/testing.yaml b/.github/workflows/runtime-testing.yaml similarity index 97% rename from .github/workflows/testing.yaml rename to .github/workflows/runtime-testing.yaml index 433cae9..3a1a927 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/runtime-testing.yaml @@ -1,4 +1,4 @@ -name: 'Linting and Unit Tests' +name: 'Runtime Testing' on: pull_request: diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 6e9f8dc..cefa210 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -28,7 +28,28 @@ jobs: with: dependency-versions: 'highest' # Require PHPStan via command-line instead of adding to Composer's - # "require-dev"; we only want to run static analysis once on the highest - # version of PHP available. - - run: 'composer require --dev "phpstan/phpstan:^2" "phpstan/phpstan-deprecation-rules"' + # "require-dev"; we only want to run static analysis on the + # floor/latest versions of PHP available. + - run: 'composer require --dev "phpstan/phpstan:^2.2" "phpstan/phpstan-deprecation-rules"' - run: './vendor/bin/phpstan analyze --no-progress --error-format="github"' + + code-style: + runs-on: 'ubuntu-24.04' + strategy: + matrix: + php: + - '7.4' + - '8.5' + steps: + - uses: 'actions/checkout@v6' + - uses: 'shivammathur/setup-php@v2' + with: + php-version: '${{ matrix.php }}' + - uses: 'ramsey/composer-install@v4' + with: + dependency-versions: 'highest' + # Require PHP-CS-Fixer via command-line instead of adding to Composer's + # "require-dev"; we only want to run code style checks on the + # floor/latest versions of PHP available. + - run: 'composer require --dev "php-cs-fixer/shim:^3.95"' + - run: './vendor/bin/php-cs-fixer check --allow-risky=yes --diff' diff --git a/tests/local.sh b/tests/local.sh index 38f0f75..72d5523 100644 --- a/tests/local.sh +++ b/tests/local.sh @@ -16,9 +16,9 @@ set -uo pipefail # Grab the full normalized path to the parent/project directory. export PROJECT_DIR="$(dirname "$(dirname "$(readlink -f -- "$0")")")" -# Every PHP version exercised by the lint + unit-test matrix in testing.yaml. +# Every PHP version exercised by the lint + unit-test matrix in `runtime-testing.yaml`. ALL_VERSIONS=("7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3" "8.4" "8.5") -# The subset that runs static analysis in static-analysis.yaml. +# The subset that runs analysis in the workflow `static-analysis.yaml`. STATIC_ANALYSIS_VERSIONS=("7.4" "8.5") FAILURES=() @@ -90,23 +90,36 @@ run_suite() { command cp -f "${PROJECT_DIR}/composer.json" "${PROJECT_DIR}/composer.json.suite-backup" - # 1. Syntax linting (testing.yaml: syntax-linting). No dependencies needed. + # 1. Syntax linting (runtime-testing.yaml: syntax-linting). No dependencies needed. echo "--- [${PHP_VERSION}] Syntax linting ---" docker_php "${PHP_VERSION}" sh -c \ 'find src/ -type f -name "*.php" -print0 | xargs -0 -n1 -P4 php -d"error_reporting=E_ALL&~E_DEPRECATED" -l -n | (! grep -v "No syntax errors detected")' \ || { echo "[${PHP_VERSION}] SYNTAX LINTING FAILED"; FAILED=1; } - # 2. Install dependencies (PHPStan added only for static-analysis versions). + # 2. Install dependencies (PHPStan+Fixer added only for static-analysis versions). echo "--- [${PHP_VERSION}] Installing dependencies ---" local DEV_DEPS=() if is_static_analysis_version "${PHP_VERSION}"; then - DEV_DEPS=('phpstan/phpstan:^2' 'phpstan/phpstan-deprecation-rules') + DEV_DEPS=('phpstan/phpstan:^2.2' 'phpstan/phpstan-deprecation-rules' 'php-cs-fixer/shim:^3.95') fi docker_install "${PHP_VERSION}" "${DEV_DEPS[@]}" \ || { echo "[${PHP_VERSION}] DEPENDENCY INSTALL FAILED"; FAILED=1; } if [ "${FAILED}" -eq 0 ]; then - # 3. Unit tests (testing.yaml: unit-testing). + # 3. Code style (static-analysis.yaml: code-style) on the relevant versions. + if is_static_analysis_version "${PHP_VERSION}"; then + echo "--- [${PHP_VERSION}] Code style ---" + docker_php "${PHP_VERSION}" php -d'memory_limit=512M' \ + 'vendor/bin/php-cs-fixer' \ + check \ + --allow-risky='yes' \ + --diff \ + || { echo "[${PHP_VERSION}] CODE STYLE FAILED"; FAILED=1; } + fi + fi + + if [ "${FAILED}" -eq 0 ]; then + # 4. Unit tests (runtime-testing.yaml: unit-testing). echo "--- [${PHP_VERSION}] Unit tests ---" docker_php "${PHP_VERSION}" php \ 'vendor/bin/phpunit' \ @@ -117,7 +130,7 @@ run_suite() { fi if [ "${FAILED}" -eq 0 ]; then - # 4. Static analysis (static-analysis.yaml: phpstan) on the relevant versions. + # 5. Static analysis (static-analysis.yaml: phpstan) on the relevant versions. if is_static_analysis_version "${PHP_VERSION}"; then echo "--- [${PHP_VERSION}] Static analysis ---" docker_php "${PHP_VERSION}" php -d'memory_limit=1G' \ From 16ef4850bcd447128a7bfe709e36fc6d6424598a Mon Sep 17 00:00:00 2001 From: Zan Baldwin Date: Tue, 2 Jun 2026 21:58:17 +0200 Subject: [PATCH 3/4] =?UTF-8?q?style:=20=F0=9F=92=84=20apply=20code=20styl?= =?UTF-8?q?e=20ruleset=20to=20codebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/AbstractIP.php | 51 +--- src/Exception/InvalidCidrException.php | 8 +- src/Exception/InvalidIpAddressException.php | 12 +- src/Exception/IpException.php | 4 +- .../Strategy/ExtractionException.php | 5 - src/Exception/WrongVersionException.php | 5 +- src/Formatter/ConsistentFormatter.php | 15 +- src/Formatter/NativeFormatter.php | 10 +- src/IpInterface.php | 45 +-- src/Strategy/Compatible.php | 17 +- src/Strategy/Derived.php | 17 +- src/Strategy/Mapped.php | 15 +- src/Util/Binary.php | 32 +-- src/Version/IPv4.php | 53 +--- src/Version/IPv6.php | 59 +--- src/Version/Multi.php | 61 +---- src/Version/Version6Interface.php | 22 +- .../Formatter/ConsistentFormatter.php | 52 ++-- .../Formatter/NativeFormatter.php | 42 +-- tests/DataProvider/IPv4.php | 46 ++-- tests/DataProvider/IPv6.php | 94 +++---- .../DataProvider/IpDataProviderInterface.php | 83 +++--- tests/DataProvider/Multi.php | 220 +++++++-------- tests/DataProvider/Strategy/Compatible.php | 6 +- tests/DataProvider/Strategy/Derived.php | 6 +- tests/DataProvider/Strategy/Mapped.php | 6 +- tests/DataProvider/Util/Binary.php | 2 + tests/Formatter/ConsistentFormatterTest.php | 28 +- tests/Formatter/NativeFormatterTest.php | 28 +- tests/Strategy/CompatibleTest.php | 41 +-- tests/Strategy/DerivedTest.php | 41 +-- tests/Strategy/MappedTest.php | 41 +-- tests/Util/BinaryTest.php | 46 +--- tests/Util/MbStringTest.php | 81 ++---- tests/Version/IPv4Test.php | 201 +++----------- tests/Version/IPv6Test.php | 226 +++------------ tests/Version/MultiTest.php | 258 ++++-------------- tests/bootstrap.php | 6 +- 38 files changed, 591 insertions(+), 1394 deletions(-) diff --git a/src/AbstractIP.php b/src/AbstractIP.php index 6fa829e..b371e76 100644 --- a/src/AbstractIP.php +++ b/src/AbstractIP.php @@ -35,7 +35,7 @@ public static function setProtocolFormatter(ProtocolFormatterInterface $formatte protected static function getProtocolFormatter(): ProtocolFormatterInterface { if (null === self::$formatter) { - self::$formatter = new ConsistentFormatter; + self::$formatter = new ConsistentFormatter(); } return self::$formatter; } @@ -45,49 +45,31 @@ protected function __construct(string $ip) $this->ip = $ip; } - /** - * {@inheritDoc} - */ final public function getBinary(): string { return $this->ip; } - /** - * {@inheritDoc} - */ public function equals(IpInterface $ip): bool { return $this->getBinary() === $ip->getBinary(); } - /** - * {@inheritDoc} - */ public function isVersion(int $version): bool { return $this->getVersion() === $version; } - /** - * {@inheritDoc} - */ public function isVersion4(): bool { return $this->isVersion(4); } - /** - * {@inheritDoc} - */ public function isVersion6(): bool { return $this->isVersion(6); } - /** - * {@inheritDoc} - */ public function getNetworkIp(int $cidr) { // Providing that the CIDR is valid, bitwise AND the IP address binary @@ -98,9 +80,6 @@ public function getNetworkIp(int $cidr) )); } - /** - * {@inheritDoc} - */ public function getBroadcastIp(int $cidr) { // Providing that the CIDR is valid, bitwise OR the IP address binary @@ -111,9 +90,6 @@ public function getBroadcastIp(int $cidr) )); } - /** - * {@inheritDoc} - */ public function inRange(IpInterface $ip, int $cidr): bool { if (!$this->isSameByteLength($ip)) { @@ -130,15 +106,14 @@ public function inRange(IpInterface $ip, int $cidr): bool return $ours->getNetworkIp($cidr)->getBinary() === $theirs->getNetworkIp($cidr)->getBinary(); } - /** {@inheritDoc} */ public function getCommonCidr(IpInterface $ip): int { // Cannot calculate the greatest common CIDR between an IPv4 and // IPv6/IPv4-embedded address, they are fundamentally incompatible. if (!$this->isSameByteLength($ip)) { throw new WrongVersionException( - MbString::getLength($this->getBinary()) === 4 ? 4 : 6, - MbString::getLength($ip->getBinary()) === 4 ? 4 : 6, + 4 === MbString::getLength($this->getBinary()) ? 4 : 6, + 4 === MbString::getLength($ip->getBinary()) ? 4 : 6, (string) $ip ); } @@ -147,33 +122,21 @@ public function getCommonCidr(IpInterface $ip): int return MbString::getLength($parts[0]); } - /** - * {@inheritDoc} - */ public function isMapped(): bool { - return (new Strategy\Mapped)->isEmbedded($this->getBinary()); + return (new Strategy\Mapped())->isEmbedded($this->getBinary()); } - /** - * {@inheritDoc} - */ public function isDerived(): bool { - return (new Strategy\Derived)->isEmbedded($this->getBinary()); + return (new Strategy\Derived())->isEmbedded($this->getBinary()); } - /** - * {@inheritDoc} - */ public function isCompatible(): bool { - return (new Strategy\Compatible)->isEmbedded($this->getBinary()); + return (new Strategy\Compatible())->isEmbedded($this->getBinary()); } - /** - * {@inheritDoc} - */ public function isEmbedded(): bool { return false; @@ -193,7 +156,7 @@ protected function isSameByteLength(IpInterface $ip): bool */ protected function generateBinaryMask(int $cidr, int $lengthInBytes): string { - if ($cidr < 0 || $lengthInBytes < 0 + if ($cidr < 0 || $lengthInBytes < 0 // CIDR is measured in bits; we're describing the length in bytes. || $cidr > $lengthInBytes * 8 ) { diff --git a/src/Exception/InvalidCidrException.php b/src/Exception/InvalidCidrException.php index 99bf190..63791a6 100644 --- a/src/Exception/InvalidCidrException.php +++ b/src/Exception/InvalidCidrException.php @@ -6,12 +6,10 @@ class InvalidCidrException extends IpException { - /** @var mixed $cidr */ + /** @var mixed */ private $cidr; /** - * Constructor - * * @param mixed $cidr * @param mixed $addressLengthInBytes */ @@ -27,9 +25,7 @@ public function __construct($cidr, $addressLengthInBytes, ?\Exception $previous parent::__construct($message, 0, $previous); } - /** - * @return mixed - */ + /** @return mixed */ public function getSuppliedCidr() { return $this->cidr; diff --git a/src/Exception/InvalidIpAddressException.php b/src/Exception/InvalidIpAddressException.php index 17f35ae..983d776 100644 --- a/src/Exception/InvalidIpAddressException.php +++ b/src/Exception/InvalidIpAddressException.php @@ -6,23 +6,17 @@ class InvalidIpAddressException extends IpException { - /** @var mixed $ip */ + /** @var scalar */ private $ip; - /** - * Constructor - * - * @param scalar $ip - */ + /** @param scalar $ip */ public function __construct($ip, ?\Exception $previous = null) { $this->ip = $ip; parent::__construct('The IP address supplied is not valid.', 0, $previous); } - /** - * @return mixed - */ + /** @return scalar */ public function getSuppliedIp() { return $this->ip; diff --git a/src/Exception/IpException.php b/src/Exception/IpException.php index 418c970..a2d9ce7 100644 --- a/src/Exception/IpException.php +++ b/src/Exception/IpException.php @@ -4,6 +4,4 @@ namespace Darsyn\IP\Exception; -class IpException extends \Exception -{ -} +class IpException extends \Exception {} diff --git a/src/Exception/Strategy/ExtractionException.php b/src/Exception/Strategy/ExtractionException.php index 60bec57..198169f 100644 --- a/src/Exception/Strategy/ExtractionException.php +++ b/src/Exception/Strategy/ExtractionException.php @@ -15,11 +15,6 @@ class ExtractionException extends IpException /** @var \Darsyn\IP\Strategy\EmbeddingStrategyInterface $embeddingStrategy */ private $embeddingStrategy; - /** - * @param string $binary - * @param \Darsyn\IP\Strategy\EmbeddingStrategyInterface $embeddingStrategy - * @param \Exception|null $previous - */ public function __construct(string $binary, EmbeddingStrategyInterface $embeddingStrategy, ?\Exception $previous = null) { $this->binary = $binary; diff --git a/src/Exception/WrongVersionException.php b/src/Exception/WrongVersionException.php index 9d3732b..a9b1e77 100644 --- a/src/Exception/WrongVersionException.php +++ b/src/Exception/WrongVersionException.php @@ -12,10 +12,7 @@ class WrongVersionException extends InvalidIpAddressException /** @var int $actual */ private $actual; - /** - * @param scalar $ip - * @param \Exception|null $previous - */ + /** @param scalar $ip */ public function __construct(int $expected, int $actual, $ip, ?\Exception $previous = null) { $this->expected = $expected; diff --git a/src/Formatter/ConsistentFormatter.php b/src/Formatter/ConsistentFormatter.php index 1af5e6f..c81d299 100644 --- a/src/Formatter/ConsistentFormatter.php +++ b/src/Formatter/ConsistentFormatter.php @@ -10,16 +10,13 @@ class ConsistentFormatter extends NativeFormatter { - /** - * {@inheritDoc} - */ public function ntop(string $binary): string { $length = MbString::getLength($binary); - if ($length === 16) { + if (16 === $length) { return $this->ntopVersion6($binary); } - if ($length === 4) { + if (4 === $length) { return $this->ntopVersion4($binary); } throw new FormatException($binary); @@ -29,8 +26,8 @@ private function ntopVersion6(string $binary): string { $hex = Binary::toHex($binary); $parts = \str_split($hex, 4); - $zeroes = \array_map(function ($part) { - return $part === '0000'; + $zeroes = \array_map(static function ($part) { + return '0000' === $part; }, $parts); $length = $i = 0; $sequences = []; @@ -42,13 +39,13 @@ private function ntopVersion6(string $binary): string $maxLength = \max($sequences); $endPosition = \array_search($maxLength, $sequences, true); if (!\is_int($endPosition)) { - throw new \RuntimeException; + throw new \RuntimeException(); } $startPosition = $endPosition - $maxLength; } else { $maxLength = $startPosition = 0; } - $parts = \array_map(function ($part) { + $parts = \array_map(static function ($part) { return \ltrim($part, '0') ?: '0'; }, $parts); // RFC 5952 § 4.2.2: a single 16-bit "0" field MUST NOT be shortened to diff --git a/src/Formatter/NativeFormatter.php b/src/Formatter/NativeFormatter.php index b543d3c..fc29060 100644 --- a/src/Formatter/NativeFormatter.php +++ b/src/Formatter/NativeFormatter.php @@ -9,13 +9,10 @@ class NativeFormatter implements ProtocolFormatterInterface { - /** - * {@inheritDoc} - */ public function ntop(string $binary): string { $length = MbString::getLength($binary); - if ($length === 16 || $length === 4) { + if (16 === $length || 4 === $length) { $pack = \pack(\sprintf('A%d', $length), $binary); // $pack return type is `string|false` below PHP 8 and `string` // above PHP 8. @@ -28,9 +25,6 @@ public function ntop(string $binary): string throw new FormatException($binary); } - /** - * {@inheritDoc} - */ public function pton(string $binary): string { if (\filter_var($binary, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) { @@ -54,7 +48,7 @@ public function pton(string $binary): string return $return; } $length = MbString::getLength($binary); - if ($length === 4 || $length === 16) { + if (4 === $length || 16 === $length) { return $binary; } throw new FormatException($binary); diff --git a/src/IpInterface.php b/src/IpInterface.php index e092119..c93c318 100644 --- a/src/IpInterface.php +++ b/src/IpInterface.php @@ -13,34 +13,22 @@ interface IpInterface */ public static function factory(string $ip); - /** - * Get Binary Representation - */ + /** Get Binary Representation */ public function getBinary(): string; - /** - * Do two IP objects represent the same IP address? - */ + /** Do two IP objects represent the same IP address? */ public function equals(self $ip): bool; - /** - * Get the IP version from the binary value - */ + /** Get the IP version from the binary value */ public function getVersion(): int; - /** - * Is Version? - */ + /** Is Version? */ public function isVersion(int $version): bool; - /** - * Whether the IP is version 4 - */ + /** Whether the IP is version 4 */ public function isVersion4(): bool; - /** - * Whether the IP is version 6 - */ + /** Whether the IP is version 6 */ public function isVersion6(): bool; /** @@ -58,7 +46,6 @@ public function getNetworkIp(int $cidr); * * Get a new value object from the broadcast address of the original IP. * - * @param int $cidr * @throws \Darsyn\IP\Exception\InvalidCidrException * @return static */ @@ -86,19 +73,13 @@ public function inRange(self $ip, int $cidr): bool; */ public function getCommonCidr(self $ip): int; - /** - * Whether the IP is an IPv4-mapped IPv6 address (eg, "::ffff:7f00:1"). - */ + /** Whether the IP is an IPv4-mapped IPv6 address (eg, "::ffff:7f00:1"). */ public function isMapped(): bool; - /** - * Whether the IP is a 6to4-derived address (eg, "2002:7f00:1::"). - */ + /** Whether the IP is a 6to4-derived address (eg, "2002:7f00:1::"). */ public function isDerived(): bool; - /** - * Whether the IP is an IPv4-compatible IPv6 address (eg, `::7f00:1`). - */ + /** Whether the IP is an IPv4-compatible IPv6 address (eg, `::7f00:1`). */ public function isCompatible(): bool; /** @@ -131,9 +112,7 @@ public function isMulticast(): bool; */ public function isPrivateUse(): bool; - /** - * Whether the IP is unspecified, according to RFC 5735/RFC 2373 (IPv4/IPv6). - */ + /** Whether the IP is unspecified, according to RFC 5735/RFC 2373 (IPv4/IPv6). */ public function isUnspecified(): bool; /** @@ -157,8 +136,6 @@ public function isDocumentation(): bool; */ public function isPublicUse(): bool; - /** - * Implement string casting for IP objects. - */ + /** Implement string casting for IP objects. */ public function __toString(): string; } diff --git a/src/Strategy/Compatible.php b/src/Strategy/Compatible.php index afbb369..9a6a602 100644 --- a/src/Strategy/Compatible.php +++ b/src/Strategy/Compatible.php @@ -9,32 +9,23 @@ class Compatible implements EmbeddingStrategyInterface { - /** - * {@inheritDoc} - */ public function isEmbedded(string $binary): bool { - return MbString::getLength($binary) === 16 - && MbString::subString($binary, 0, 12) === "\0\0\0\0\0\0\0\0\0\0\0\0"; + return 16 === MbString::getLength($binary) + && "\0\0\0\0\0\0\0\0\0\0\0\0" === MbString::subString($binary, 0, 12); } - /** - * {@inheritDoc} - */ public function extract(string $binary): string { - if (MbString::getLength($binary) === 16) { + if (16 === MbString::getLength($binary)) { return MbString::subString($binary, 12, 4); } throw new StrategyException\ExtractionException($binary, $this); } - /** - * {@inheritDoc} - */ public function pack(string $binary): string { - if (MbString::getLength($binary) === 4) { + if (4 === MbString::getLength($binary)) { return "\0\0\0\0\0\0\0\0\0\0\0\0" . $binary; } throw new StrategyException\PackingException($binary, $this); diff --git a/src/Strategy/Derived.php b/src/Strategy/Derived.php index aa81154..d99503a 100644 --- a/src/Strategy/Derived.php +++ b/src/Strategy/Derived.php @@ -10,33 +10,24 @@ class Derived implements EmbeddingStrategyInterface { - /** - * {@inheritDoc} - */ public function isEmbedded(string $binary): bool { - return MbString::getLength($binary) === 16 + return 16 === MbString::getLength($binary) && MbString::subString($binary, 0, 2) === Binary::fromHex('2002') - && MbString::subString($binary, 6, 10) === "\0\0\0\0\0\0\0\0\0\0"; + && "\0\0\0\0\0\0\0\0\0\0" === MbString::subString($binary, 6, 10); } - /** - * {@inheritDoc} - */ public function extract(string $binary): string { - if (MbString::getLength($binary) === 16) { + if (16 === MbString::getLength($binary)) { return MbString::subString($binary, 2, 4); } throw new StrategyException\ExtractionException($binary, $this); } - /** - * {@inheritDoc} - */ public function pack(string $binary): string { - if (MbString::getLength($binary) === 4) { + if (4 === MbString::getLength($binary)) { return Binary::fromHex('2002') . $binary . "\0\0\0\0\0\0\0\0\0\0"; } throw new StrategyException\PackingException($binary, $this); diff --git a/src/Strategy/Mapped.php b/src/Strategy/Mapped.php index cfd3c56..4d42094 100644 --- a/src/Strategy/Mapped.php +++ b/src/Strategy/Mapped.php @@ -10,32 +10,23 @@ class Mapped implements EmbeddingStrategyInterface { - /** - * {@inheritDoc} - */ public function isEmbedded(string $binary): bool { - return MbString::getLength($binary) === 16 + return 16 === MbString::getLength($binary) && MbString::subString($binary, 0, 12) === Binary::fromHex('00000000000000000000ffff'); } - /** - * {@inheritDoc} - */ public function extract(string $binary): string { - if (MbString::getLength($binary) === 16) { + if (16 === MbString::getLength($binary)) { return MbString::subString($binary, 12, 4); } throw new StrategyException\ExtractionException($binary, $this); } - /** - * {@inheritDoc} - */ public function pack(string $binary): string { - if (MbString::getLength($binary) === 4) { + if (4 === MbString::getLength($binary)) { return Binary::fromHex('00000000000000000000ffff') . $binary; } throw new StrategyException\PackingException($binary, $this); diff --git a/src/Util/Binary.php b/src/Util/Binary.php index 70778d9..88d515a 100644 --- a/src/Util/Binary.php +++ b/src/Util/Binary.php @@ -6,24 +6,16 @@ class Binary { - /** - * @param string $hex - * @throws \InvalidArgumentException - * @return string - */ + /** @throws \InvalidArgumentException */ public static function fromHex(string $hex): string { - if (!(\ctype_xdigit($hex) || $hex === '') || MbString::getLength($hex) % 2 !== 0) { + if (!(\ctype_xdigit($hex) || '' === $hex) || 0 !== MbString::getLength($hex) % 2) { throw new \InvalidArgumentException('Valid hexadecimal string not provided.'); } return \pack('H*', \strtolower($hex)); } - /** - * @param string $binary - * @throws \InvalidArgumentException - * @return string - */ + /** @throws \InvalidArgumentException */ public static function toHex(string $binary): string { if (false === ($data = \unpack('H*', $binary)) || !is_string($hex = \reset($data))) { @@ -32,32 +24,24 @@ public static function toHex(string $binary): string return $hex; } - /** - * @param string $asciiBinarySequence - * @throws \InvalidArgumentException - * @return string - */ + /** @throws \InvalidArgumentException */ public static function fromHumanReadable(string $asciiBinarySequence): string { if (!\preg_match('/^[01]*$/', $asciiBinarySequence) - || MbString::getLength($asciiBinarySequence) % 8 !== 0 + || 0 !== MbString::getLength($asciiBinarySequence) % 8 ) { throw new \InvalidArgumentException('Valid (ASCII) binary sequence not provided.'); } - return $asciiBinarySequence === '' ? '' : static::fromHex(\implode('', \array_map(function ($byteRepresentation) { + return '' === $asciiBinarySequence ? '' : static::fromHex(\implode('', \array_map(static function ($byteRepresentation) { return MbString::padString(\dechex((int) \bindec($byteRepresentation)), 2, '0', \STR_PAD_LEFT); }, \function_exists('mb_str_split') ? \mb_str_split($asciiBinarySequence, 8, '8bit') : \str_split($asciiBinarySequence, 8)))); } - /** - * @param string $binary - * @throws \InvalidArgumentException - * @return string - */ + /** @throws \InvalidArgumentException */ public static function toHumanReadable(string $binary): string { $hex = static::toHex($binary); - return \implode('', \array_map(function ($character) { + return \implode('', \array_map(static function ($character) { return MbString::padString(\decbin((int) \hexdec($character)), 8, '0', \STR_PAD_LEFT); }, \function_exists('mb_str_split') ? \mb_str_split($hex, 2, '8bit') : \str_split($hex, 2))); } diff --git a/src/Version/IPv4.php b/src/Version/IPv4.php index cb0f332..a5e0d67 100644 --- a/src/Version/IPv4.php +++ b/src/Version/IPv4.php @@ -28,9 +28,6 @@ */ class IPv4 extends AbstractIP implements Version4Interface { - /** - * {@inheritDoc} - */ public static function factory(string $ip) { try { @@ -39,21 +36,18 @@ public static function factory(string $ip) // If the string was not 4 bytes long, then the IP supplied was // neither in protocol notation or binary sequence notation. Throw // an exception. - if (MbString::getLength($binary) !== 4) { - if (MbString::getLength($ip) !== 4) { + if (4 !== MbString::getLength($binary)) { + if (4 !== MbString::getLength($ip)) { throw new Exception\WrongVersionException(4, 6, $ip); } $binary = $ip; } - } catch(Exception\IpException $e) { + } catch (Exception\IpException $e) { throw new Exception\InvalidIpAddressException($ip, $e); } return new static($binary); } - /** - * {@inheritDoc} - */ public function getDotAddress(): string { try { @@ -63,41 +57,26 @@ public function getDotAddress(): string } } - /** - * {@inheritDoc} - */ public function getVersion(): int { return 4; } - /** - * {@inheritDoc} - */ public function isLinkLocal(): bool { return $this->inRange(new self(Binary::fromHex('a9fe0000')), 16); } - /** - * {@inheritDoc} - */ public function isLoopback(): bool { return $this->inRange(new self(Binary::fromHex('7f000000')), 8); } - /** - * {@inheritDoc} - */ public function isMulticast(): bool { return $this->inRange(new self(Binary::fromHex('e0000000')), 4); } - /** - * {@inheritDoc} - */ public function isPrivateUse(): bool { return $this->inRange(new self(Binary::fromHex('0a000000')), 8) @@ -105,25 +84,16 @@ public function isPrivateUse(): bool || $this->inRange(new self(Binary::fromHex('c0a80000')), 16); } - /** - * {@inheritDoc} - */ public function isUnspecified(): bool { - return $this->getBinary() === "\0\0\0\0"; + return "\0\0\0\0" === $this->getBinary(); } - /** - * {@inheritDoc} - */ public function isBenchmarking(): bool { return $this->inRange(new self(Binary::fromHex('c6120000')), 15); } - /** - * {@inheritDoc} - */ public function isDocumentation(): bool { return $this->inRange(new self(Binary::fromHex('c0000200')), 24) @@ -131,9 +101,6 @@ public function isDocumentation(): bool || $this->inRange(new self(Binary::fromHex('cb007100')), 24); } - /** - * {@inheritDoc} - */ public function isPublicUse(): bool { // Both 192.0.0.9 and 192.0.0.10 are globally routable, despite being in the future reserved block. @@ -161,34 +128,22 @@ public function isPublicUse(): bool && !$this->isBenchmarking(); } - /** - * {@inheritDoc} - */ public function isBroadcast(): bool { return $this->getBinary() === Binary::fromHex('ffffffff'); } - /** - * {@inheritDoc} - */ public function isShared(): bool { return $this->inRange(new self(Binary::fromHex('64400000')), 10); } - /** - * {@inheritDoc} - */ public function isFutureReserved(): bool { return $this->getBinary() !== Binary::fromHex('ffffffff') && $this->inRange(new self(Binary::fromHex('f0000000')), 4); } - /** - * {@inheritDoc} - */ public function __toString(): string { return $this->getDotAddress(); diff --git a/src/Version/IPv6.php b/src/Version/IPv6.php index 84fcbbf..970414a 100644 --- a/src/Version/IPv6.php +++ b/src/Version/IPv6.php @@ -29,10 +29,6 @@ */ class IPv6 extends AbstractIP implements Version6Interface { - - /** - * {@inheritDoc} - */ public static function factory(string $ip) { try { @@ -40,7 +36,7 @@ public static function factory(string $ip) $binary = self::getProtocolFormatter()->pton($ip); // If the string was not 4 bytes long, then the IP supplied was neither // in protocol notation or binary sequence notation. Throw an exception. - if (MbString::getLength($binary) !== 16) { + if (16 !== MbString::getLength($binary)) { throw new Exception\WrongVersionException(6, 4, $ip); } } catch (Exception\IpException $e) { @@ -50,7 +46,6 @@ public static function factory(string $ip) } /** - * @param \Darsyn\IP\Strategy\EmbeddingStrategyInterface|null $strategy * @throws \Darsyn\IP\Exception\InvalidIpAddressException * @throws \Darsyn\IP\Exception\WrongVersionException * @return static @@ -60,9 +55,6 @@ public static function fromEmbedded(string $ip, ?EmbeddingStrategyInterface $str return new static(Multi::factory($ip, $strategy)->getBinary()); } - /** - * {@inheritDoc} - */ public function getExpandedAddress(): string { // Convert the 16-byte binary sequence into a hexadecimal-string @@ -72,9 +64,6 @@ public function getExpandedAddress(): string return MbString::subString(\is_string($expanded) ? $expanded : '', 0, -1); } - /** - * {@inheritDoc} - */ public function getCompactedAddress(): string { try { @@ -84,41 +73,26 @@ public function getCompactedAddress(): string } } - /** - * {@inheritDoc} - */ public function getVersion(): int { return 6; } - /** - * {@inheritDoc} - */ public function isLinkLocal(): bool { return $this->inRange(new self(Binary::fromHex('fe800000000000000000000000000000')), 10); } - /** - * {@inheritDoc} - */ public function isLoopback(): bool { return $this->inRange(new self(Binary::fromHex('00000000000000000000000000000001')), 128); } - /** - * {@inheritDoc} - */ public function isMulticast(): bool { return $this->inRange(new self(Binary::fromHex('ff000000000000000000000000000000')), 8); } - /** - * {@inheritDoc} - */ public function getMulticastScope(): ?int { if (!$this->isMulticast()) { @@ -128,65 +102,41 @@ public function getMulticastScope(): ?int return (int) hexdec(Binary::toHex($firstSegment & Binary::fromHex('000f'))); } - /** - * {@inheritDoc} - */ public function isPrivateUse(): bool { return $this->inRange(new self(Binary::fromHex('fd000000000000000000000000000000')), 8); } - /** - * {@inheritDoc} - */ public function isUnspecified(): bool { - return $this->getBinary() === "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; + return "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" === $this->getBinary(); } - /** - * @inheritDoc - */ public function isBenchmarking(): bool { return $this->inRange(new self(Binary::fromHex('20010002000000000000000000000000')), 48); } - /** - * @inheritDoc - */ public function isDocumentation(): bool { return $this->inRange(new self(Binary::fromHex('20010db8000000000000000000000000')), 32); } - /** - * @inheritDoc - */ public function isPublicUse(): bool { - return $this->getMulticastScope() === self::MULTICAST_GLOBAL || $this->isUnicastGlobal(); + return self::MULTICAST_GLOBAL === $this->getMulticastScope() || $this->isUnicastGlobal(); } - /** - * @inheritDoc - */ public function isUniqueLocal(): bool { return $this->inRange(new self(Binary::fromHex('fc000000000000000000000000000000')), 7); } - /** - * @inheritDoc - */ public function isUnicast(): bool { return !$this->isMulticast(); } - /** - * @inheritDoc - */ public function isUnicastGlobal(): bool { return $this->isUnicast() @@ -197,9 +147,6 @@ public function isUnicastGlobal(): bool && !$this->isDocumentation(); } - /** - * {@inheritDoc} - */ public function __toString(): string { return $this->getCompactedAddress(); diff --git a/src/Version/Multi.php b/src/Version/Multi.php index a853e1a..a9844b1 100644 --- a/src/Version/Multi.php +++ b/src/Version/Multi.php @@ -40,9 +40,6 @@ class Multi extends IPv6 implements MultiVersionInterface /** @var bool $embedded */ private $embedded; - /** - * {@inheritDoc} - */ public static function setDefaultEmbeddingStrategy(EmbeddingStrategyInterface $strategy): void { self::$defaultEmbeddingStrategy = $strategy; @@ -54,13 +51,9 @@ public static function setDefaultEmbeddingStrategy(EmbeddingStrategyInterface $s */ private static function getDefaultEmbeddingStrategy(): EmbeddingStrategyInterface { - return self::$defaultEmbeddingStrategy ?: new MappedEmbeddingStrategy; + return self::$defaultEmbeddingStrategy ?: new MappedEmbeddingStrategy(); } - /** - * {@inheritDoc} - * @param \Darsyn\IP\Strategy\EmbeddingStrategyInterface $strategy - */ public static function factory(string $ip, ?EmbeddingStrategyInterface $strategy = null): self { // We need a strategy to pack version 4 addresses. @@ -72,7 +65,7 @@ public static function factory(string $ip, ?EmbeddingStrategyInterface $strategy // If the IP address is a binary sequence of 4 bytes, then pack it into // a 16 byte IPv6 binary sequence according to the embedding strategy. - if (MbString::getLength($binary) === 4) { + if (4 === MbString::getLength($binary)) { $binary = $strategy->pack($binary); } } catch (Exception\IpException $e) { @@ -81,9 +74,6 @@ public static function factory(string $ip, ?EmbeddingStrategyInterface $strategy return new static($binary, $strategy); } - /** - * {@inheritDoc} - */ protected function __construct(string $ip, ?EmbeddingStrategyInterface $strategy = null) { // Fallback to default in case this instance was created from static in @@ -92,7 +82,6 @@ protected function __construct(string $ip, ?EmbeddingStrategyInterface $strategy parent::__construct($ip); } - /** {@inheritDoc} */ public function getProtocolAppropriateAddress(): string { // If binary string contains an embedded IPv4 address, then extract it. @@ -120,13 +109,11 @@ public function getDotAddress(): string throw new Exception\WrongVersionException(4, 6, (string) $this); } - /** {@inheritDoc} */ public function getVersion(): int { return $this->isEmbedded() ? 4 : 6; } - /** {@inheritDoc} */ public function getNetworkIp(int $cidr): self { try { @@ -142,7 +129,6 @@ public function getNetworkIp(int $cidr): self return new static(parent::getNetworkIp($cidr)->getBinary(), clone $this->embeddingStrategy); } - /** {@inheritDoc} */ public function getBroadcastIp(int $cidr): self { try { @@ -158,7 +144,6 @@ public function getBroadcastIp(int $cidr): self return new static(parent::getBroadcastIp($cidr)->getBinary(), clone $this->embeddingStrategy); } - /** {@inheritDoc} */ public function inRange(IpInterface $ip, int $cidr): bool { try { @@ -175,7 +160,6 @@ public function inRange(IpInterface $ip, int $cidr): bool return parent::inRange($ip, $cidr); } - /** {@inheritDoc} */ public function getCommonCidr(IpInterface $ip): int { try { @@ -192,7 +176,6 @@ public function getCommonCidr(IpInterface $ip): int return parent::getCommonCidr($ip); } - /** {@inheritDoc} */ public function isEmbedded(): bool { if (null === $this->embedded) { @@ -201,7 +184,6 @@ public function isEmbedded(): bool return $this->embedded; } - /** {@inheritDoc} */ public function isLinkLocal(): bool { return $this->isEmbedded() @@ -209,7 +191,6 @@ public function isLinkLocal(): bool : parent::isLinkLocal(); } - /** {@inheritDoc} */ public function isLoopback(): bool { return $this->isEmbedded() @@ -225,7 +206,6 @@ public function isMulticast(): bool : parent::isMulticast(); } - /** {@inheritDoc} */ public function isPrivateUse(): bool { return $this->isEmbedded() @@ -233,7 +213,6 @@ public function isPrivateUse(): bool : parent::isPrivateUse(); } - /** {@inheritDoc} */ public function isUnspecified(): bool { return $this->isEmbedded() @@ -241,7 +220,6 @@ public function isUnspecified(): bool : parent::isUnspecified(); } - /** {@inheritDoc} */ public function isBenchmarking(): bool { return $this->isEmbedded() @@ -249,7 +227,6 @@ public function isBenchmarking(): bool : parent::isBenchmarking(); } - /** {@inheritDoc} */ public function isDocumentation(): bool { return $this->isEmbedded() @@ -257,7 +234,6 @@ public function isDocumentation(): bool : parent::isDocumentation(); } - /** {@inheritDoc} */ public function isPublicUse(): bool { return $this->isEmbedded() @@ -265,9 +241,6 @@ public function isPublicUse(): bool : parent::isPublicUse(); } - /** - * @inheritDoc - */ public function isUniqueLocal(): bool { if ($this->isEmbedded()) { @@ -276,9 +249,6 @@ public function isUniqueLocal(): bool return parent::isUniqueLocal(); } - /** - * @inheritDoc - */ public function isUnicast(): bool { if ($this->isEmbedded()) { @@ -287,9 +257,6 @@ public function isUnicast(): bool return parent::isUnicast(); } - /** - * @inheritDoc - */ public function isUnicastGlobal(): bool { if ($this->isEmbedded()) { @@ -298,9 +265,6 @@ public function isUnicastGlobal(): bool return parent::isUnicastGlobal(); } - /** - * {@inheritDoc} - */ public function isBroadcast(): bool { if ($this->isEmbedded()) { @@ -309,9 +273,6 @@ public function isBroadcast(): bool throw new Exception\WrongVersionException(4, 6, (string) $this); } - /** - * {@inheritDoc} - */ public function isShared(): bool { if ($this->isEmbedded()) { @@ -320,9 +281,6 @@ public function isShared(): bool throw new Exception\WrongVersionException(4, 6, (string) $this); } - /** - * {@inheritDoc} - */ public function isFutureReserved(): bool { if ($this->isEmbedded()) { @@ -331,33 +289,24 @@ public function isFutureReserved(): bool throw new Exception\WrongVersionException(4, 6, (string) $this); } - /** - * @throws \Darsyn\IP\Exception\Strategy\ExtractionException - */ + /** @throws \Darsyn\IP\Exception\Strategy\ExtractionException */ private function getShortBinary(): string { return $this->embeddingStrategy->extract($this->getBinary()); } - /** - * Can the supplied CIDR and current version be considered as an IPv4 operation? - */ + /** Can the supplied CIDR and current version be considered as an IPv4 operation? */ private function isVersion4WithAppropriateCidr(int $cidr): bool { return $cidr <= 32 && $this->isVersion4(); } - /** - * Can the supplied and current IP be considered as an IPv4 operation? - */ + /** Can the supplied and current IP be considered as an IPv4 operation? */ private function isVersion4CompatibleWithCurrentStrategy(IpInterface $ip): bool { return $this->isVersion4() && $ip->isVersion4() && $this->embeddingStrategy->isEmbedded($ip->getBinary()); } - /** - * {@inheritDoc} - */ public function __toString(): string { return $this->getProtocolAppropriateAddress(); diff --git a/src/Version/Version6Interface.php b/src/Version/Version6Interface.php index 65a8433..bc33026 100644 --- a/src/Version/Version6Interface.php +++ b/src/Version/Version6Interface.php @@ -8,13 +8,13 @@ interface Version6Interface extends IpInterface { - const MULTICAST_INTERFACE_LOCAL = 1; - const MULTICAST_LINK_LOCAL = 2; - const MULTICAST_REALM_LOCAL = 3; - const MULTICAST_ADMIN_LOCAL = 4; - const MULTICAST_SITE_LOCAL = 5; - const MULTICAST_ORGANIZATION_LOCAL = 8; - const MULTICAST_GLOBAL = 14; + public const MULTICAST_INTERFACE_LOCAL = 1; + public const MULTICAST_LINK_LOCAL = 2; + public const MULTICAST_REALM_LOCAL = 3; + public const MULTICAST_ADMIN_LOCAL = 4; + public const MULTICAST_SITE_LOCAL = 5; + public const MULTICAST_ORGANIZATION_LOCAL = 8; + public const MULTICAST_GLOBAL = 14; /** * Get Compacted Address @@ -43,14 +43,10 @@ public function getExpandedAddress(): string; */ public function getMulticastScope(): ?int; - /** - * Whether the IP is a unique local address, according to RFC 4193. - */ + /** Whether the IP is a unique local address, according to RFC 4193. */ public function isUniqueLocal(): bool; - /** - * Whether the IP is a unicast address, according to RFC 4291. - */ + /** Whether the IP is a unicast address, according to RFC 4291. */ public function isUnicast(): bool; /** diff --git a/tests/DataProvider/Formatter/ConsistentFormatter.php b/tests/DataProvider/Formatter/ConsistentFormatter.php index 5905fb4..c0a9c19 100644 --- a/tests/DataProvider/Formatter/ConsistentFormatter.php +++ b/tests/DataProvider/Formatter/ConsistentFormatter.php @@ -1,5 +1,7 @@ 0); }); foreach ($ipAddresses as $ipAddress => $categories) { @@ -275,10 +275,10 @@ public static function getCategoryOfIpAddresses($category, $exclude = 0) $data[] = [$ipAddress, $isIpInCategory]; $isIpInCategory ? $true++ : $false++; } - if ($true === 0) { + if (0 === $true) { throw new \DomainException('Test data only contains invalid IP addresses for the test category; supply valid cases too.'); } - if ($false === 0) { + if (0 === $false) { throw new \DomainException('Test data only contains valid IP addresses for the test category; supply invalid cases too.'); } return $data; diff --git a/tests/DataProvider/IPv6.php b/tests/DataProvider/IPv6.php index 77384d1..a93c00a 100644 --- a/tests/DataProvider/IPv6.php +++ b/tests/DataProvider/IPv6.php @@ -1,5 +1,7 @@ 0); }); foreach ($ipAddresses as $ipAddress => $categories) { @@ -327,10 +327,10 @@ public static function getCategoryOfIpAddresses($category, $exclude = 0) $data[] = [$ipAddress, $isIpInCategory]; $isIpInCategory ? $true++ : $false++; } - if ($true === 0) { + if (0 === $true) { throw new \DomainException('Test data only contains invalid IP addresses for the test category; supply valid cases too.'); } - if ($false === 0) { + if (0 === $false) { throw new \DomainException('Test data only contains valid IP addresses for the test category; supply invalid cases too.'); } return $data; diff --git a/tests/DataProvider/IpDataProviderInterface.php b/tests/DataProvider/IpDataProviderInterface.php index ad32abb..1480f39 100644 --- a/tests/DataProvider/IpDataProviderInterface.php +++ b/tests/DataProvider/IpDataProviderInterface.php @@ -1,50 +1,55 @@ - */ + /** @return array */ public static function getCategorizedIpAddresses(); - /** - * @param int $category - * @param int $exclude - * @return list - */ - public static function getCategoryOfIpAddresses($category, $exclude = 0); + /** @return list */ + public static function getCategoryOfIpAddresses(int $category, int $exclude = 0); } diff --git a/tests/DataProvider/Multi.php b/tests/DataProvider/Multi.php index 82c8072..a0ef8fe 100644 --- a/tests/DataProvider/Multi.php +++ b/tests/DataProvider/Multi.php @@ -1,5 +1,7 @@ */ public static function getValidIpVersion4Addresses() { - return array_values(array_filter(self::getValidIpAddresses(), function (array $row) { + return array_values(array_filter(self::getValidIpAddresses(), static function (array $row) { return is_string($row[4]); })); } @@ -75,12 +77,12 @@ public static function getValidIpVersion4Addresses() /** @return list */ public static function getValidIpVersion6Addresses() { - return array_values(array_filter(self::getValidIpAddresses(), function (array $row) { + return array_values(array_filter(self::getValidIpAddresses(), static function (array $row) { return !is_string($row[4]); })); } - /** @return list */ + /** @return list */ public static function getInvalidIpAddresses() { return [ @@ -99,10 +101,10 @@ public static function getInvalidIpAddresses() public static function getIpAddressVersions() { return array_merge( - array_map(function ($row) { + array_map(static function ($row) { return [$row[0], 4]; }, self::getValidIpVersion4Addresses()), - array_map(function ($row) { + array_map(static function ($row) { return [$row[0], 6]; }, self::getValidIpVersion6Addresses()) ); @@ -124,11 +126,11 @@ public static function getOutOfRangeCidrValues() public static function getNetworkIpAddresses() { return array_merge( - array_map(function ($row) { + array_map(static function ($row) { array_unshift($row, '12.34.56.78'); return $row; }, IPv4::getNetworkIpAddresses()), - array_map(function ($row) { + array_map(static function ($row) { array_unshift($row, '2001:db8::a60:8a2e:370:7334'); return $row; }, IPv6::getNetworkIpAddresses()) @@ -140,11 +142,11 @@ public static function getNetworkIpAddresses() public static function getBroadcastIpAddresses() { return array_merge( - array_map(function ($row) { + array_map(static function ($row) { array_unshift($row, '12.34.56.78'); return $row; }, IPv4::getBroadcastIpAddresses()), - array_map(function ($row) { + array_map(static function ($row) { array_unshift($row, '2001:db8::a60:8a2e:370:7334'); return $row; }, IPv6::getBroadcastIpAddresses()) @@ -177,10 +179,10 @@ public static function getCommonCidrValues() public static function getEmbeddedAddresses() { return array_merge( - array_map(function ($row) { + array_map(static function ($row) { return [$row[0], true]; }, self::getValidIpVersion4Addresses()), - array_map(function ($row) { + array_map(static function ($row) { return [$row[0], false]; }, self::getValidIpVersion6Addresses()) ); @@ -277,10 +279,10 @@ public static function getPublicUseIpAddresses() public static function getUniqueLocalIpAddresses() { return array_merge( - array_map(function ($testData) { + array_map(static function ($testData) { return [$testData[0], false, true]; }, self::getValidIpVersion4Addresses()), - array_map(function ($testData) { + array_map(static function ($testData) { $testData[] = false; return $testData; }, IPv6::getUniqueLocalIpAddressesExcludingMapped()) @@ -291,10 +293,10 @@ public static function getUniqueLocalIpAddresses() public static function getUnicastIpAddresses() { return array_merge( - array_map(function ($testData) { + array_map(static function ($testData) { return [$testData[0], false, true]; }, self::getValidIpVersion4Addresses()), - array_map(function ($testData) { + array_map(static function ($testData) { $testData[] = false; return $testData; }, IPv6::getUnicastIpAddressesExcludingMapped()) @@ -305,10 +307,10 @@ public static function getUnicastIpAddresses() public static function getUnicastGlobalIpAddresses() { return array_merge( - array_map(function ($testData) { + array_map(static function ($testData) { return [$testData[0], false, true]; }, self::getValidIpVersion4Addresses()), - array_map(function ($testData) { + array_map(static function ($testData) { $testData[] = false; return $testData; }, IPv6::getUnicastGlobalIpAddressesExcludingMapped()) @@ -319,11 +321,11 @@ public static function getUnicastGlobalIpAddresses() public static function getIsBroadcastIpAddresses() { return array_merge( - array_map(function ($testData) { + array_map(static function ($testData) { $testData[] = false; return $testData; }, IPv4::getIsBroadcastIpAddresses()), - array_map(function ($testData) { + array_map(static function ($testData) { return [$testData[0], false, true]; }, self::getValidIpVersion6Addresses()) ); @@ -333,11 +335,11 @@ public static function getIsBroadcastIpAddresses() public static function getSharedIpAddresses() { return array_merge( - array_map(function ($testData) { + array_map(static function ($testData) { $testData[] = false; return $testData; }, IPv4::getSharedIpAddresses()), - array_map(function ($testData) { + array_map(static function ($testData) { return [$testData[0], false, true]; }, self::getValidIpVersion6Addresses()) ); @@ -347,11 +349,11 @@ public static function getSharedIpAddresses() public static function getFutureReservedIpAddresses() { return array_merge( - array_map(function ($testData) { + array_map(static function ($testData) { $testData[] = false; return $testData; }, IPv4::getFutureReservedIpAddresses()), - array_map(function ($testData) { + array_map(static function ($testData) { return [$testData[0], false, true]; }, self::getValidIpVersion6Addresses()) ); @@ -361,59 +363,59 @@ public static function getFutureReservedIpAddresses() public static function getEmbeddingStrategyIpAddresses() { return [ - [Compatible::class, '0000:0000:0000:0000:0000:0000:0c22:384e', '12.34.56.78' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:770e:712c', '119.14.113.44' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:53c5:2449', '83.197.36.73' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:1276:3b28', '18.118.59.40' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:6427:4480', '100.39.68.128' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:44c0:6122', '68.192.97.34' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:8dd8:074b', '141.216.7.75' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:97c5:30cd', '151.197.48.205' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:b6ea:c58d', '182.234.197.141' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:0000:0000', '0.0.0.0' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:7163:7a89', '113.99.122.137' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:4708:d36c', '71.8.211.108' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:c8fa:3d9b', '200.250.61.155' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:db37:478d', '219.55.71.141' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:ae82:3cc4', '174.130.60.196' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:0c06:79fc', '12.6.121.252' ], - [Compatible::class, '0000:0000:0000:0000:0000:0000:ffff:ffff', '255.255.255.255' ], - - [Derived::class, '2002:0c22:384e:0000:0000:0000:0000:0000', '12.34.56.78' ], - [Derived::class, '2002:770e:712c:0000:0000:0000:0000:0000', '119.14.113.44' ], - [Derived::class, '2002:53c5:2449:0000:0000:0000:0000:0000', '83.197.36.73' ], - [Derived::class, '2002:1276:3b28:0000:0000:0000:0000:0000', '18.118.59.40' ], - [Derived::class, '2002:6427:4480:0000:0000:0000:0000:0000', '100.39.68.128' ], - [Derived::class, '2002:44c0:6122:0000:0000:0000:0000:0000', '68.192.97.34' ], - [Derived::class, '2002:8dd8:074b:0000:0000:0000:0000:0000', '141.216.7.75' ], - [Derived::class, '2002:97c5:30cd:0000:0000:0000:0000:0000', '151.197.48.205' ], - [Derived::class, '2002:b6ea:c58d:0000:0000:0000:0000:0000', '182.234.197.141' ], - [Derived::class, '2002:0000:0000:0000:0000:0000:0000:0000', '0.0.0.0' ], - [Derived::class, '2002:7163:7a89:0000:0000:0000:0000:0000', '113.99.122.137' ], - [Derived::class, '2002:4708:d36c:0000:0000:0000:0000:0000', '71.8.211.108' ], - [Derived::class, '2002:c8fa:3d9b:0000:0000:0000:0000:0000', '200.250.61.155' ], - [Derived::class, '2002:db37:478d:0000:0000:0000:0000:0000', '219.55.71.141' ], - [Derived::class, '2002:ae82:3cc4:0000:0000:0000:0000:0000', '174.130.60.196' ], - [Derived::class, '2002:0c06:79fc:0000:0000:0000:0000:0000', '12.6.121.252' ], - [Derived::class, '2002:ffff:ffff:0000:0000:0000:0000:0000', '255.255.255.255' ], - - [Mapped::class, '0000:0000:0000:0000:0000:ffff:0c22:384e', '12.34.56.78' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:770e:712c', '119.14.113.44' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:53c5:2449', '83.197.36.73' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:1276:3b28', '18.118.59.40' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:6427:4480', '100.39.68.128' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:44c0:6122', '68.192.97.34' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:8dd8:074b', '141.216.7.75' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:97c5:30cd', '151.197.48.205' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:b6ea:c58d', '182.234.197.141' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:0000:0000', '0.0.0.0' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:7163:7a89', '113.99.122.137' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:4708:d36c', '71.8.211.108' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:c8fa:3d9b', '200.250.61.155' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:db37:478d', '219.55.71.141' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:ae82:3cc4', '174.130.60.196' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:0c06:79fc', '12.6.121.252' ], - [Mapped::class, '0000:0000:0000:0000:0000:ffff:ffff:ffff', '255.255.255.255' ], + [Compatible::class, '0000:0000:0000:0000:0000:0000:0c22:384e', '12.34.56.78'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:770e:712c', '119.14.113.44'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:53c5:2449', '83.197.36.73'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:1276:3b28', '18.118.59.40'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:6427:4480', '100.39.68.128'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:44c0:6122', '68.192.97.34'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:8dd8:074b', '141.216.7.75'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:97c5:30cd', '151.197.48.205'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:b6ea:c58d', '182.234.197.141'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:0000:0000', '0.0.0.0'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:7163:7a89', '113.99.122.137'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:4708:d36c', '71.8.211.108'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:c8fa:3d9b', '200.250.61.155'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:db37:478d', '219.55.71.141'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:ae82:3cc4', '174.130.60.196'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:0c06:79fc', '12.6.121.252'], + [Compatible::class, '0000:0000:0000:0000:0000:0000:ffff:ffff', '255.255.255.255'], + + [Derived::class, '2002:0c22:384e:0000:0000:0000:0000:0000', '12.34.56.78'], + [Derived::class, '2002:770e:712c:0000:0000:0000:0000:0000', '119.14.113.44'], + [Derived::class, '2002:53c5:2449:0000:0000:0000:0000:0000', '83.197.36.73'], + [Derived::class, '2002:1276:3b28:0000:0000:0000:0000:0000', '18.118.59.40'], + [Derived::class, '2002:6427:4480:0000:0000:0000:0000:0000', '100.39.68.128'], + [Derived::class, '2002:44c0:6122:0000:0000:0000:0000:0000', '68.192.97.34'], + [Derived::class, '2002:8dd8:074b:0000:0000:0000:0000:0000', '141.216.7.75'], + [Derived::class, '2002:97c5:30cd:0000:0000:0000:0000:0000', '151.197.48.205'], + [Derived::class, '2002:b6ea:c58d:0000:0000:0000:0000:0000', '182.234.197.141'], + [Derived::class, '2002:0000:0000:0000:0000:0000:0000:0000', '0.0.0.0'], + [Derived::class, '2002:7163:7a89:0000:0000:0000:0000:0000', '113.99.122.137'], + [Derived::class, '2002:4708:d36c:0000:0000:0000:0000:0000', '71.8.211.108'], + [Derived::class, '2002:c8fa:3d9b:0000:0000:0000:0000:0000', '200.250.61.155'], + [Derived::class, '2002:db37:478d:0000:0000:0000:0000:0000', '219.55.71.141'], + [Derived::class, '2002:ae82:3cc4:0000:0000:0000:0000:0000', '174.130.60.196'], + [Derived::class, '2002:0c06:79fc:0000:0000:0000:0000:0000', '12.6.121.252'], + [Derived::class, '2002:ffff:ffff:0000:0000:0000:0000:0000', '255.255.255.255'], + + [Mapped::class, '0000:0000:0000:0000:0000:ffff:0c22:384e', '12.34.56.78'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:770e:712c', '119.14.113.44'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:53c5:2449', '83.197.36.73'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:1276:3b28', '18.118.59.40'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:6427:4480', '100.39.68.128'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:44c0:6122', '68.192.97.34'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:8dd8:074b', '141.216.7.75'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:97c5:30cd', '151.197.48.205'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:b6ea:c58d', '182.234.197.141'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:0000:0000', '0.0.0.0'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:7163:7a89', '113.99.122.137'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:4708:d36c', '71.8.211.108'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:c8fa:3d9b', '200.250.61.155'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:db37:478d', '219.55.71.141'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:ae82:3cc4', '174.130.60.196'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:0c06:79fc', '12.6.121.252'], + [Mapped::class, '0000:0000:0000:0000:0000:ffff:ffff:ffff', '255.255.255.255'], ]; } } diff --git a/tests/DataProvider/Strategy/Compatible.php b/tests/DataProvider/Strategy/Compatible.php index 99b53cb..d2339f6 100644 --- a/tests/DataProvider/Strategy/Compatible.php +++ b/tests/DataProvider/Strategy/Compatible.php @@ -1,5 +1,7 @@ */ public static function getValidIpAddresses() { - $valid = array_map(function (array $row) { + $valid = array_map(static function (array $row) { $row[1] = true; return $row; }, self::getValidSequences()); - $invalid = array_map(function (array $row) { + $invalid = array_map(static function (array $row) { $row[1] = false; return $row; }, self::getInvalidSequences()); diff --git a/tests/DataProvider/Strategy/Derived.php b/tests/DataProvider/Strategy/Derived.php index a794374..c6ee9bb 100644 --- a/tests/DataProvider/Strategy/Derived.php +++ b/tests/DataProvider/Strategy/Derived.php @@ -1,5 +1,7 @@ */ public static function getValidIpAddresses() { - $valid = array_map(function (array $row) { + $valid = array_map(static function (array $row) { $row[1] = true; return $row; }, self::getValidSequences()); - $invalid = array_map(function (array $row) { + $invalid = array_map(static function (array $row) { $row[1] = false; return $row; }, self::getInvalidSequences()); diff --git a/tests/DataProvider/Strategy/Mapped.php b/tests/DataProvider/Strategy/Mapped.php index b00d997..d9efada 100644 --- a/tests/DataProvider/Strategy/Mapped.php +++ b/tests/DataProvider/Strategy/Mapped.php @@ -1,5 +1,7 @@ */ public static function getValidIpAddresses() { - $valid = array_map(function (array $row) { + $valid = array_map(static function (array $row) { $row[1] = true; return $row; }, self::getValidSequences()); - $invalid = array_map(function (array $row) { + $invalid = array_map(static function (array $row) { $row[1] = false; return $row; }, self::getInvalidSequences()); diff --git a/tests/DataProvider/Util/Binary.php b/tests/DataProvider/Util/Binary.php index 24c30b7..a5c272e 100644 --- a/tests/DataProvider/Util/Binary.php +++ b/tests/DataProvider/Util/Binary.php @@ -1,5 +1,7 @@ formatter = new Formatter; + $this->formatter = new Formatter(); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testFormatterIsInstanceOfInterface() + public function testFormatterIsInstanceOfInterface(): void { $this->assertInstanceOf(ProtocolFormatterInterface::class, $this->formatter); } @@ -37,13 +33,10 @@ public function testFormatterIsInstanceOfInterface() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Formatter\ConsistentFormatter::getValidBinarySequences() - * @param string $value - * @param string $expected - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(ConsistentFormatterDataProvider::class, 'getValidBinarySequences')] - public function testFormatterReturnsCorrectProtocolString($value, $expected) + public function testFormatterReturnsCorrectProtocolString(string $value, string $expected): void { $this->assertSame($expected, $this->formatter->ntop($value)); } @@ -51,16 +44,13 @@ public function testFormatterReturnsCorrectProtocolString($value, $expected) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Formatter\ConsistentFormatter::getInvalidBinarySequences() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(ConsistentFormatterDataProvider::class, 'getInvalidBinarySequences')] - public function testFormatterThrowsExceptionOnInvalidBinarySequences($value) + public function testFormatterThrowsExceptionOnInvalidBinarySequences(string $value): void { $this->expectException(\Darsyn\IP\Exception\Formatter\FormatException::class); try { - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->formatter->ntop($value); } catch (FormatException $e) { $this->assertSame($value, $e->getSuppliedBinary()); diff --git a/tests/Formatter/NativeFormatterTest.php b/tests/Formatter/NativeFormatterTest.php index 0194f0d..3292028 100644 --- a/tests/Formatter/NativeFormatterTest.php +++ b/tests/Formatter/NativeFormatterTest.php @@ -1,5 +1,7 @@ formatter = new Formatter; + $this->formatter = new Formatter(); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testFormatterIsInstanceOfInterface() + public function testFormatterIsInstanceOfInterface(): void { $this->assertInstanceOf(ProtocolFormatterInterface::class, $this->formatter); } @@ -37,13 +33,10 @@ public function testFormatterIsInstanceOfInterface() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Formatter\NativeFormatter::getValidBinarySequences() - * @param string $value - * @param string $expected - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(NativeFormatterDataProvider::class, 'getValidBinarySequences')] - public function testFormatterReturnsCorrectProtocolString($value, $expected) + public function testFormatterReturnsCorrectProtocolString(string $value, string $expected): void { $this->assertSame($expected, $this->formatter->ntop($value)); } @@ -51,16 +44,13 @@ public function testFormatterReturnsCorrectProtocolString($value, $expected) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Formatter\NativeFormatter::getInvalidBinarySequences() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(NativeFormatterDataProvider::class, 'getInvalidBinarySequences')] - public function testFormatterThrowsExceptionOnInvalidBinarySequences($value) + public function testFormatterThrowsExceptionOnInvalidBinarySequences(string $value): void { $this->expectException(\Darsyn\IP\Exception\Formatter\FormatException::class); try { - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->formatter->ntop($value); } catch (FormatException $e) { $this->assertSame($value, $e->getSuppliedBinary()); diff --git a/tests/Strategy/CompatibleTest.php b/tests/Strategy/CompatibleTest.php index 836220f..35190e0 100644 --- a/tests/Strategy/CompatibleTest.php +++ b/tests/Strategy/CompatibleTest.php @@ -1,5 +1,7 @@ strategy = new Compatible; + $this->strategy = new Compatible(); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Compatible::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(CompatibleDataProvider::class, 'getInvalidIpAddresses')] - public function testIsEmbeddedReturnsFalseForAStringOtherThan16BytesLong($value) + public function testIsEmbeddedReturnsFalseForAStringOtherThan16BytesLong(string $value): void { - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->assertFalse($this->strategy->isEmbedded($value)); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Compatible::getValidIpAddresses() - * @param string $value - * @param bool $isEmbedded - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(CompatibleDataProvider::class, 'getValidIpAddresses')] - public function testIsEmbedded($value, $isEmbedded) + public function testIsEmbedded(string $value, bool $isEmbedded): void { $this->assertSame($isEmbedded, $this->strategy->isEmbedded($value)); } @@ -55,16 +48,13 @@ public function testIsEmbedded($value, $isEmbedded) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Compatible::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(CompatibleDataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownWhenTryingToExtractFromStringsNot16Bytes($value) + public function testExceptionIsThrownWhenTryingToExtractFromStringsNot16Bytes(string $value): void { $this->expectException(\Darsyn\IP\Exception\Strategy\ExtractionException::class); try { - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->strategy->extract($value); } catch (ExtractionException $e) { $this->assertSame($this->strategy, $e->getEmbeddingStrategy()); @@ -77,13 +67,10 @@ public function testExceptionIsThrownWhenTryingToExtractFromStringsNot16Bytes($v /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Compatible::getValidSequences() - * @param string $ipv6 - * @param string $ipv4 - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(CompatibleDataProvider::class, 'getValidSequences')] - public function testCorrectSequenceExtractedFromIpBinary($ipv6, $ipv4) + public function testCorrectSequenceExtractedFromIpBinary(string $ipv6, string $ipv4): void { $this->assertSame($ipv4, $this->strategy->extract($ipv6)); } @@ -91,16 +78,13 @@ public function testCorrectSequenceExtractedFromIpBinary($ipv6, $ipv4) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Compatible::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(CompatibleDataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownWhenTryingToPackStringsNot4Bytes($value) + public function testExceptionIsThrownWhenTryingToPackStringsNot4Bytes(string $value): void { $this->expectException(\Darsyn\IP\Exception\Strategy\PackingException::class); try { - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->strategy->pack($value); } catch (PackingException $e) { $this->assertSame($this->strategy, $e->getEmbeddingStrategy()); @@ -113,13 +97,10 @@ public function testExceptionIsThrownWhenTryingToPackStringsNot4Bytes($value) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Compatible::getValidSequences() - * @param string $ipv6 - * @param string $ipv4 - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(CompatibleDataProvider::class, 'getValidSequences')] - public function testSequenceCorrectlyPackedIntoIpBinaryFromIpBinary($ipv6, $ipv4) + public function testSequenceCorrectlyPackedIntoIpBinaryFromIpBinary(string $ipv6, string $ipv4): void { $this->assertSame($ipv6, $this->strategy->pack($ipv4)); } diff --git a/tests/Strategy/DerivedTest.php b/tests/Strategy/DerivedTest.php index 5222cbd..33d9ab8 100644 --- a/tests/Strategy/DerivedTest.php +++ b/tests/Strategy/DerivedTest.php @@ -1,5 +1,7 @@ strategy = new Derived; + $this->strategy = new Derived(); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Derived::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(DerivedDataProvider::class, 'getInvalidIpAddresses')] - public function testIsEmbeddedReturnsFalseForAStringOtherThan16BytesLong($value) + public function testIsEmbeddedReturnsFalseForAStringOtherThan16BytesLong(string $value): void { - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->assertFalse($this->strategy->isEmbedded($value)); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Derived::getValidIpAddresses() - * @param string $value - * @param bool $isEmbedded - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(DerivedDataProvider::class, 'getValidIpAddresses')] - public function testIsEmbedded($value, $isEmbedded) + public function testIsEmbedded(string $value, bool $isEmbedded): void { $this->assertSame($isEmbedded, $this->strategy->isEmbedded($value)); } @@ -53,28 +46,22 @@ public function testIsEmbedded($value, $isEmbedded) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Derived::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(DerivedDataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownWhenTryingToExtractFromStringsNot16Bytes($value) + public function testExceptionIsThrownWhenTryingToExtractFromStringsNot16Bytes(string $value): void { $this->expectException(\Darsyn\IP\Exception\Strategy\ExtractionException::class); - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->strategy->extract($value); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Derived::getValidSequences() - * @param string $ipv6 - * @param string $ipv4 - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(DerivedDataProvider::class, 'getValidSequences')] - public function testCorrectSequenceExtractedFromIpBinary($ipv6, $ipv4) + public function testCorrectSequenceExtractedFromIpBinary(string $ipv6, string $ipv4): void { $this->assertSame($ipv4, $this->strategy->extract($ipv6)); } @@ -82,28 +69,22 @@ public function testCorrectSequenceExtractedFromIpBinary($ipv6, $ipv4) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Derived::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(DerivedDataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownWhenTryingToPackStringsNot4Bytes($value) + public function testExceptionIsThrownWhenTryingToPackStringsNot4Bytes(string $value): void { $this->expectException(\Darsyn\IP\Exception\Strategy\PackingException::class); - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->strategy->pack($value); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Derived::getValidSequences() - * @param string $ipv6 - * @param string $ipv4 - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(DerivedDataProvider::class, 'getValidSequences')] - public function testSequenceCorrectlyPackedIntoIpBinaryFromIpBinary($ipv6, $ipv4) + public function testSequenceCorrectlyPackedIntoIpBinaryFromIpBinary(string $ipv6, string $ipv4): void { $this->assertSame($ipv6, $this->strategy->pack($ipv4)); } diff --git a/tests/Strategy/MappedTest.php b/tests/Strategy/MappedTest.php index ea2afd4..1b50a59 100644 --- a/tests/Strategy/MappedTest.php +++ b/tests/Strategy/MappedTest.php @@ -1,5 +1,7 @@ strategy = new Mapped; + $this->strategy = new Mapped(); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Mapped::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MappedDataProvider::class, 'getInvalidIpAddresses')] - public function testIsEmbeddedReturnsFalseForAStringOtherThan16BytesLong($value) + public function testIsEmbeddedReturnsFalseForAStringOtherThan16BytesLong(string $value): void { - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->assertFalse($this->strategy->isEmbedded($value)); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Mapped::getValidIpAddresses() - * @param string $value - * @param bool $isEmbedded - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MappedDataProvider::class, 'getValidIpAddresses')] - public function testIsEmbedded($value, $isEmbedded) + public function testIsEmbedded(string $value, bool $isEmbedded): void { $this->assertSame($isEmbedded, $this->strategy->isEmbedded($value)); } @@ -53,28 +46,22 @@ public function testIsEmbedded($value, $isEmbedded) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Mapped::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MappedDataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownWhenTryingToExtractFromStringsNot16Bytes($value) + public function testExceptionIsThrownWhenTryingToExtractFromStringsNot16Bytes(string $value): void { $this->expectException(\Darsyn\IP\Exception\Strategy\ExtractionException::class); - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->strategy->extract($value); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Mapped::getValidSequences() - * @param string $ipv6 - * @param string $ipv4 - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MappedDataProvider::class, 'getValidSequences')] - public function testCorrectSequenceExtractedFromIpBinary($ipv6, $ipv4) + public function testCorrectSequenceExtractedFromIpBinary(string $ipv6, string $ipv4): void { $this->assertSame($ipv4, $this->strategy->extract($ipv6)); } @@ -82,28 +69,22 @@ public function testCorrectSequenceExtractedFromIpBinary($ipv6, $ipv4) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Mapped::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MappedDataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownWhenTryingToPackStringsNot4Bytes($value) + public function testExceptionIsThrownWhenTryingToPackStringsNot4Bytes(string $value): void { $this->expectException(\Darsyn\IP\Exception\Strategy\PackingException::class); - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ $this->strategy->pack($value); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Strategy\Mapped::getValidSequences() - * @param string $ipv6 - * @param string $ipv4 - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MappedDataProvider::class, 'getValidSequences')] - public function testSequenceCorrectlyPackedIntoIpBinaryFromIpBinary($ipv6, $ipv4) + public function testSequenceCorrectlyPackedIntoIpBinaryFromIpBinary(string $ipv6, string $ipv4): void { $this->assertSame($ipv6, $this->strategy->pack($ipv4)); } diff --git a/tests/Util/BinaryTest.php b/tests/Util/BinaryTest.php index 3a9d2b4..dda28a7 100644 --- a/tests/Util/BinaryTest.php +++ b/tests/Util/BinaryTest.php @@ -1,5 +1,7 @@ expectException(\InvalidArgumentException::class); - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ Binary::fromHex($input); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Util\Binary::getInvalidHumanReadable() - * @param mixed $input - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(BinaryDataProvider::class, 'getInvalidHumanReadable')] - public function testInvalidHumanReadableInput($input) + public function testInvalidHumanReadableInput(string $input): void { $this->expectException(\InvalidArgumentException::class); - /** @phpstan-ignore-next-line (@phpstan-ignore argument.type) */ Binary::fromHumanReadable($input); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testEmptyHexInput() + public function testEmptyHexInput(): void { $this->assertSame('', Binary::fromHex('')); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testEmptyHumanReadableInput() + public function testEmptyHumanReadableInput(): void { $this->assertSame('', Binary::fromHumanReadable('')); } @@ -62,13 +52,10 @@ public function testEmptyHumanReadableInput() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Util\Binary::getBinaryData() - * @param string $hex - * @param string $humanReadable - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(BinaryDataProvider::class, 'getBinaryData')] - public function testHexCanConvertAndBackAgain($hex, $humanReadable) + public function testHexCanConvertAndBackAgain(string $hex, string $humanReadable): void { $converted = Binary::fromHex($hex); $this->assertSame(strtolower($hex), Binary::toHex($converted)); @@ -77,13 +64,10 @@ public function testHexCanConvertAndBackAgain($hex, $humanReadable) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Util\Binary::getBinaryData() - * @param string $hex - * @param string $humanReadable - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(BinaryDataProvider::class, 'getBinaryData')] - public function testHumanReadableCanConvertAndBackAgain($hex, $humanReadable) + public function testHumanReadableCanConvertAndBackAgain(string $hex, string $humanReadable): void { $converted = Binary::fromHumanReadable($humanReadable); $this->assertSame($humanReadable, Binary::toHumanReadable($converted)); @@ -92,13 +76,10 @@ public function testHumanReadableCanConvertAndBackAgain($hex, $humanReadable) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Util\Binary::getBinaryData() - * @param string $hex - * @param string $humanReadable - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(BinaryDataProvider::class, 'getBinaryData')] - public function testHexCanConvertToHumanReadable($hex, $humanReadable) + public function testHexCanConvertToHumanReadable(string $hex, string $humanReadable): void { $converted = Binary::fromHex($hex); $this->assertSame($humanReadable, Binary::toHumanReadable($converted)); @@ -107,13 +88,10 @@ public function testHexCanConvertToHumanReadable($hex, $humanReadable) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Util\Binary::getBinaryData() - * @param string $hex - * @param string $humanReadable - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(BinaryDataProvider::class, 'getBinaryData')] - public function testHumanReadableCanConvertToHex($hex, $humanReadable) + public function testHumanReadableCanConvertToHex(string $hex, string $humanReadable): void { $converted = Binary::fromHumanReadable($humanReadable); $this->assertSame(strtolower($hex), Binary::toHex($converted)); diff --git a/tests/Util/MbStringTest.php b/tests/Util/MbStringTest.php index bef5b91..a6127fa 100644 --- a/tests/Util/MbStringTest.php +++ b/tests/Util/MbStringTest.php @@ -1,5 +1,7 @@ assertSame(13, MbString::getLength('Hello, World!')); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testGetLengthUnicodeCharacter() + public function testGetLengthUnicodeCharacter(): void { $this->assertSame(7 + self::EMOJI_BYTES, MbString::getLength('Hello! ' . self::EMOJI)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testGetLengthGraphemeCluster() + public function testGetLengthGraphemeCluster(): void { $this->assertSame(15 + self::GRAPHEME_CLUSTER_BYTES, MbString::getLength('Harriet Potter ' . self::GRAPHEME_CLUSTER)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testSubStringAscii() + public function testSubStringAscii(): void { $text = 'Hello, World!'; $substring = MbString::subString($text, 3); @@ -58,12 +47,9 @@ public function testSubStringAscii() $this->assertSame('lo, World!', $substring); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testSubStringUnicodeCharacter() + public function testSubStringUnicodeCharacter(): void { $text = 'Hello! ' . self::EMOJI; $substring = MbString::subString($text, 5, 4); @@ -71,12 +57,9 @@ public function testSubStringUnicodeCharacter() $this->assertSame('! ' . Binary::fromHex('f09f'), $substring); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testSubStringGraphemeCluster() + public function testSubStringGraphemeCluster(): void { $text = 'Harriet Potter ' . self::GRAPHEME_CLUSTER; $substring = MbString::subString($text, 11, 10); @@ -84,48 +67,36 @@ public function testSubStringGraphemeCluster() $this->assertSame('ter ' . Binary::fromHex('f09fa799e280'), $substring); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testSubStringPreservesZeroByte() + public function testSubStringPreservesZeroByte(): void { $this->assertSame('0', MbString::subString('0', 0, 1)); $this->assertSame('0', MbString::subString('0', 0)); $this->assertSame('0', MbString::subString('109', 1, 1)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testPadStringAscii() + public function testPadStringAscii(): void { $this->assertSame('-0--Hello', $result = MbString::padString('Hello', 9, '-0-', STR_PAD_LEFT)); $this->assertSame('Hello-0--', $result = MbString::padString('Hello', 9, '-0-', STR_PAD_RIGHT)); $this->assertSame('-0Hello-0', $result = MbString::padString('Hello', 9, '-0-', STR_PAD_BOTH)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testPadStringUnicodeCharacter() + public function testPadStringUnicodeCharacter(): void { $this->assertSame('---' . self::EMOJI, MbString::padString(self::EMOJI, 3 + self::EMOJI_BYTES, '-', STR_PAD_LEFT)); $this->assertSame(self::EMOJI . '---', MbString::padString(self::EMOJI, 3 + self::EMOJI_BYTES, '-', STR_PAD_RIGHT)); $this->assertSame('-' . self::EMOJI . '--', MbString::padString(self::EMOJI, 3 + self::EMOJI_BYTES, '-', STR_PAD_BOTH)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testPadStringGraphemeCluster() + public function testPadStringGraphemeCluster(): void { $this->assertSame('--' . self::GRAPHEME_CLUSTER, MbString::padString(self::GRAPHEME_CLUSTER, 2 + self::GRAPHEME_CLUSTER_BYTES, '-', STR_PAD_LEFT)); $this->assertSame(self::GRAPHEME_CLUSTER . '--', MbString::padString(self::GRAPHEME_CLUSTER, 2 + self::GRAPHEME_CLUSTER_BYTES, '-', STR_PAD_RIGHT)); diff --git a/tests/Version/IPv4Test.php b/tests/Version/IPv4Test.php index 88fd80d..a271766 100644 --- a/tests/Version/IPv4Test.php +++ b/tests/Version/IPv4Test.php @@ -1,5 +1,7 @@ assertInstanceOf(IpInterface::class, $ip); @@ -35,14 +33,10 @@ public function testInstantiationWithValidAddresses($value, $expectedHex, $expec /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidBinarySequences() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidBinarySequences')] - public function testBinarySequenceIsTheSameOnceInstantiated($value, $expectedHex, $expectedDot) + public function testBinarySequenceIsTheSameOnceInstantiated(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertSame($value, $ip->getBinary()); @@ -51,14 +45,10 @@ public function testBinarySequenceIsTheSameOnceInstantiated($value, $expectedHex /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidProtocolIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidProtocolIpAddresses')] - public function testProtocolNotationConvertsToCorrectBinarySequence($value, $expectedHex, $expectedDot) + public function testProtocolNotationConvertsToCorrectBinarySequence(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $actualHex = unpack('H*hex', $ip->getBinary()); @@ -68,17 +58,14 @@ public function testProtocolNotationConvertsToCorrectBinarySequence($value, $exp /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value) + public function testExceptionIsThrownOnInstantiationWithInvalidAddresses(string $value): void { $this->expectException(\Darsyn\IP\Exception\InvalidIpAddressException::class); $this->expectExceptionMessage('The IP address supplied is not valid.'); try { - // @phpstan-ignore argument.type IP::factory($value); } catch (InvalidIpAddressException $e) { $this->assertSame($value, $e->getSuppliedIp()); @@ -90,14 +77,10 @@ public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testGetBinaryAlwaysReturnsA4ByteString($value, $expectedHex, $expectedDot) + public function testGetBinaryAlwaysReturnsA4ByteString(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertSame(4, strlen(bin2hex($ip->getBinary())) / 2); @@ -106,14 +89,10 @@ public function testGetBinaryAlwaysReturnsA4ByteString($value, $expectedHex, $ex /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testDotAddressReturnsCorrectString($value, $expectedHex, $expectedDot) + public function testDotAddressReturnsCorrectString(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertSame($expectedDot, $ip->getDotAddress()); @@ -122,14 +101,10 @@ public function testDotAddressReturnsCorrectString($value, $expectedHex, $expect /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testGetVersionAlwaysReturns4($value, $expectedHex, $expectedDot) + public function testGetVersionAlwaysReturns4(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertSame(4, $ip->getVersion()); @@ -138,14 +113,10 @@ public function testGetVersionAlwaysReturns4($value, $expectedHex, $expectedDot) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testIsVersionOnlyReturnsTrueFor4($value, $expectedHex, $expectedDot) + public function testIsVersionOnlyReturnsTrueFor4(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertTrue($ip->isVersion(4)); @@ -154,14 +125,10 @@ public function testIsVersionOnlyReturnsTrueFor4($value, $expectedHex, $expected /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testIsVersionOnlyReturnsFalseFor6($value, $expectedHex, $expectedDot) + public function testIsVersionOnlyReturnsFalseFor6(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertFalse($ip->isVersion(6)); @@ -170,14 +137,10 @@ public function testIsVersionOnlyReturnsFalseFor6($value, $expectedHex, $expecte /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testIsVersion4AlwaysReturnsTrue($value, $expectedHex, $expectedDot) + public function testIsVersion4AlwaysReturnsTrue(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertTrue($ip->isVersion4()); @@ -186,14 +149,10 @@ public function testIsVersion4AlwaysReturnsTrue($value, $expectedHex, $expectedD /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testIsVersion6AlwaysReturnsFalse($value, $expectedHex, $expectedDot) + public function testIsVersion6AlwaysReturnsFalse(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertFalse($ip->isVersion6()); @@ -202,13 +161,10 @@ public function testIsVersion6AlwaysReturnsFalse($value, $expectedHex, $expected /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidCidrValues() - * @param int $cidr - * @param string $expectedMaskHex - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidCidrValues')] - public function testCidrMasks($cidr, $expectedMaskHex) + public function testCidrMasks(int $cidr, string $expectedMaskHex): void { $ip = IP::factory('12.34.56.78'); $mask = (function () use ($cidr): string { @@ -221,12 +177,10 @@ public function testCidrMasks($cidr, $expectedMaskHex) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getOutOfRangeCidrValues() - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getOutOfRangeCidrValues')] - public function testExceptionIsThrownFromOutOfRangeCidrValues($cidr) + public function testExceptionIsThrownFromOutOfRangeCidrValues(int $cidr): void { $this->expectException(\Darsyn\IP\Exception\InvalidCidrException::class); $this->expectExceptionMessage('The supplied CIDR is not valid; it must be an integer (between 0 and 32).'); @@ -245,13 +199,10 @@ public function testExceptionIsThrownFromOutOfRangeCidrValues($cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getNetworkIpAddresses() - * @param string $expected - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getNetworkIpAddresses')] - public function testNetworkIp($expected, $cidr) + public function testNetworkIp(string $expected, int $cidr): void { $ip = IP::factory('12.34.56.78'); $this->assertSame($expected, $ip->getNetworkIp($cidr)->getDotAddress()); @@ -260,13 +211,10 @@ public function testNetworkIp($expected, $cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getBroadcastIpAddresses() - * @param string $expected - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getBroadcastIpAddresses')] - public function testBroadcastIp($expected, $cidr) + public function testBroadcastIp(string $expected, int $cidr): void { $ip = IP::factory('12.34.56.78'); $this->assertSame($expected, $ip->getBroadcastIp($cidr)->getDotAddress()); @@ -275,14 +223,10 @@ public function testBroadcastIp($expected, $cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidInRangeIpAddresses() - * @param string $first - * @param string $second - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidInRangeIpAddresses')] - public function testInRange($first, $second, $cidr) + public function testInRange(string $first, string $second, int $cidr): void { $first = IP::factory($first); $second = IP::factory($second); @@ -292,12 +236,10 @@ public function testInRange($first, $second, $cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getOutOfRangeCidrValues() - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getOutOfRangeCidrValues')] - public function testInRangeThrowsExceptionOnOutOfRangeCidr($cidr) + public function testInRangeThrowsExceptionOnOutOfRangeCidr(int $cidr): void { $first = IP::factory('12.34.56.78'); $second = IP::factory('12.34.56.78'); @@ -305,12 +247,9 @@ public function testInRangeThrowsExceptionOnOutOfRangeCidr($cidr) $first->inRange($second, $cidr); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testDifferentVersionsAreNotInRange() + public function testDifferentVersionsAreNotInRange(): void { $ip = IP::factory('12.34.56.78'); $other = IPv6::factory('::12.34.56.78'); @@ -321,26 +260,19 @@ public function testDifferentVersionsAreNotInRange() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getCommonCidrValues() - * @param string $first - * @param string $second - * @param int $expectedCidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getCommonCidrValues')] - public function testCommonCidr($first, $second, $expectedCidr) + public function testCommonCidr(string $first, string $second, int $expectedCidr): void { $first = IP::factory($first); $second = IP::factory($second); $this->assertSame($expectedCidr, $first->getCommonCidr($second)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testCommonCidrThrowsException() + public function testCommonCidrThrowsException(): void { $first = IP::factory('12.34.56.78'); $second = IPv6::factory('2001:db8::a60:8a2e:370:7334'); @@ -351,14 +283,10 @@ public function testCommonCidrThrowsException() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testIsMappedAlwaysReturnsFalse($value, $expectedHex, $expectedDot) + public function testIsMappedAlwaysReturnsFalse(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertFalse($ip->isMapped()); @@ -367,14 +295,10 @@ public function testIsMappedAlwaysReturnsFalse($value, $expectedHex, $expectedDo /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testIsDerivedAlwaysReturnsFalse($value, $expectedHex, $expectedDot) + public function testIsDerivedAlwaysReturnsFalse(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertFalse($ip->isDerived()); @@ -383,14 +307,10 @@ public function testIsDerivedAlwaysReturnsFalse($value, $expectedHex, $expectedD /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testIsCompatibleAlwaysReturnsFalse($value, $expectedHex, $expectedDot) + public function testIsCompatibleAlwaysReturnsFalse(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertFalse($ip->isCompatible()); @@ -399,14 +319,10 @@ public function testIsCompatibleAlwaysReturnsFalse($value, $expectedHex, $expect /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testIsEmbeddedAlwaysReturnsFalse($value, $expectedHex, $expectedDot) + public function testIsEmbeddedAlwaysReturnsFalse(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertFalse($ip->isEmbedded()); @@ -415,13 +331,10 @@ public function testIsEmbeddedAlwaysReturnsFalse($value, $expectedHex, $expected /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getLinkLocalIpAddresses() - * @param string $value - * @param bool $isLinkLocal - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getLinkLocalIpAddresses')] - public function testIsLinkLocal($value, $isLinkLocal) + public function testIsLinkLocal(string $value, bool $isLinkLocal): void { $ip = IP::factory($value); $this->assertSame($isLinkLocal, $ip->isLinkLocal()); @@ -430,13 +343,10 @@ public function testIsLinkLocal($value, $isLinkLocal) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getLoopbackIpAddresses() - * @param string $value - * @param bool $isLoopback - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getLoopbackIpAddresses')] - public function testIsLoopback($value, $isLoopback) + public function testIsLoopback(string $value, bool $isLoopback): void { $ip = IP::factory($value); $this->assertSame($isLoopback, $ip->isLoopback()); @@ -445,13 +355,10 @@ public function testIsLoopback($value, $isLoopback) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getMulticastIpAddresses() - * @param string $value - * @param bool $isMulticast - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getMulticastIpAddresses')] - public function testIsMulticast($value, $isMulticast) + public function testIsMulticast(string $value, bool $isMulticast): void { $ip = IP::factory($value); $this->assertSame($isMulticast, $ip->isMulticast()); @@ -461,13 +368,10 @@ public function testIsMulticast($value, $isMulticast) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getPrivateUseIpAddresses() - * @param string $value - * @param bool $isPrivateUse - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getPrivateUseIpAddresses')] - public function testIsPrivateUse($value, $isPrivateUse) + public function testIsPrivateUse(string $value, bool $isPrivateUse): void { $ip = IP::factory($value); $this->assertSame($isPrivateUse, $ip->isPrivateUse()); @@ -476,13 +380,10 @@ public function testIsPrivateUse($value, $isPrivateUse) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getUnspecifiedIpAddresses() - * @param string $value - * @param bool $isUnspecified - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getUnspecifiedIpAddresses')] - public function testIsUnspecified($value, $isUnspecified) + public function testIsUnspecified(string $value, bool $isUnspecified): void { $ip = IP::factory($value); $this->assertSame($isUnspecified, $ip->isUnspecified()); @@ -491,13 +392,10 @@ public function testIsUnspecified($value, $isUnspecified) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getBenchmarkingIpAddresses() - * @param string $value - * @param bool $isBenchmarking - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getBenchmarkingIpAddresses')] - public function testIsBenchmarking($value, $isBenchmarking) + public function testIsBenchmarking(string $value, bool $isBenchmarking): void { $ip = IP::factory($value); $this->assertSame($isBenchmarking, $ip->isBenchmarking()); @@ -506,13 +404,10 @@ public function testIsBenchmarking($value, $isBenchmarking) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getDocumentationIpAddresses() - * @param string $value - * @param bool $isDocumentation - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getDocumentationIpAddresses')] - public function testIsDocumentation($value, $isDocumentation) + public function testIsDocumentation(string $value, bool $isDocumentation): void { $ip = IP::factory($value); $this->assertSame($isDocumentation, $ip->isDocumentation()); @@ -521,13 +416,10 @@ public function testIsDocumentation($value, $isDocumentation) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getPublicUseIpAddresses() - * @param string $value - * @param bool $isPublicUse - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getPublicUseIpAddresses')] - public function testIsPublicUse($value, $isPublicUse) + public function testIsPublicUse(string $value, bool $isPublicUse): void { $ip = IP::factory($value); $this->assertSame($isPublicUse, $ip->isPublicUse()); @@ -536,13 +428,10 @@ public function testIsPublicUse($value, $isPublicUse) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getIsBroadcastIpAddresses() - * @param string $value - * @param bool $isBroadcast - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getIsBroadcastIpAddresses')] - public function testIsBroadcast($value, $isBroadcast) + public function testIsBroadcast(string $value, bool $isBroadcast): void { $ip = IP::factory($value); $this->assertSame($isBroadcast, $ip->isBroadcast()); @@ -551,13 +440,10 @@ public function testIsBroadcast($value, $isBroadcast) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getSharedIpAddresses() - * @param string $value - * @param bool $isShared - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getSharedIpAddresses')] - public function testIsShared($value, $isShared) + public function testIsShared(string $value, bool $isShared): void { $ip = IP::factory($value); $this->assertSame($isShared, $ip->isShared()); @@ -566,13 +452,10 @@ public function testIsShared($value, $isShared) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getFutureReservedIpAddresses() - * @param string $value - * @param bool $isFutureReserved - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getFutureReservedIpAddresses')] - public function testIsFutureReserved($value, $isFutureReserved) + public function testIsFutureReserved(string $value, bool $isFutureReserved): void { $ip = IP::factory($value); $this->assertSame($isFutureReserved, $ip->isFutureReserved()); @@ -581,14 +464,10 @@ public function testIsFutureReserved($value, $isFutureReserved) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getValidIpAddresses() - * @param string $value - * @param string $expectedHex - * @param string $expectedDot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getValidIpAddresses')] - public function testStringCasting($value, $expectedHex, $expectedDot) + public function testStringCasting(string $value, string $expectedHex, string $expectedDot): void { $ip = IP::factory($value); $this->assertSame($expectedDot, (string) $ip); diff --git a/tests/Version/IPv6Test.php b/tests/Version/IPv6Test.php index aaf147d..58a30bf 100644 --- a/tests/Version/IPv6Test.php +++ b/tests/Version/IPv6Test.php @@ -1,5 +1,7 @@ assertInstanceOf(IpInterface::class, $ip); @@ -39,15 +36,10 @@ public function testInstantiationWithValidAddresses($value, $hex, $expanded, $co /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidBinarySequences() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidBinarySequences')] - public function testBinarySequenceIsTheSameOnceInstantiated($value, $hex, $expanded, $compacted) + public function testBinarySequenceIsTheSameOnceInstantiated(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertSame($value, $ip->getBinary()); @@ -56,15 +48,10 @@ public function testBinarySequenceIsTheSameOnceInstantiated($value, $hex, $expan /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidProtocolIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidProtocolIpAddresses')] - public function testProtocolNotationConvertsToCorrectBinarySequence($value, $hex, $expanded, $compacted) + public function testProtocolNotationConvertsToCorrectBinarySequence(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $actualHex = unpack('H*hex', $ip->getBinary()); @@ -74,17 +61,14 @@ public function testProtocolNotationConvertsToCorrectBinarySequence($value, $hex /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value) + public function testExceptionIsThrownOnInstantiationWithInvalidAddresses(string $value): void { $this->expectException(\Darsyn\IP\Exception\InvalidIpAddressException::class); $this->expectExceptionMessage('The IP address supplied is not valid.'); try { - // @phpstan-ignore argument.type $ip = IP::factory($value); } catch (InvalidIpAddressException $e) { $this->assertSame($value, $e->getSuppliedIp()); @@ -98,10 +82,9 @@ public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value) * @covers \Darsyn\IP\Version\IPv6::fromEmbedded() * @covers \Darsyn\IP\Version\Multi::factory() * @covers \Darsyn\IP\Version\Multi::getBinary() - * @return void */ #[PHPUnit\Test] - public function testInstantiationFromEmbeddedIpAddress() + public function testInstantiationFromEmbeddedIpAddress(): void { try { $ip = IP::factory('12.34.56.78'); @@ -110,12 +93,12 @@ public function testInstantiationFromEmbeddedIpAddress() } // IPv4 address can be embedded into IPv6 objects using the fromEmbedded() static instantiator. - $embedded = IP::fromEmbedded('12.34.56.78', new Mapped); + $embedded = IP::fromEmbedded('12.34.56.78', new Mapped()); // But IPv6 objects should ignore the fact that it's embedded and only work with the full IPv6 address. $this->assertSame('0000:1fff:ffff:ffff:ffff:ffff:ffff:ffff', $embedded->getBroadcastIp(19)->getExpandedAddress()); // Multi objects understand both IPv4 and IPv6 addresses. - $multi = Multi::factory('12.34.56.78', new Mapped); + $multi = Multi::factory('12.34.56.78', new Mapped()); // So therefore, if a Multi object detects that it holds an embedded IPv4 address it will attempt to work with // the IPv4 address before falling back on the full IPv6 address. $this->assertSame('0000:0000:0000:0000:0000:ffff:0c22:3fff', $multi->getBroadcastIp(19)->getExpandedAddress()); @@ -125,15 +108,10 @@ public function testInstantiationFromEmbeddedIpAddress() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testGetBinaryAlwaysReturnsA16ByteString($value, $hex, $expanded, $compacted) + public function testGetBinaryAlwaysReturnsA16ByteString(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertSame(16, strlen(bin2hex($ip->getBinary())) / 2); @@ -142,15 +120,10 @@ public function testGetBinaryAlwaysReturnsA16ByteString($value, $hex, $expanded, /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testGetCompactedAddressReturnsCorrectString($value, $hex, $expanded, $compacted) + public function testGetCompactedAddressReturnsCorrectString(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertSame($compacted, $ip->getCompactedAddress()); @@ -159,15 +132,10 @@ public function testGetCompactedAddressReturnsCorrectString($value, $hex, $expan /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidProtocolIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidProtocolIpAddresses')] - public function testGetExpandedAddressReturnsCorrectString($value, $hex, $expanded, $compacted) + public function testGetExpandedAddressReturnsCorrectString(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertSame($expanded, $ip->getExpandedAddress()); @@ -176,15 +144,10 @@ public function testGetExpandedAddressReturnsCorrectString($value, $hex, $expand /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testGetVersionAlwaysReturns6($value, $hex, $expanded, $compacted) + public function testGetVersionAlwaysReturns6(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertSame(6, $ip->getVersion()); @@ -193,15 +156,10 @@ public function testGetVersionAlwaysReturns6($value, $hex, $expanded, $compacted /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testIsVersionOnlyReturnsTrueFor6($value, $hex, $expanded, $compacted) + public function testIsVersionOnlyReturnsTrueFor6(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertTrue($ip->isVersion(6)); @@ -210,15 +168,10 @@ public function testIsVersionOnlyReturnsTrueFor6($value, $hex, $expanded, $compa /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testIsVersionOnlyReturnsFalseFor4($value, $hex, $expanded, $compacted) + public function testIsVersionOnlyReturnsFalseFor4(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertFalse($ip->isVersion(4)); @@ -227,15 +180,10 @@ public function testIsVersionOnlyReturnsFalseFor4($value, $hex, $expanded, $comp /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testIsVersion6AlwaysReturnsTrue($value, $hex, $expanded, $compacted) + public function testIsVersion6AlwaysReturnsTrue(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertTrue($ip->isVersion6()); @@ -244,15 +192,10 @@ public function testIsVersion6AlwaysReturnsTrue($value, $hex, $expanded, $compac /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testIsVersion4AlwaysReturnsFalse($value, $hex, $expanded, $compacted) + public function testIsVersion4AlwaysReturnsFalse(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertFalse($ip->isVersion4()); @@ -261,13 +204,10 @@ public function testIsVersion4AlwaysReturnsFalse($value, $hex, $expanded, $compa /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidCidrValues() - * @param int $cidr - * @param string $expectedMaskHex - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidCidrValues')] - public function testCidrMasks($cidr, $expectedMaskHex) + public function testCidrMasks(int $cidr, string $expectedMaskHex): void { $ip = IP::factory('::1'); $mask = (function () use ($cidr): string { @@ -280,12 +220,10 @@ public function testCidrMasks($cidr, $expectedMaskHex) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getOutOfRangeCidrValues() - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getOutOfRangeCidrValues')] - public function testExceptionIsThrownFromOutOfRangeCidrValues($cidr) + public function testExceptionIsThrownFromOutOfRangeCidrValues(int $cidr): void { $this->expectException(\Darsyn\IP\Exception\InvalidCidrException::class); $this->expectExceptionMessage('The supplied CIDR is not valid; it must be an integer (between 0 and 128).'); @@ -304,13 +242,10 @@ public function testExceptionIsThrownFromOutOfRangeCidrValues($cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getNetworkIpAddresses() - * @param string $expected - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getNetworkIpAddresses')] - public function testNetworkIp($expected, $cidr) + public function testNetworkIp(string $expected, int $cidr): void { $ip = IP::factory('2001:db8::a60:8a2e:370:7334'); $this->assertSame($expected, $ip->getNetworkIp($cidr)->getCompactedAddress()); @@ -319,13 +254,10 @@ public function testNetworkIp($expected, $cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getBroadcastIpAddresses() - * @param string $expected - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getBroadcastIpAddresses')] - public function testBroadcastIp($expected, $cidr) + public function testBroadcastIp(string $expected, int $cidr): void { $ip = IP::factory('2001:db8::a60:8a2e:370:7334'); $this->assertSame($expected, $ip->getBroadcastIp($cidr)->getCompactedAddress()); @@ -334,26 +266,19 @@ public function testBroadcastIp($expected, $cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidInRangeIpAddresses() - * @param string $first - * @param string $second - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidInRangeIpAddresses')] - public function testInRange($first, $second, $cidr) + public function testInRange(string $first, string $second, int $cidr): void { $first = IP::factory($first); $second = IP::factory($second); $this->assertTrue($first->inRange($second, $cidr)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testDifferentVersionsAreNotInRange() + public function testDifferentVersionsAreNotInRange(): void { $ip = IP::factory('::12.34.56.78'); $other = IPv4::factory('12.34.56.78'); @@ -364,14 +289,10 @@ public function testDifferentVersionsAreNotInRange() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getCommonCidrValues() - * @param string $first - * @param string $second - * @param int $expectedCidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getCommonCidrValues')] - public function testCommonCidr($first, $second, $expectedCidr) + public function testCommonCidr(string $first, string $second, int $expectedCidr): void { $first = IP::factory($first); $second = IP::factory($second); @@ -381,26 +302,19 @@ public function testCommonCidr($first, $second, $expectedCidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv4::getCommonCidrValues() - * @param string $first - * @param string $second - * @param int $expectedCidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv4DataProvider::class, 'getCommonCidrValues')] - public function testEmbeddedCommonCidr($first, $second, $expectedCidr) + public function testEmbeddedCommonCidr(string $first, string $second, int $expectedCidr): void { $first = IP::fromEmbedded($first); $second = IP::fromEmbedded($second); $this->assertSame(96 + $expectedCidr, $first->getCommonCidr($second)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testCommonCidrThrowsException() + public function testCommonCidrThrowsException(): void { $first = IP::factory('2001:db8::a60:8a2e:370:7334'); $second = IPv4::factory('12.34.56.78'); @@ -411,13 +325,10 @@ public function testCommonCidrThrowsException() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getMappedIpAddresses() - * @param string $value - * @param bool $isMapped - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getMappedIpAddresses')] - public function testIsMapped($value, $isMapped) + public function testIsMapped(string $value, bool $isMapped): void { $ip = IP::factory($value); $this->assertSame($isMapped, $ip->isMapped()); @@ -426,13 +337,10 @@ public function testIsMapped($value, $isMapped) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getDerivedIpAddresses() - * @param string $value - * @param bool $isDerived - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getDerivedIpAddresses')] - public function testIsDerived($value, $isDerived) + public function testIsDerived(string $value, bool $isDerived): void { $ip = IP::factory($value); $this->assertSame($isDerived, $ip->isDerived()); @@ -441,13 +349,10 @@ public function testIsDerived($value, $isDerived) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getCompatibleIpAddresses() - * @param string $value - * @param bool $isCompatible - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getCompatibleIpAddresses')] - public function testIsCompatible($value, $isCompatible) + public function testIsCompatible(string $value, bool $isCompatible): void { $ip = IP::factory($value); $this->assertSame($isCompatible, $ip->isCompatible()); @@ -456,15 +361,10 @@ public function testIsCompatible($value, $isCompatible) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testIsEmbeddedAlwaysReturnsFalse($value, $hex, $expanded, $compacted) + public function testIsEmbeddedAlwaysReturnsFalse(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertFalse($ip->isEmbedded()); @@ -473,13 +373,10 @@ public function testIsEmbeddedAlwaysReturnsFalse($value, $hex, $expanded, $compa /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getLinkLocalIpAddresses() - * @param string $value - * @param bool $isLinkLocal - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getLinkLocalIpAddresses')] - public function testIsLinkLocal($value, $isLinkLocal) + public function testIsLinkLocal(string $value, bool $isLinkLocal): void { $ip = IP::factory($value); $this->assertSame($isLinkLocal, $ip->isLinkLocal()); @@ -488,13 +385,10 @@ public function testIsLinkLocal($value, $isLinkLocal) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getLoopbackIpAddresses() - * @param string $value - * @param bool $isLoopback - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getLoopbackIpAddresses')] - public function testIsLoopback($value, $isLoopback) + public function testIsLoopback(string $value, bool $isLoopback): void { $ip = IP::factory($value); $this->assertSame($isLoopback, $ip->isLoopback()); @@ -503,13 +397,10 @@ public function testIsLoopback($value, $isLoopback) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getMulticastIpAddresses() - * @param string $value - * @param bool $isMulticast - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getMulticastIpAddresses')] - public function testIsMulticast($value, $isMulticast) + public function testIsMulticast(string $value, bool $isMulticast): void { $ip = IP::factory($value); $this->assertSame($isMulticast, $ip->isMulticast()); @@ -519,13 +410,10 @@ public function testIsMulticast($value, $isMulticast) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getPrivateUseIpAddresses() - * @param string $value - * @param bool $isPrivateUse - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getPrivateUseIpAddresses')] - public function testIsPrivateUse($value, $isPrivateUse) + public function testIsPrivateUse(string $value, bool $isPrivateUse): void { $ip = IP::factory($value); $this->assertSame($isPrivateUse, $ip->isPrivateUse()); @@ -534,13 +422,10 @@ public function testIsPrivateUse($value, $isPrivateUse) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getUnspecifiedIpAddresses() - * @param string $value - * @param bool $isUnspecified - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getUnspecifiedIpAddresses')] - public function testIsUnspecified($value, $isUnspecified) + public function testIsUnspecified(string $value, bool $isUnspecified): void { $ip = IP::factory($value); $this->assertSame($isUnspecified, $ip->isUnspecified()); @@ -549,13 +434,10 @@ public function testIsUnspecified($value, $isUnspecified) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getBenchmarkingIpAddresses() - * @param string $value - * @param bool $isBenchmarking - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getBenchmarkingIpAddresses')] - public function testIsBenchmarking($value, $isBenchmarking) + public function testIsBenchmarking(string $value, bool $isBenchmarking): void { $ip = IP::factory($value); $this->assertSame($isBenchmarking, $ip->isBenchmarking()); @@ -564,13 +446,10 @@ public function testIsBenchmarking($value, $isBenchmarking) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getDocumentationIpAddresses() - * @param string $value - * @param bool $isDocumentation - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getDocumentationIpAddresses')] - public function testIsDocumentation($value, $isDocumentation) + public function testIsDocumentation(string $value, bool $isDocumentation): void { $ip = IP::factory($value); $this->assertSame($isDocumentation, $ip->isDocumentation()); @@ -579,13 +458,10 @@ public function testIsDocumentation($value, $isDocumentation) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getPublicUseIpAddresses() - * @param string $value - * @param bool $isPublicUse - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getPublicUseIpAddresses')] - public function testIsPublicUse($value, $isPublicUse) + public function testIsPublicUse(string $value, bool $isPublicUse): void { $ip = IP::factory($value); $this->assertSame($isPublicUse, $ip->isPublicUse()); @@ -594,13 +470,10 @@ public function testIsPublicUse($value, $isPublicUse) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getUniqueLocalIpAddresses() - * @param string $value - * @param bool $isUniqueLocal - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getUniqueLocalIpAddresses')] - public function testIsUniqueLocal($value, $isUniqueLocal) + public function testIsUniqueLocal(string $value, bool $isUniqueLocal): void { $ip = IP::factory($value); $this->assertSame($isUniqueLocal, $ip->isUniqueLocal()); @@ -609,13 +482,10 @@ public function testIsUniqueLocal($value, $isUniqueLocal) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getUnicastIpAddresses() - * @param string $value - * @param bool $isUnicast - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getUnicastIpAddresses')] - public function testIsUnicast($value, $isUnicast) + public function testIsUnicast(string $value, bool $isUnicast): void { $ip = IP::factory($value); $this->assertSame($isUnicast, $ip->isUnicast()); @@ -624,13 +494,10 @@ public function testIsUnicast($value, $isUnicast) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getUnicastGlobalIpAddresses() - * @param string $value - * @param bool $isUnicastGlobal - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getUnicastGlobalIpAddresses')] - public function testIsUnicastGlobal($value, $isUnicastGlobal) + public function testIsUnicastGlobal(string $value, bool $isUnicastGlobal): void { $ip = IP::factory($value); $this->assertSame($isUnicastGlobal, $ip->isUnicastGlobal()); @@ -639,15 +506,10 @@ public function testIsUnicastGlobal($value, $isUnicastGlobal) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\IPv6::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(IPv6DataProvider::class, 'getValidIpAddresses')] - public function testStringCasting($value, $hex, $expanded, $compacted) + public function testStringCasting(string $value, string $hex, string $expanded, string $compacted): void { $ip = IP::factory($value); $this->assertSame($compacted, (string) $ip); diff --git a/tests/Version/MultiTest.php b/tests/Version/MultiTest.php index 38b0580..c3f5324 100644 --- a/tests/Version/MultiTest.php +++ b/tests/Version/MultiTest.php @@ -1,5 +1,7 @@ assertInstanceOf(IpInterface::class, $ip); @@ -53,15 +46,12 @@ public function testInstantiationWithValidAddresses($value, $hex, $expanded, $co * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getEmbeddingStrategyIpAddresses() * @param class-string $strategyClass - * @param string $expandedAddress - * @param string $v4address - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getEmbeddingStrategyIpAddresses')] - public function testEmbeddingStrategy($strategyClass, $expandedAddress, $v4address) + public function testEmbeddingStrategy(string $strategyClass, string $expandedAddress, string $v4address): void { - $ip = IP::factory($v4address, new $strategyClass); + $ip = IP::factory($v4address, new $strategyClass()); $this->assertSame($expandedAddress, $ip->getExpandedAddress()); } @@ -69,15 +59,12 @@ public function testEmbeddingStrategy($strategyClass, $expandedAddress, $v4addre * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getEmbeddingStrategyIpAddresses() * @param class-string $strategyClass - * @param string $expandedAddress - * @param string $v4address - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getEmbeddingStrategyIpAddresses')] - public function testDefaufltEmbeddingStrategy($strategyClass, $expandedAddress, $v4address) + public function testDefaufltEmbeddingStrategy(string $strategyClass, string $expandedAddress, string $v4address): void { - IP::setDefaultEmbeddingStrategy(new $strategyClass); + IP::setDefaultEmbeddingStrategy(new $strategyClass()); $ip = IP::factory($v4address); $this->assertSame($expandedAddress, $ip->getExpandedAddress()); } @@ -85,16 +72,10 @@ public function testDefaufltEmbeddingStrategy($strategyClass, $expandedAddress, /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidBinarySequences() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @param string $dot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidBinarySequences')] - public function testBinarySequenceIsTheSameOnceInstantiated($value, $hex, $expanded, $compacted, $dot) + public function testBinarySequenceIsTheSameOnceInstantiated(string $value, string $hex, string $expanded, string $compacted, ?string $dot): void { $ip = IP::factory($value); $this->assertSame($value, $ip->getBinary()); @@ -103,16 +84,10 @@ public function testBinarySequenceIsTheSameOnceInstantiated($value, $hex, $expan /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidProtocolIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @param string $dot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidProtocolIpAddresses')] - public function testProtocolNotationConvertsToCorrectBinarySequence($value, $hex, $expanded, $compacted, $dot) + public function testProtocolNotationConvertsToCorrectBinarySequence(string $value, string $hex, string $expanded, string $compacted, ?string $dot): void { $ip = IP::factory($value); $actualHex = unpack('H*hex', $ip->getBinary()); @@ -122,17 +97,14 @@ public function testProtocolNotationConvertsToCorrectBinarySequence($value, $hex /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getInvalidIpAddresses() - * @param mixed $value - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getInvalidIpAddresses')] - public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value) + public function testExceptionIsThrownOnInstantiationWithInvalidAddresses(string $value): void { $this->expectException(InvalidIpAddressException::class); $this->expectExceptionMessage('The IP address supplied is not valid.'); try { - // @phpstan-ignore argument.type $ip = IP::factory($value); } catch (InvalidIpAddressException $e) { $this->assertSame($value, $e->getSuppliedIp()); @@ -143,16 +115,10 @@ public function testExceptionIsThrownOnInstantiationWithInvalidAddresses($value) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @param string $dot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidIpAddresses')] - public function testGetBinaryAlwaysReturnsA16ByteString($value, $hex, $expanded, $compacted, $dot) + public function testGetBinaryAlwaysReturnsA16ByteString(string $value, string $hex, string $expanded, string $compacted, ?string $dot): void { $ip = IP::factory($value); $this->assertSame(16, strlen(bin2hex($ip->getBinary())) / 2); @@ -161,16 +127,10 @@ public function testGetBinaryAlwaysReturnsA16ByteString($value, $hex, $expanded, /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @param string $dot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidIpAddresses')] - public function testGetCompactedAddressReturnsCorrectString($value, $hex, $expanded, $compacted, $dot) + public function testGetCompactedAddressReturnsCorrectString(string $value, string $hex, string $expanded, string $compacted, ?string $dot): void { $ip = IP::factory($value); $this->assertSame($compacted, $ip->getCompactedAddress()); @@ -179,16 +139,10 @@ public function testGetCompactedAddressReturnsCorrectString($value, $hex, $expan /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidProtocolIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @param string $dot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidProtocolIpAddresses')] - public function testGetExpandedAddressReturnsCorrectString($value, $hex, $expanded, $compacted, $dot) + public function testGetExpandedAddressReturnsCorrectString(string $value, string $hex, string $expanded, string $compacted, ?string $dot): void { $ip = IP::factory($value); $this->assertSame($expanded, $ip->getExpandedAddress()); @@ -197,16 +151,10 @@ public function testGetExpandedAddressReturnsCorrectString($value, $hex, $expand /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidIpVersion4Addresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @param string $dot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidIpVersion4Addresses')] - public function testDotAddressReturnsCorrectString($value, $hex, $expanded, $compacted, $dot) + public function testDotAddressReturnsCorrectString(string $value, string $hex, string $expanded, string $compacted, ?string $dot): void { $ip = IP::factory($value); $this->assertSame($dot, $ip->getDotAddress()); @@ -215,16 +163,10 @@ public function testDotAddressReturnsCorrectString($value, $hex, $expanded, $com /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidIpVersion6Addresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @param string $dot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidIpVersion6Addresses')] - public function testDotAddressThrowsExceptionForNonVersion4Addresses($value, $hex, $expanded, $compacted, $dot) + public function testDotAddressThrowsExceptionForNonVersion4Addresses(string $value, string $hex, string $expanded, string $compacted, ?string $dot): void { $this->expectException(\Darsyn\IP\Exception\WrongVersionException::class); try { @@ -242,13 +184,10 @@ public function testDotAddressThrowsExceptionForNonVersion4Addresses($value, $he /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getIpAddressVersions() - * @param string $value - * @param int $version - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getIpAddressVersions')] - public function testVersion($value, $version) + public function testVersion(string $value, int $version): void { $ip = IP::factory($value); $this->assertSame($version, $ip->getVersion()); @@ -257,14 +196,10 @@ public function testVersion($value, $version) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getNetworkIpAddresses() - * @param string $initial - * @param string $expected - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getNetworkIpAddresses')] - public function testNetworkIp($initial, $expected, $cidr) + public function testNetworkIp(string $initial, string $expected, int $cidr): void { $ip = IP::factory($initial); $this->assertSame($expected, $ip->getNetworkIp($cidr)->getProtocolAppropriateAddress()); @@ -273,14 +208,10 @@ public function testNetworkIp($initial, $expected, $cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getBroadcastIpAddresses() - * @param string $initial - * @param string $expected - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getBroadcastIpAddresses')] - public function testBroadcastIp($initial, $expected, $cidr) + public function testBroadcastIp(string $initial, string $expected, int $cidr): void { $ip = IP::factory($initial); $this->assertSame($expected, $ip->getBroadcastIp($cidr)->getProtocolAppropriateAddress()); @@ -289,38 +220,28 @@ public function testBroadcastIp($initial, $expected, $cidr) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidInRangeIpAddresses() - * @param string $first - * @param string $second - * @param int $cidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidInRangeIpAddresses')] - public function testInRange($first, $second, $cidr) + public function testInRange(string $first, string $second, int $cidr): void { $first = IP::factory($first); $second = IP::factory($second); $this->assertTrue($first->inRange($second, $cidr)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testDifferentVersionsAreInRange() + public function testDifferentVersionsAreInRange(): void { - $first = IP::factory('127.0.0.1', new Strategy\Mapped); + $first = IP::factory('127.0.0.1', new Strategy\Mapped()); $second = IPv6::factory('::1234:5678:abcd:90ef'); $this->assertTrue($first->inRange($second, 0)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testDifferentByteLengthsAreNotInRange() + public function testDifferentByteLengthsAreNotInRange(): void { $first = IP::factory('127.0.0.1'); $second = IPv4::factory('127.0.0.1'); @@ -331,26 +252,19 @@ public function testDifferentByteLengthsAreNotInRange() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getCommonCidrValues() - * @param string $first - * @param string $second - * @param int $expectedCidr - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getCommonCidrValues')] - public function testCommonCidr($first, $second, $expectedCidr) + public function testCommonCidr(string $first, string $second, int $expectedCidr): void { $first = IP::factory($first); $second = IP::factory($second); $this->assertSame($expectedCidr, $first->getCommonCidr($second)); } - /** - * @test - * @return void - */ + /** @test */ #[PHPUnit\Test] - public function testCommonCidrThrowsException() + public function testCommonCidrThrowsException(): void { $first = IP::factory('12.34.56.78'); $second = IPv4::factory('12.34.56.78'); @@ -361,13 +275,10 @@ public function testCommonCidrThrowsException() /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getLinkLocalIpAddresses() - * @param string $value - * @param bool $isLinkLocal - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getLinkLocalIpAddresses')] - public function testIsLinkLocal($value, $isLinkLocal) + public function testIsLinkLocal(string $value, bool $isLinkLocal): void { $ip = IP::factory($value); $this->assertSame($isLinkLocal, $ip->isLinkLocal()); @@ -376,31 +287,25 @@ public function testIsLinkLocal($value, $isLinkLocal) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getMappedLoopbackIpAddresses() - * @param string $value - * @param bool $isLoopback - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getMappedLoopbackIpAddresses')] - public function testIsLoopbackMapped($value, $isLoopback) + public function testIsLoopbackMapped(string $value, bool $isLoopback): void { - $ip = IP::factory($value, new Strategy\Mapped); + $ip = IP::factory($value, new Strategy\Mapped()); $this->assertSame($isLoopback, $ip->isLoopback()); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getCompatibleLoopbackIpAddresses() - * @param string $value - * @param bool $isLoopback - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getCompatibleLoopbackIpAddresses')] - public function testIsLoopbackCompatible($value, $isLoopback) + public function testIsLoopbackCompatible(string $value, bool $isLoopback): void { - $ip = IP::factory($value, new Strategy\Compatible); - if ($ip->getExpandedAddress() === '0000:0000:0000:0000:0000:0000:0000:0001') { + $ip = IP::factory($value, new Strategy\Compatible()); + if ('0000:0000:0000:0000:0000:0000:0000:0001' === $ip->getExpandedAddress()) { // Special case that I can't figure out a solution for. // The address 0.0.0.1 (when using the compatible embedding strategy) // is a loopback address if viewing as IPv6 (::1), but also not a @@ -413,28 +318,22 @@ public function testIsLoopbackCompatible($value, $isLoopback) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getDerivedLoopbackIpAddresses() - * @param string $value - * @param bool $isLoopback - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getDerivedLoopbackIpAddresses')] - public function testIsLoopbackDerived($value, $isLoopback) + public function testIsLoopbackDerived(string $value, bool $isLoopback): void { - $ip = IP::factory($value, new Strategy\Derived); + $ip = IP::factory($value, new Strategy\Derived()); $this->assertSame($isLoopback, $ip->isLoopback()); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getMulticastIpAddresses() - * @param string $value - * @param bool $isMulticast - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getMulticastIpAddresses')] - public function testIsMulticast($value, $isMulticast) + public function testIsMulticast(string $value, bool $isMulticast): void { $ip = IP::factory($value); $this->assertSame($isMulticast, $ip->isMulticast()); @@ -444,13 +343,10 @@ public function testIsMulticast($value, $isMulticast) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getPrivateUseIpAddresses() - * @param string $value - * @param bool $isPrivateUse - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getPrivateUseIpAddresses')] - public function testIsPrivateUse($value, $isPrivateUse) + public function testIsPrivateUse(string $value, bool $isPrivateUse): void { $ip = IP::factory($value); $this->assertSame($isPrivateUse, $ip->isPrivateUse()); @@ -459,13 +355,10 @@ public function testIsPrivateUse($value, $isPrivateUse) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getUnspecifiedIpAddresses() - * @param string $value - * @param bool $isUnspecified - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getUnspecifiedIpAddresses')] - public function testIsUnspecified($value, $isUnspecified) + public function testIsUnspecified(string $value, bool $isUnspecified): void { $ip = IP::factory($value); $this->assertSame($isUnspecified, $ip->isUnspecified()); @@ -474,13 +367,10 @@ public function testIsUnspecified($value, $isUnspecified) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getBenchmarkingIpAddresses() - * @param string $value - * @param bool $isBenchmarking - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getBenchmarkingIpAddresses')] - public function testIsBenchmarking($value, $isBenchmarking) + public function testIsBenchmarking(string $value, bool $isBenchmarking): void { $ip = IP::factory($value); $this->assertSame($isBenchmarking, $ip->isBenchmarking()); @@ -489,13 +379,10 @@ public function testIsBenchmarking($value, $isBenchmarking) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getDocumentationIpAddresses() - * @param string $value - * @param bool $isDocumentation - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getDocumentationIpAddresses')] - public function testIsDocumentation($value, $isDocumentation) + public function testIsDocumentation(string $value, bool $isDocumentation): void { $ip = IP::factory($value); $this->assertSame($isDocumentation, $ip->isDocumentation()); @@ -504,31 +391,24 @@ public function testIsDocumentation($value, $isDocumentation) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getPublicUseIpAddresses() - * @param string $value - * @param bool $isPublicUse - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getPublicUseIpAddresses')] - public function testIsPublicUse($value, $isPublicUse) + public function testIsPublicUse(string $value, bool $isPublicUse): void { - $ip = IP::factory($value, new Strategy\Mapped); + $ip = IP::factory($value, new Strategy\Mapped()); $this->assertSame($isPublicUse, $ip->isPublicUse()); } /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getUniqueLocalIpAddresses() - * @param string $value - * @param bool $isUniqueLocal - * @param bool $willThrowException - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getUniqueLocalIpAddresses')] - public function testIsUniqueLocal($value, $isUniqueLocal, $willThrowException) + public function testIsUniqueLocal(string $value, bool $isUniqueLocal, bool $willThrowException): void { - $ip = IP::factory($value, new Strategy\Mapped); + $ip = IP::factory($value, new Strategy\Mapped()); $willThrowException && $this->expectException(WrongVersionException::class); $this->assertSame($isUniqueLocal, $ip->isUniqueLocal()); } @@ -536,16 +416,12 @@ public function testIsUniqueLocal($value, $isUniqueLocal, $willThrowException) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getUnicastIpAddresses() - * @param string $value - * @param bool $isUnicast - * @param bool $willThrowException - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getUnicastIpAddresses')] - public function testIsUnicast($value, $isUnicast, $willThrowException) + public function testIsUnicast(string $value, bool $isUnicast, bool $willThrowException): void { - $ip = IP::factory($value, new Strategy\Mapped); + $ip = IP::factory($value, new Strategy\Mapped()); $willThrowException && $this->expectException(WrongVersionException::class); $this->assertSame($isUnicast, $ip->isUnicast()); } @@ -553,16 +429,12 @@ public function testIsUnicast($value, $isUnicast, $willThrowException) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getUnicastGlobalIpAddresses() - * @param string $value - * @param bool $isUnicastGlobal - * @param bool $willThrowException - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getUnicastGlobalIpAddresses')] - public function testIsUnicastGlobal($value, $isUnicastGlobal, $willThrowException) + public function testIsUnicastGlobal(string $value, bool $isUnicastGlobal, bool $willThrowException): void { - $ip = IP::factory($value, new Strategy\Mapped); + $ip = IP::factory($value, new Strategy\Mapped()); $willThrowException && $this->expectException(WrongVersionException::class); $this->assertSame($isUnicastGlobal, $ip->isUnicastGlobal()); } @@ -570,14 +442,10 @@ public function testIsUnicastGlobal($value, $isUnicastGlobal, $willThrowExceptio /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getIsBroadcastIpAddresses() - * @param string $value - * @param bool $isBroadcast - * @param bool $willThrowException - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getIsBroadcastIpAddresses')] - public function testIsBroadcast($value, $isBroadcast, $willThrowException) + public function testIsBroadcast(string $value, bool $isBroadcast, bool $willThrowException): void { $ip = IP::factory($value); $willThrowException && $this->expectException(WrongVersionException::class); @@ -587,14 +455,10 @@ public function testIsBroadcast($value, $isBroadcast, $willThrowException) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getSharedIpAddresses() - * @param string $value - * @param bool $isShared - * @param bool $willThrowException - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getSharedIpAddresses')] - public function testIsShared($value, $isShared, $willThrowException) + public function testIsShared(string $value, bool $isShared, bool $willThrowException): void { $ip = IP::factory($value); $willThrowException && $this->expectException(WrongVersionException::class); @@ -604,14 +468,10 @@ public function testIsShared($value, $isShared, $willThrowException) /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getFutureReservedIpAddresses() - * @param string $value - * @param bool $isFutureReserved - * @param bool $willThrowException - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getFutureReservedIpAddresses')] - public function testIsFutureReserved($value, $isFutureReserved, $willThrowException) + public function testIsFutureReserved(string $value, bool $isFutureReserved, bool $willThrowException): void { $ip = IP::factory($value); $willThrowException && $this->expectException(WrongVersionException::class); @@ -621,19 +481,13 @@ public function testIsFutureReserved($value, $isFutureReserved, $willThrowExcept /** * @test * @dataProvider \Darsyn\IP\Tests\DataProvider\Multi::getValidIpAddresses() - * @param string $value - * @param string $hex - * @param string $expanded - * @param string $compacted - * @param string|null $dot - * @return void */ #[PHPUnit\Test] #[PHPUnit\DataProviderExternal(MultiDataProvider::class, 'getValidIpAddresses')] - public function testStringCasting($value, $hex, $expanded, $compacted, $dot) + public function testStringCasting(string $value, string $hex, string $expanded, string $compacted, ?string $dot): void { $ip = IP::factory($value); - $dot !== null + null !== $dot ? $this->assertSame($dot, (string) $ip) : $this->assertSame($compacted, (string) $ip); } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 07bf4dd..e8391d4 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,10 +1,12 @@ Date: Tue, 2 Jun 2026 22:33:44 +0200 Subject: [PATCH 4/4] =?UTF-8?q?docs:=20=F0=9F=93=9A=20update=20CHANGELOG?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f1d204d..4352e21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,9 @@ - Bugfix: don't compress single 16-bit zero group (according to RFC 5952 § `4.2.2`). - Bugfix: stop `MbString::subString()` from swallowing valid `0`. - Add Bash script for testing GitHub Action workflows locally using Docker. +- Add code style ruleset definition via PHP-CS-Fixer configuration. Apply the + code style to the entire codebase, and enable checking as another CI job in + GitHub Actions. ## `6.0.0`