From 382fdf777fc58b7e0a21ad79eab101d0b70ca4f5 Mon Sep 17 00:00:00 2001 From: Ben Ramsey Date: Fri, 1 Apr 2022 16:41:54 -0500 Subject: [PATCH] chore: upgrade PHPStan --- composer.json | 8 +- composer.lock | 174 +++++++++--------- phpstan.neon.dist | 4 - src/FeatureSet.php | 89 ++------- .../Dce/SystemDceSecurityProvider.php | 5 +- src/Provider/Node/SystemNodeProvider.php | 12 +- src/Rfc4122/Fields.php | 5 +- src/Rfc4122/VariantTrait.php | 2 +- src/Type/Decimal.php | 12 ++ src/Type/Time.php | 13 +- tests/BinaryUtilsTest.php | 2 +- tests/Generator/DceSecurityGeneratorTest.php | 13 +- tests/Rfc4122/VariantTraitTest.php | 4 +- tests/Type/DecimalTest.php | 26 +-- tests/Type/HexadecimalTest.php | 14 +- tests/Type/IntegerTest.php | 40 ++-- tests/Type/TimeTest.php | 27 ++- 17 files changed, 212 insertions(+), 238 deletions(-) diff --git a/composer.json b/composer.json index 7e4fec6..d7a4124 100644 --- a/composer.json +++ b/composer.json @@ -25,10 +25,10 @@ "php-mock/php-mock-mockery": "^1.3", "php-parallel-lint/php-parallel-lint": "^1.1", "phpbench/phpbench": "^1.0", - "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-mockery": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan": "^1.5", + "phpstan/phpstan-mockery": "^1.0", + "phpstan/phpstan-phpunit": "^1.1", "phpunit/phpunit": "^8.5 || ^9", "slevomat/coding-standard": "^7.0", "squizlabs/php_codesniffer": "^3.5", diff --git a/composer.lock b/composer.lock index d39b026..56bebd2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0a2e5de3eeffab9dc70b68b18861b8e9", + "content-hash": "42166648ed08255273b1579f817a1a15", "packages": [ { "name": "brick/math", @@ -995,16 +995,16 @@ }, { "name": "ergebnis/composer-normalize", - "version": "2.24.1", + "version": "2.25.1", "source": { "type": "git", "url": "https://github.com/ergebnis/composer-normalize.git", - "reference": "3d5392cfca3d519412cef3f4817c73d2f60d43fd" + "reference": "f8dcad3ab46b251864b89e1a33cb396d6e85984a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ergebnis/composer-normalize/zipball/3d5392cfca3d519412cef3f4817c73d2f60d43fd", - "reference": "3d5392cfca3d519412cef3f4817c73d2f60d43fd", + "url": "https://api.github.com/repos/ergebnis/composer-normalize/zipball/f8dcad3ab46b251864b89e1a33cb396d6e85984a", + "reference": "f8dcad3ab46b251864b89e1a33cb396d6e85984a", "shasum": "" }, "require": { @@ -1016,9 +1016,9 @@ "php": "^7.4 || ^8.0" }, "require-dev": { - "composer/composer": "^2.2.9", + "composer/composer": "^2.3.1", "ergebnis/license": "^1.2.0", - "ergebnis/php-cs-fixer-config": "^3.4.0", + "ergebnis/php-cs-fixer-config": "^4.4.0", "fakerphp/faker": "^1.19.0", "phpunit/phpunit": "^9.5.19", "psalm/plugin-phpunit": "~0.16.1", @@ -1066,7 +1066,7 @@ "type": "github" } ], - "time": "2022-03-19T13:37:12+00:00" + "time": "2022-03-30T13:53:56+00:00" }, { "name": "ergebnis/json-normalizer", @@ -1314,16 +1314,16 @@ }, { "name": "felixfbecker/language-server-protocol", - "version": "1.5.1", + "version": "v1.5.2", "source": { "type": "git", "url": "https://github.com/felixfbecker/php-language-server-protocol.git", - "reference": "9d846d1f5cf101deee7a61c8ba7caa0a975cd730" + "reference": "6e82196ffd7c62f7794d778ca52b69feec9f2842" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/9d846d1f5cf101deee7a61c8ba7caa0a975cd730", - "reference": "9d846d1f5cf101deee7a61c8ba7caa0a975cd730", + "url": "https://api.github.com/repos/felixfbecker/php-language-server-protocol/zipball/6e82196ffd7c62f7794d778ca52b69feec9f2842", + "reference": "6e82196ffd7c62f7794d778ca52b69feec9f2842", "shasum": "" }, "require": { @@ -1364,9 +1364,9 @@ ], "support": { "issues": "https://github.com/felixfbecker/php-language-server-protocol/issues", - "source": "https://github.com/felixfbecker/php-language-server-protocol/tree/1.5.1" + "source": "https://github.com/felixfbecker/php-language-server-protocol/tree/v1.5.2" }, - "time": "2021-02-22T14:02:09+00:00" + "time": "2022-03-02T22:36:06+00:00" }, { "name": "hamcrest/hamcrest-php", @@ -2500,16 +2500,16 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.6.0", + "version": "1.6.1", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706" + "reference": "77a32518733312af16a44300404e945338981de3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706", - "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/77a32518733312af16a44300404e945338981de3", + "reference": "77a32518733312af16a44300404e945338981de3", "shasum": "" }, "require": { @@ -2544,9 +2544,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.6.1" }, - "time": "2022-01-04T19:58:01+00:00" + "time": "2022-03-15T21:29:03+00:00" }, { "name": "phpspec/prophecy", @@ -2662,35 +2662,30 @@ }, { "name": "phpstan/phpdoc-parser", - "version": "1.2.0", + "version": "1.4.2", "source": { "type": "git", "url": "https://github.com/phpstan/phpdoc-parser.git", - "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e" + "reference": "4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/dbc093d7af60eff5cd575d2ed761b15ed40bd08e", - "reference": "dbc093d7af60eff5cd575d2ed761b15ed40bd08e", + "url": "https://api.github.com/repos/phpstan/phpdoc-parser/zipball/4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d", + "reference": "4cb3021a4e10ffe3d5f94a4c34cf4b3f6de2fa3d", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0" + "php": "^7.2 || ^8.0" }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^1.0", + "phpstan/phpstan": "^1.5", "phpstan/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^9.5", "symfony/process": "^5.2" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, "autoload": { "psr-4": { "PHPStan\\PhpDocParser\\": [ @@ -2705,26 +2700,26 @@ "description": "PHPDoc parser with support for nullable, intersection and generic types", "support": { "issues": "https://github.com/phpstan/phpdoc-parser/issues", - "source": "https://github.com/phpstan/phpdoc-parser/tree/1.2.0" + "source": "https://github.com/phpstan/phpdoc-parser/tree/1.4.2" }, - "time": "2021-09-16T20:46:02+00:00" + "time": "2022-03-30T13:33:37+00:00" }, { "name": "phpstan/phpstan", - "version": "0.12.99", + "version": "1.5.3", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7" + "reference": "39953ac1452a8843702ee41a35b4861d3e8207a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/b4d40f1d759942f523be267a1bab6884f46ca3f7", - "reference": "b4d40f1d759942f523be267a1bab6884f46ca3f7", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/39953ac1452a8843702ee41a35b4861d3e8207a7", + "reference": "39953ac1452a8843702ee41a35b4861d3e8207a7", "shasum": "" }, "require": { - "php": "^7.1|^8.0" + "php": "^7.2|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -2734,11 +2729,6 @@ "phpstan.phar" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "0.12-dev" - } - }, "autoload": { "files": [ "bootstrap.php" @@ -2751,7 +2741,7 @@ "description": "PHPStan - PHP Static Analysis Tool", "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/0.12.99" + "source": "https://github.com/phpstan/phpstan/tree/1.5.3" }, "funding": [ { @@ -2771,37 +2761,38 @@ "type": "tidelift" } ], - "time": "2021-09-12T20:09:55+00:00" + "time": "2022-03-30T21:55:08+00:00" }, { "name": "phpstan/phpstan-mockery", - "version": "0.12.14", + "version": "1.0.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-mockery.git", - "reference": "7cc74bf434b3c2190f7f4cfc08c74f7c0b65667f" + "reference": "1767581e025d830d9288702761ad3cc7b72ecca4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/7cc74bf434b3c2190f7f4cfc08c74f7c0b65667f", - "reference": "7cc74bf434b3c2190f7f4cfc08c74f7c0b65667f", + "url": "https://api.github.com/repos/phpstan/phpstan-mockery/zipball/1767581e025d830d9288702761ad3cc7b72ecca4", + "reference": "1767581e025d830d9288702761ad3cc7b72ecca4", "shasum": "" }, "require": { "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^0.12.60" + "phpstan/phpstan": "^1.0" }, "require-dev": { "mockery/mockery": "^1.2.4", + "nikic/php-parser": "^4.13.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-phpunit": "^0.12.16", - "phpstan/phpstan-strict-rules": "^0.12.5", + "phpstan/phpstan-phpunit": "^1.0", + "phpstan/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^9.5" }, "type": "phpstan-extension", "extra": { "branch-alias": { - "dev-master": "0.12-dev" + "dev-master": "1.0-dev" }, "phpstan": { "includes": [ @@ -2821,41 +2812,39 @@ "description": "PHPStan Mockery extension", "support": { "issues": "https://github.com/phpstan/phpstan-mockery/issues", - "source": "https://github.com/phpstan/phpstan-mockery/tree/0.12.14" + "source": "https://github.com/phpstan/phpstan-mockery/tree/1.0.0" }, - "time": "2021-06-10T12:12:36+00:00" + "time": "2021-09-20T16:03:58+00:00" }, { "name": "phpstan/phpstan-phpunit", - "version": "0.12.22", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan-phpunit.git", - "reference": "7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc" + "reference": "09133ce914f1388a8bb8c7f8573aaa3723cff52a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc", - "reference": "7c01ef93bf128b4ac8bdad38c54b2a4fd6b0b3cc", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/09133ce914f1388a8bb8c7f8573aaa3723cff52a", + "reference": "09133ce914f1388a8bb8c7f8573aaa3723cff52a", "shasum": "" }, "require": { - "php": "^7.1 || ^8.0", - "phpstan/phpstan": "^0.12.92" + "php": "^7.2 || ^8.0", + "phpstan/phpstan": "^1.5.0" }, "conflict": { "phpunit/phpunit": "<7.0" }, "require-dev": { + "nikic/php-parser": "^4.13.0", "php-parallel-lint/php-parallel-lint": "^1.2", - "phpstan/phpstan-strict-rules": "^0.12.6", + "phpstan/phpstan-strict-rules": "^1.0", "phpunit/phpunit": "^9.5" }, "type": "phpstan-extension", "extra": { - "branch-alias": { - "dev-master": "0.12-dev" - }, "phpstan": { "includes": [ "extension.neon", @@ -2875,9 +2864,9 @@ "description": "PHPUnit extensions and rules for PHPStan", "support": { "issues": "https://github.com/phpstan/phpstan-phpunit/issues", - "source": "https://github.com/phpstan/phpstan-phpunit/tree/0.12.22" + "source": "https://github.com/phpstan/phpstan-phpunit/tree/1.1.0" }, - "time": "2021-08-12T10:53:43+00:00" + "time": "2022-03-28T09:20:49+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3199,16 +3188,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.19", + "version": "9.5.20", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807" + "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/35ea4b7f3acabb26f4bb640f8c30866c401da807", - "reference": "35ea4b7f3acabb26f4bb640f8c30866c401da807", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/12bc8879fb65aef2138b26fc633cb1e3620cffba", + "reference": "12bc8879fb65aef2138b26fc633cb1e3620cffba", "shasum": "" }, "require": { @@ -3286,7 +3275,7 @@ ], "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", - "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.19" + "source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.20" }, "funding": [ { @@ -3298,7 +3287,7 @@ "type": "github" } ], - "time": "2022-03-15T09:57:31+00:00" + "time": "2022-04-01T12:37:26+00:00" }, { "name": "psr/cache", @@ -4593,23 +4582,24 @@ }, { "name": "seld/jsonlint", - "version": "1.8.3", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "9ad6ce79c342fbd44df10ea95511a1b24dee5b57" + "reference": "4211420d25eba80712bff236a98960ef68b866b7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/9ad6ce79c342fbd44df10ea95511a1b24dee5b57", - "reference": "9ad6ce79c342fbd44df10ea95511a1b24dee5b57", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/4211420d25eba80712bff236a98960ef68b866b7", + "reference": "4211420d25eba80712bff236a98960ef68b866b7", "shasum": "" }, "require": { "php": "^5.3 || ^7.0 || ^8.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0" + "phpstan/phpstan": "^1.5", + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0 || ^8.5.13" }, "bin": [ "bin/jsonlint" @@ -4640,7 +4630,7 @@ ], "support": { "issues": "https://github.com/Seldaek/jsonlint/issues", - "source": "https://github.com/Seldaek/jsonlint/tree/1.8.3" + "source": "https://github.com/Seldaek/jsonlint/tree/1.9.0" }, "funding": [ { @@ -4652,36 +4642,36 @@ "type": "tidelift" } ], - "time": "2020-11-11T09:19:24+00:00" + "time": "2022-04-01T13:37:23+00:00" }, { "name": "slevomat/coding-standard", - "version": "7.0.19", + "version": "7.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37" + "reference": "b521bd358b5f7a7d69e9637fd139e036d8adeb6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37", - "reference": "bef66a43815bbf9b5f49775e9ded3f7c6ba0cc37", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/b521bd358b5f7a7d69e9637fd139e036d8adeb6f", + "reference": "b521bd358b5f7a7d69e9637fd139e036d8adeb6f", "shasum": "" }, "require": { "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7", - "php": "^7.1 || ^8.0", - "phpstan/phpdoc-parser": "^1.0.0", + "php": "^7.2 || ^8.0", + "phpstan/phpdoc-parser": "^1.4.1", "squizlabs/php_codesniffer": "^3.6.2" }, "require-dev": { "phing/phing": "2.17.2", "php-parallel-lint/php-parallel-lint": "1.3.2", - "phpstan/phpstan": "1.4.6", + "phpstan/phpstan": "1.4.10|1.5.2", "phpstan/phpstan-deprecation-rules": "1.0.0", - "phpstan/phpstan-phpunit": "1.0.0", + "phpstan/phpstan-phpunit": "1.0.0|1.1.0", "phpstan/phpstan-strict-rules": "1.1.0", - "phpunit/phpunit": "7.5.20|8.5.21|9.5.16" + "phpunit/phpunit": "7.5.20|8.5.21|9.5.19" }, "type": "phpcodesniffer-standard", "extra": { @@ -4701,7 +4691,7 @@ "description": "Slevomat Coding Standard for PHP_CodeSniffer complements Consistence Coding Standard by providing sniffs with additional checks.", "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/7.0.19" + "source": "https://github.com/slevomat/coding-standard/tree/7.1" }, "funding": [ { @@ -4713,7 +4703,7 @@ "type": "tidelift" } ], - "time": "2022-03-01T18:01:41+00:00" + "time": "2022-03-29T12:44:16+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -5954,7 +5944,7 @@ "prefer-stable": true, "prefer-lowest": false, "platform": { - "php": "^8.0", + "php": "^8.1", "ext-ctype": "*", "ext-json": "*" }, diff --git a/phpstan.neon.dist b/phpstan.neon.dist index b26818b..acd9320 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -11,7 +11,3 @@ parameters: message: '#^Comparison operation ">" between 6 and 0 is always true\.$#' count: 1 path: ./src/Generator/CombGenerator.php - - - message: '#^Result of \|\| is always false\.$#' - count: 1 - path: ./src/Type/Time.php diff --git a/src/FeatureSet.php b/src/FeatureSet.php index aa1ec3d..038b006 100644 --- a/src/FeatureSet.php +++ b/src/FeatureSet.php @@ -61,80 +61,21 @@ use const PHP_INT_SIZE; */ class FeatureSet { - /** - * @var bool - */ - private $disable64Bit = false; - - /** - * @var bool - */ - private $ignoreSystemNode = false; - - /** - * @var bool - */ - private $enablePecl = false; - - /** - * @var UuidBuilderInterface - */ - private $builder; - - /** - * @var CodecInterface - */ - private $codec; - - /** - * @var DceSecurityGeneratorInterface - */ - private $dceSecurityGenerator; - - /** - * @var NameGeneratorInterface - */ - private $nameGenerator; - - /** - * @var NodeProviderInterface - */ - private $nodeProvider; - - /** - * @var NumberConverterInterface - */ - private $numberConverter; - - /** - * @var TimeConverterInterface - */ - private $timeConverter; - - /** - * @var RandomGeneratorInterface - */ - private $randomGenerator; - - /** - * @var TimeGeneratorInterface - */ - private $timeGenerator; - - /** - * @var TimeProviderInterface - */ - private $timeProvider; - - /** - * @var ValidatorInterface - */ - private $validator; - - /** - * @var CalculatorInterface - */ - private $calculator; + private bool $disable64Bit; + private bool $ignoreSystemNode; + private bool $enablePecl; + private UuidBuilderInterface $builder; + private CodecInterface $codec; + private DceSecurityGeneratorInterface $dceSecurityGenerator; + private NameGeneratorInterface $nameGenerator; + private NodeProviderInterface $nodeProvider; + private NumberConverterInterface $numberConverter; + private TimeConverterInterface $timeConverter; + private RandomGeneratorInterface $randomGenerator; + private TimeGeneratorInterface $timeGenerator; + private TimeProviderInterface $timeProvider; + private ValidatorInterface $validator; + private CalculatorInterface $calculator; /** * @param bool $useGuids True build UUIDs using the GuidStringCodec diff --git a/src/Provider/Dce/SystemDceSecurityProvider.php b/src/Provider/Dce/SystemDceSecurityProvider.php index 7ff4076..5c7bd19 100644 --- a/src/Provider/Dce/SystemDceSecurityProvider.php +++ b/src/Provider/Dce/SystemDceSecurityProvider.php @@ -150,7 +150,10 @@ class SystemDceSecurityProvider implements DceSecurityProviderInterface */ private function getOs(): string { - return strtoupper(substr(constant('PHP_OS'), 0, 3)); + /** @var string $os */ + $os = constant('PHP_OS'); + + return strtoupper(substr($os, 0, 3)); } /** diff --git a/src/Provider/Node/SystemNodeProvider.php b/src/Provider/Node/SystemNodeProvider.php index d512f22..79e7d97 100644 --- a/src/Provider/Node/SystemNodeProvider.php +++ b/src/Provider/Node/SystemNodeProvider.php @@ -104,8 +104,11 @@ class SystemNodeProvider implements NodeProviderInterface return ''; } + /** @var string $os */ + $os = constant('PHP_OS'); + ob_start(); - switch (strtoupper(substr(constant('PHP_OS'), 0, 3))) { + switch (strtoupper(substr($os, 0, 3))) { case 'WIN': passthru('ipconfig /all 2>&1'); @@ -142,7 +145,10 @@ class SystemNodeProvider implements NodeProviderInterface { $mac = ''; - if (strtoupper(constant('PHP_OS')) === 'LINUX') { + /** @var string $os */ + $os = constant('PHP_OS'); + + if (strtoupper($os) === 'LINUX') { $addressPaths = glob('/sys/class/net/*/address', GLOB_NOSORT); if ($addressPaths === false || count($addressPaths) === 0) { @@ -157,7 +163,7 @@ class SystemNodeProvider implements NodeProviderInterface } }); - $macs = array_map('trim', $macs); + $macs = array_map(trim(...), $macs); // @phpstan-ignore-line // Remove invalid entries. $macs = array_filter($macs, function (string $address) { diff --git a/src/Rfc4122/Fields.php b/src/Rfc4122/Fields.php index 0c54a11..735e219 100644 --- a/src/Rfc4122/Fields.php +++ b/src/Rfc4122/Fields.php @@ -46,10 +46,7 @@ final class Fields implements FieldsInterface use VariantTrait; use VersionTrait; - /** - * @var string - */ - private $bytes; + private string $bytes; /** * @param string $bytes A 16-byte binary string representation of a UUID diff --git a/src/Rfc4122/VariantTrait.php b/src/Rfc4122/VariantTrait.php index 81c0d0d..873faf1 100644 --- a/src/Rfc4122/VariantTrait.php +++ b/src/Rfc4122/VariantTrait.php @@ -19,8 +19,8 @@ use Ramsey\Uuid\Variant; use function decbin; use function str_pad; +use function str_starts_with; use function strlen; -use function strpos; use function substr; use function unpack; diff --git a/src/Type/Decimal.php b/src/Type/Decimal.php index 45d6778..02a597b 100644 --- a/src/Type/Decimal.php +++ b/src/Type/Decimal.php @@ -17,8 +17,11 @@ namespace Ramsey\Uuid\Type; use Ramsey\Uuid\Exception\InvalidArgumentException; use ValueError; +use function abs; +use function assert; use function is_numeric; use function sprintf; +use function str_starts_with; /** * A value object representing a decimal @@ -51,16 +54,25 @@ final class Decimal implements NumberInterface return $this->isNegative; } + /** + * @return numeric-string + */ public function toString(): string { return $this->value; } + /** + * @return numeric-string + */ public function __toString(): string { return $this->toString(); } + /** + * @return numeric-string + */ public function jsonSerialize(): string { return $this->toString(); diff --git a/src/Type/Time.php b/src/Type/Time.php index fdbabe0..fceca9b 100644 --- a/src/Type/Time.php +++ b/src/Type/Time.php @@ -51,18 +51,27 @@ final class Time implements TypeInterface return $this->microseconds; } + /** + * @return numeric-string + */ public function toString(): string { - return $this->seconds->toString() . '.' . $this->microseconds->toString(); + /** @var numeric-string $combined */ + $combined = $this->seconds->toString() . '.' . $this->microseconds->toString(); + + return $combined; } + /** + * @return numeric-string + */ public function __toString(): string { return $this->toString(); } /** - * @return string[] + * @return array{seconds: string, microseconds: string} */ public function jsonSerialize(): array { diff --git a/tests/BinaryUtilsTest.php b/tests/BinaryUtilsTest.php index 0a4ec16..57ef027 100644 --- a/tests/BinaryUtilsTest.php +++ b/tests/BinaryUtilsTest.php @@ -30,7 +30,7 @@ class BinaryUtilsTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideVersionTestValues(): array { diff --git a/tests/Generator/DceSecurityGeneratorTest.php b/tests/Generator/DceSecurityGeneratorTest.php index 378a04c..4097d1a 100644 --- a/tests/Generator/DceSecurityGeneratorTest.php +++ b/tests/Generator/DceSecurityGeneratorTest.php @@ -28,19 +28,14 @@ use function substr; class DceSecurityGeneratorTest extends TestCase { /** - * @param mixed $uid - * @param mixed $gid - * @param mixed $seconds - * @param mixed $microseconds - * * @dataProvider provideValuesForDceSecurityGenerator */ public function testGenerateBytesReplacesBytesWithDceValues( - $uid, - $gid, + int | string $uid, + int | string $gid, string $node, - $seconds, - $microseconds, + int $seconds, + int $microseconds, int $providedDomain, ?IntegerObject $providedId, ?Hexadecimal $providedNode, diff --git a/tests/Rfc4122/VariantTraitTest.php b/tests/Rfc4122/VariantTraitTest.php index 17251d2..0c5acdc 100644 --- a/tests/Rfc4122/VariantTraitTest.php +++ b/tests/Rfc4122/VariantTraitTest.php @@ -33,7 +33,7 @@ class VariantTraitTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function invalidBytesProvider(): array { @@ -59,7 +59,7 @@ class VariantTraitTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function uuidVariantProvider(): array { diff --git a/tests/Type/DecimalTest.php b/tests/Type/DecimalTest.php index 0708a66..f2d0ccb 100644 --- a/tests/Type/DecimalTest.php +++ b/tests/Type/DecimalTest.php @@ -16,12 +16,13 @@ use function unserialize; class DecimalTest extends TestCase { /** - * @param int|float|string $value - * * @dataProvider provideDecimal */ - public function testDecimalValueType($value, string $expected, bool $expectedIsNegative): void - { + public function testDecimalValueType( + float | int | Decimal | string $value, + string $expected, + bool $expectedIsNegative + ): void { $decimal = new Decimal($value); $this->assertSame($expected, $decimal->toString()); @@ -30,7 +31,7 @@ class DecimalTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideDecimal(): array { @@ -240,15 +241,18 @@ class DecimalTest extends TestCase 'expected' => '1234.56', 'expectedIsNegative' => false, ], + [ + 'value' => new Decimal('+1234.56'), + 'expected' => '1234.56', + 'expectedIsNegative' => false, + ], ]; } /** - * @param int|float|string $value - * * @dataProvider provideDecimalBadValues */ - public function testDecimalTypeThrowsExceptionForBadValues($value): void + public function testDecimalTypeThrowsExceptionForBadValues(string $value): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( @@ -260,7 +264,7 @@ class DecimalTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideDecimalBadValues(): array { @@ -289,11 +293,9 @@ class DecimalTest extends TestCase } /** - * @param mixed $value - * * @dataProvider provideDecimal */ - public function testJsonSerialize($value, string $expected): void + public function testJsonSerialize(float | int | Decimal | string $value, string $expected): void { $decimal = new Decimal($value); $expectedJson = sprintf('"%s"', $expected); diff --git a/tests/Type/HexadecimalTest.php b/tests/Type/HexadecimalTest.php index 1d485eb..2509bb3 100644 --- a/tests/Type/HexadecimalTest.php +++ b/tests/Type/HexadecimalTest.php @@ -18,7 +18,7 @@ class HexadecimalTest extends TestCase /** * @dataProvider provideHex */ - public function testHexadecimalType(string $value, string $expected): void + public function testHexadecimalType(Hexadecimal | string $value, string $expected): void { $hexadecimal = new Hexadecimal($value); @@ -27,7 +27,7 @@ class HexadecimalTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideHex(): array { @@ -44,6 +44,10 @@ class HexadecimalTest extends TestCase 'value' => 'ABCDEF', 'expected' => 'abcdef', ], + [ + 'value' => new Hexadecimal('ABCDEF'), + 'expected' => 'abcdef', + ], ]; } @@ -61,7 +65,7 @@ class HexadecimalTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideHexBadValues(): array { @@ -88,11 +92,9 @@ class HexadecimalTest extends TestCase } /** - * @param mixed $value - * * @dataProvider provideHex */ - public function testJsonSerialize($value, string $expected): void + public function testJsonSerialize(Hexadecimal | string $value, string $expected): void { $hexadecimal = new Hexadecimal($value); $expectedJson = sprintf('"%s"', $expected); diff --git a/tests/Type/IntegerTest.php b/tests/Type/IntegerTest.php index c57e656..9d96bbf 100644 --- a/tests/Type/IntegerTest.php +++ b/tests/Type/IntegerTest.php @@ -16,12 +16,15 @@ use function unserialize; class IntegerTest extends TestCase { /** - * @param int|float|string $value + * @param numeric-string $expected * * @dataProvider provideInteger */ - public function testIntegerType($value, string $expected, bool $expectedIsNegative): void - { + public function testIntegerType( + float | int | IntegerObject | string $value, + string $expected, + bool $expectedIsNegative + ): void { $integer = new IntegerObject($value); $this->assertSame($expected, $integer->toString()); @@ -30,7 +33,7 @@ class IntegerTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideInteger(): array { @@ -155,15 +158,18 @@ class IntegerTest extends TestCase 'expected' => '11386878954224802805705605120', 'expectedIsNegative' => false, ], + [ + 'value' => new IntegerObject('11386878954224802805705605120'), + 'expected' => '11386878954224802805705605120', + 'expectedIsNegative' => false, + ], ]; } /** - * @param int|float|string $value - * * @dataProvider provideIntegerBadValues */ - public function testIntegerTypeThrowsExceptionForBadValues($value): void + public function testIntegerTypeThrowsExceptionForBadValues(float | int | string $value): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage( @@ -175,7 +181,7 @@ class IntegerTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideIntegerBadValues(): array { @@ -195,26 +201,32 @@ class IntegerTest extends TestCase } /** - * @param mixed $value + * @param numeric-string $expected * * @dataProvider provideInteger */ - public function testSerializeUnserializeInteger($value, string $expected): void - { + public function testSerializeUnserializeInteger( + float | int | IntegerObject | string $value, + string $expected + ): void { $integer = new IntegerObject($value); $serializedInteger = serialize($integer); + + /** @var IntegerObject $unserializedInteger */ $unserializedInteger = unserialize($serializedInteger); $this->assertSame($expected, $unserializedInteger->toString()); } /** - * @param mixed $value + * @param numeric-string $expected * * @dataProvider provideInteger */ - public function testJsonSerialize($value, string $expected): void - { + public function testJsonSerialize( + float | int | IntegerObject | string $value, + string $expected + ): void { $integer = new IntegerObject($value); $expectedJson = sprintf('"%s"', $expected); diff --git a/tests/Type/TimeTest.php b/tests/Type/TimeTest.php index 5f40d8e..6adad44 100644 --- a/tests/Type/TimeTest.php +++ b/tests/Type/TimeTest.php @@ -4,8 +4,8 @@ declare(strict_types=1); namespace Ramsey\Uuid\Test\Type; -use Ramsey\Uuid\Exception\UnsupportedOperationException; use Ramsey\Uuid\Test\TestCase; +use Ramsey\Uuid\Type\Integer as IntegerObject; use Ramsey\Uuid\Type\Time; use function json_encode; @@ -15,13 +15,12 @@ use function unserialize; class TimeTest extends TestCase { /** - * @param int|float|string $seconds - * @param int|float|string|null $microseconds - * * @dataProvider provideTimeValues */ - public function testTime($seconds, $microseconds): void - { + public function testTime( + int | IntegerObject | string $seconds, + int | IntegerObject | string | null $microseconds + ): void { $params = [$seconds]; $timeString = (string) $seconds; @@ -45,7 +44,7 @@ class TimeTest extends TestCase } /** - * @phpcsSuppress SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification + * @return array */ public function provideTimeValues(): array { @@ -58,6 +57,14 @@ class TimeTest extends TestCase 'seconds' => -12219292800, 'microseconds' => 1234, ], + [ + 'seconds' => new IntegerObject(103072857659), + 'microseconds' => null, + ], + [ + 'seconds' => new IntegerObject(-12219292800), + 'microseconds' => new IntegerObject(1234), + ], ]; } @@ -90,8 +97,10 @@ class TimeTest extends TestCase /** * @dataProvider provideTimeValues */ - public function testJsonSerialize(int | IntegerObject | string $seconds, int | IntegerObject | string | null $microseconds): void - { + public function testJsonSerialize( + int | IntegerObject | string $seconds, + int | IntegerObject | string | null $microseconds + ): void { $time = [ 'seconds' => (string) $seconds, 'microseconds' => (string) $microseconds ?: '0',