From bff689c862e36fa34eb0b3044faff523123a56de Mon Sep 17 00:00:00 2001 From: azjezz Date: Fri, 14 May 2021 14:15:55 +0100 Subject: [PATCH] require php 8.0 --- .github/workflows/coding-standards.yml | 4 ++-- .github/workflows/documentation-check.yml | 4 ++-- .github/workflows/security-analysis.yml | 2 +- .github/workflows/static-analysis.yml | 2 +- .github/workflows/unit-tests.yml | 3 +-- .gitignore | 1 + Makefile | 4 ++-- composer.json | 2 +- src/Psl/Iter/contains.php | 2 +- src/Psl/Iter/contains_key.php | 4 ++-- src/Psl/Json/decode.php | 4 +--- src/Psl/Json/encode.php | 4 +--- src/Psl/Json/typed.php | 2 +- src/Psl/Math/base_convert.php | 2 -- src/Psl/Result/Success.php | 6 +++--- src/Psl/Shell/execute.php | 6 +++--- src/Psl/Str/Byte/slice.php | 5 +---- tools/php-codesniffer/composer.json | 2 +- tools/php-cs-fixer/{.php_cs.dist => .php_cs.dist.php} | 6 +----- tools/php-cs-fixer/composer.json | 6 +++--- tools/phpunit/composer.json | 4 ++-- tools/psalm/composer.json | 2 +- tools/psalm/psalm.xml | 2 +- 23 files changed, 33 insertions(+), 46 deletions(-) rename tools/php-cs-fixer/{.php_cs.dist => .php_cs.dist.php} (94%) diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml index ac4ec9f..ad3edf0 100644 --- a/.github/workflows/coding-standards.yml +++ b/.github/workflows/coding-standards.yml @@ -1,6 +1,6 @@ name: "coding standards" -on: +on: pull_request: ~ push: ~ @@ -15,7 +15,7 @@ jobs: - name: "installing PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "7.4" + php-version: "8.0" ini-values: memory_limit=-1 tools: composer:v2, cs2pr extensions: bcmath, mbstring, intl, sodium, json diff --git a/.github/workflows/documentation-check.yml b/.github/workflows/documentation-check.yml index ef2fbd0..717c05b 100644 --- a/.github/workflows/documentation-check.yml +++ b/.github/workflows/documentation-check.yml @@ -1,6 +1,6 @@ name: "documentation check" -on: +on: pull_request: ~ push: ~ @@ -15,7 +15,7 @@ jobs: - name: "installing PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "7.4" + php-version: "8.0" ini-values: memory_limit=-1 tools: composer:v2, cs2pr extensions: bcmath, mbstring, intl, sodium, json diff --git a/.github/workflows/security-analysis.yml b/.github/workflows/security-analysis.yml index 968c49e..1aa9eef 100644 --- a/.github/workflows/security-analysis.yml +++ b/.github/workflows/security-analysis.yml @@ -15,7 +15,7 @@ jobs: - name: "installing PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "7.4" + php-version: "8.0" ini-values: memory_limit=-1 tools: composer:v2, cs2pr extensions: bcmath, mbstring, intl, sodium, json diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 4c35845..0f45a98 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -17,7 +17,7 @@ jobs: - name: "installing PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "7.4" + php-version: "8.0" ini-values: memory_limit=-1 tools: composer:v2, cs2pr extensions: bcmath, mbstring, intl, sodium, json diff --git a/.github/workflows/unit-tests.yml b/.github/workflows/unit-tests.yml index 9f4d843..9bc7021 100644 --- a/.github/workflows/unit-tests.yml +++ b/.github/workflows/unit-tests.yml @@ -1,6 +1,6 @@ name: "unit tests" -on: +on: pull_request: ~ push: ~ @@ -13,7 +13,6 @@ jobs: strategy: matrix: php-version: - - "7.4" - "8.0" operating-system: - "macos-latest" diff --git a/.gitignore b/.gitignore index 6f09c26..fe5e167 100644 --- a/.gitignore +++ b/.gitignore @@ -17,6 +17,7 @@ # php-cs-fixer cache /.php_cs.cache +/.php-cs-fixer.cache # phpunit cache /tools/phpunit/.phpunit.result.cache diff --git a/Makefile b/Makefile index 39310c0..6384afc 100644 --- a/Makefile +++ b/Makefile @@ -14,11 +14,11 @@ install-unit-tests-dependencies: install: install-root-dependencies install-coding-standard-dependencies install-static-analysis-dependencies install-unit-tests-dependencies coding-standard-fix: - php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist + php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist.php php tools/php-codesniffer/vendor/bin/phpcbf --basepath=. --standard=tools/php-codesniffer/.phpcs.xml coding-standard-check: - php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist --dry-run + php tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --config=tools/php-cs-fixer/.php_cs.dist.php --dry-run php tools/php-codesniffer/vendor/bin/phpcs --basepath=. --standard=tools/php-codesniffer/.phpcs.xml static-analysis: diff --git a/composer.json b/composer.json index 19d4456..6ce1953 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-bcmath": "*", "ext-json": "*", "ext-mbstring": "*", diff --git a/src/Psl/Iter/contains.php b/src/Psl/Iter/contains.php index 2cf9108..ca038e9 100644 --- a/src/Psl/Iter/contains.php +++ b/src/Psl/Iter/contains.php @@ -24,7 +24,7 @@ namespace Psl\Iter; * @param iterable $iterable * @param T $value */ -function contains(iterable $iterable, $value): bool +function contains(iterable $iterable, mixed $value): bool { foreach ($iterable as $v) { if ($value === $v) { diff --git a/src/Psl/Iter/contains_key.php b/src/Psl/Iter/contains_key.php index 35376d9..03919a5 100644 --- a/src/Psl/Iter/contains_key.php +++ b/src/Psl/Iter/contains_key.php @@ -10,10 +10,10 @@ namespace Psl\Iter; * @template Tk * @template Tv * - * @param iterable $iterable, + * @param iterable $iterable * @param Tk $key */ -function contains_key(iterable $iterable, $key): bool +function contains_key(iterable $iterable, mixed $key): bool { foreach ($iterable as $k => $_v) { if ($key === $k) { diff --git a/src/Psl/Json/decode.php b/src/Psl/Json/decode.php index b95ca5a..1ed4425 100644 --- a/src/Psl/Json/decode.php +++ b/src/Psl/Json/decode.php @@ -17,11 +17,9 @@ use const JSON_THROW_ON_ERROR; * * @throws Exception\DecodeException If an error occurred. * - * @return mixed - * * @pure */ -function decode(string $json, bool $assoc = true) +function decode(string $json, bool $assoc = true): mixed { try { /** @var mixed $value */ diff --git a/src/Psl/Json/encode.php b/src/Psl/Json/encode.php index 327b454..d2d823e 100644 --- a/src/Psl/Json/encode.php +++ b/src/Psl/Json/encode.php @@ -18,13 +18,11 @@ use const JSON_UNESCAPED_UNICODE; /** * Returns a string containing the JSON representation of the supplied value. * - * @param mixed $value - * * @pure * * @throws Exception\EncodeException If an error occurred. */ -function encode($value, bool $pretty = false, int $flags = 0): string +function encode(mixed $value, bool $pretty = false, int $flags = 0): string { $flags |= JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES diff --git a/src/Psl/Json/typed.php b/src/Psl/Json/typed.php index ba34355..c292fc2 100644 --- a/src/Psl/Json/typed.php +++ b/src/Psl/Json/typed.php @@ -17,7 +17,7 @@ use Psl\Type; * * @return T */ -function typed(string $json, Type\TypeInterface $type) +function typed(string $json, Type\TypeInterface $type): mixed { try { return $type->coerce(decode($json)); diff --git a/src/Psl/Math/base_convert.php b/src/Psl/Math/base_convert.php index 05633c3..cc52618 100644 --- a/src/Psl/Math/base_convert.php +++ b/src/Psl/Math/base_convert.php @@ -49,7 +49,6 @@ function base_convert(string $value, int $from_base, int $to_base): string Psl\invariant($to_base >= 2 && $to_base <= 36, 'Expected $to_base to be between 2 and 36, got %d', $to_base); $from_alphabet = Byte\slice(Str\ALPHABET_ALPHANUMERIC, 0, $from_base); - /** @var numeric-string $result_decimal */ $result_decimal = '0'; $place_value = bcpow((string)$from_base, (string)(Byte\length($value) - 1)); foreach (Byte\chunk($value) as $digit) { @@ -69,7 +68,6 @@ function base_convert(string $value, int $from_base, int $to_base): string $result = ''; do { $result = $to_alphabet[(int)bcmod($result_decimal, (string)$to_base)] . $result; - /** @var numeric-string $result_decimal */ $result_decimal = bcdiv($result_decimal, (string)$to_base); } while (bccomp($result_decimal, '0') > 0); diff --git a/src/Psl/Result/Success.php b/src/Psl/Result/Success.php index 367e5e4..bb4d2e0 100644 --- a/src/Psl/Result/Success.php +++ b/src/Psl/Result/Success.php @@ -21,12 +21,12 @@ final class Success implements ResultInterface * * @readonly */ - private $value; + private mixed $value; /** * @param T $value */ - public function __construct($value) + public function __construct(mixed $value) { $this->value = $value; } @@ -38,7 +38,7 @@ final class Success implements ResultInterface * * @psalm-mutation-free */ - public function getResult() + public function getResult(): mixed { return $this->value; } diff --git a/src/Psl/Shell/execute.php b/src/Psl/Shell/execute.php index dc44bd2..676f0e2 100644 --- a/src/Psl/Shell/execute.php +++ b/src/Psl/Shell/execute.php @@ -21,9 +21,9 @@ use function stream_get_contents; * * @param string $command The command to execute. * @param list $arguments The command arguments listed as separate entries. - * @param string $working_directory The initial working directory for the command. - * This must be an absolute directory path, or null if you want to - * use the default value ( the current directory ) + * @param null|string $working_directory The initial working directory for the command. + * This must be an absolute directory path, or null if you want to + * use the default value ( the current directory ) * @param array $environment A dict with the environment variables for the command that * will be run. * @param bool $escape_arguments If set to true ( default ), all $arguments will be escaped using `escape_argument`. diff --git a/src/Psl/Str/Byte/slice.php b/src/Psl/Str/Byte/slice.php index c8fc910..9dd00e4 100644 --- a/src/Psl/Str/Byte/slice.php +++ b/src/Psl/Str/Byte/slice.php @@ -23,9 +23,6 @@ function slice(string $string, int $offset, ?int $length = null): string { Psl\invariant(null === $length || $length >= 0, 'Expected a non-negative length.'); $offset = Psl\Internal\validate_offset($offset, length($string)); - $result = null === $length - ? substr($string, $offset) - : substr($string, $offset, $length); - return false === $result ? '' : $result; + return null === $length ? substr($string, $offset) : substr($string, $offset, $length); } diff --git a/tools/php-codesniffer/composer.json b/tools/php-codesniffer/composer.json index 8c33640..adba8bb 100644 --- a/tools/php-codesniffer/composer.json +++ b/tools/php-codesniffer/composer.json @@ -1,7 +1,7 @@ { "type": "project", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-bcmath": "*", "ext-intl": "*", "ext-json": "*", diff --git a/tools/php-cs-fixer/.php_cs.dist b/tools/php-cs-fixer/.php_cs.dist.php similarity index 94% rename from tools/php-cs-fixer/.php_cs.dist rename to tools/php-cs-fixer/.php_cs.dist.php index 8af7810..4781150 100644 --- a/tools/php-cs-fixer/.php_cs.dist +++ b/tools/php-cs-fixer/.php_cs.dist.php @@ -1,6 +1,6 @@ setFinder( \Symfony\Component\Finder\Finder::create() ->in([ @@ -25,14 +25,10 @@ return PhpCsFixer\Config::create() 'list_syntax' => [ 'syntax' => 'short', ], - 'lowercase_constants' => true, 'multiline_comment_opening_closing' => true, 'native_function_casing' => true, 'no_empty_phpdoc' => true, 'no_leading_import_slash' => true, - 'no_superfluous_phpdoc_tags' => [ - 'allow_mixed' => true, - ], 'no_unused_imports' => true, 'no_useless_else' => true, 'no_useless_return' => true, diff --git a/tools/php-cs-fixer/composer.json b/tools/php-cs-fixer/composer.json index b9b8a80..9718047 100644 --- a/tools/php-cs-fixer/composer.json +++ b/tools/php-cs-fixer/composer.json @@ -1,12 +1,12 @@ { "type": "project", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-bcmath": "*", "ext-intl": "*", "ext-json": "*", "ext-mbstring": "*", "ext-sodium": "*", - "friendsofphp/php-cs-fixer": "^2.18" + "friendsofphp/php-cs-fixer": "^3.0" } -} \ No newline at end of file +} diff --git a/tools/phpunit/composer.json b/tools/phpunit/composer.json index 4f7832d..eee86e7 100644 --- a/tools/phpunit/composer.json +++ b/tools/phpunit/composer.json @@ -1,7 +1,7 @@ { "type": "project", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-bcmath": "*", "ext-intl": "*", "ext-json": "*", @@ -9,4 +9,4 @@ "ext-sodium": "*", "phpunit/phpunit": "^9.5" } -} \ No newline at end of file +} diff --git a/tools/psalm/composer.json b/tools/psalm/composer.json index 09169f1..e097607 100644 --- a/tools/psalm/composer.json +++ b/tools/psalm/composer.json @@ -1,7 +1,7 @@ { "type": "project", "require": { - "php": "^7.4 || ^8.0", + "php": "^8.0", "ext-bcmath": "*", "ext-intl": "*", "ext-json": "*", diff --git a/tools/psalm/psalm.xml b/tools/psalm/psalm.xml index 36250cc..e48f7b9 100644 --- a/tools/psalm/psalm.xml +++ b/tools/psalm/psalm.xml @@ -1,5 +1,5 @@ - +