From b1cec77602dac6da2ffba3a7db59c48229ee561b Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:24:37 +0100 Subject: [PATCH 01/11] feat: drop support for EOLed php --- .github/workflows/test.yaml | 8 +++--- .gitignore | 2 +- .php_cs.dist => .php-cs-fixer.dist.php | 4 ++- composer.json | 6 ++--- src/Functional/Matching.php | 20 --------------- src/Functional/ValueToKey.php | 35 +++++++------------------- tests/Functional/AbstractTestCase.php | 20 ++++++--------- tests/Functional/MatchingTest.php | 16 ------------ tests/Functional/ValueToKeyTest.php | 21 +++++----------- 9 files changed, 33 insertions(+), 99 deletions(-) rename .php_cs.dist => .php-cs-fixer.dist.php (78%) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 2c581fd1..96e9dea7 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -12,11 +12,9 @@ jobs: fail-fast: false matrix: php-version: - - 7.1 - - 7.2 - - 7.3 - - 7.4 - - 8.0 + - 8.1 + - 8.2 + - 8.3 experimental: [false] include: - php-version: 8.1 diff --git a/.gitignore b/.gitignore index 09e8c9d5..16ec26f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ build/ vendor/ -.php_cs.cache +.php-cs-fixer.cache composer.lock phpcs.xml phpunit.xml diff --git a/.php_cs.dist b/.php-cs-fixer.dist.php similarity index 78% rename from .php_cs.dist rename to .php-cs-fixer.dist.php index 4238d7e8..adf94efc 100644 --- a/.php_cs.dist +++ b/.php-cs-fixer.dist.php @@ -1,6 +1,8 @@ setRiskyAllowed(true) ->setRules([ 'native_function_invocation' => true, diff --git a/composer.json b/composer.json index ebfe9738..d12bae3f 100644 --- a/composer.json +++ b/composer.json @@ -17,12 +17,12 @@ } ], "require": { - "php": "^7.1|~8" + "php": "~8.1" }, "require-dev": { "squizlabs/php_codesniffer": "~3.0", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.5", - "friendsofphp/php-cs-fixer": "^2.17" + "phpunit/phpunit": "^9.5", + "friendsofphp/php-cs-fixer": "^v3.49" }, "autoload": { "psr-4": { diff --git a/src/Functional/Matching.php b/src/Functional/Matching.php index d941f86a..02d28c88 100644 --- a/src/Functional/Matching.php +++ b/src/Functional/Matching.php @@ -12,12 +12,6 @@ use Functional\Exceptions\MatchException; -use function Functional\head; -use function Functional\tail; -use function Functional\if_else; - -use const PHP_VERSION_ID; - /** * Performs an operation checking for the given conditions * @@ -40,17 +34,3 @@ function matching(array $conditions) return if_else($if, $then, matching(tail($conditions)))($value); }; } - - -if (PHP_VERSION_ID < 80000 && !\function_exists('Functional\match')) { - eval(<<<'ALIAS' -namespace Functional; - -/** @no-named-arguments */ -function match(array $conditions) { - trigger_error('Functional\match() will be unavailable with PHP 8. Use Functional\matching() instead', E_USER_DEPRECATED); - return matching($conditions); -} -ALIAS - ); -} diff --git a/src/Functional/ValueToKey.php b/src/Functional/ValueToKey.php index 345723f7..267a2e72 100644 --- a/src/Functional/ValueToKey.php +++ b/src/Functional/ValueToKey.php @@ -14,10 +14,6 @@ use Traversable; use WeakReference; -use function serialize; - -use const PHP_VERSION_ID; - /** * @no-named-arguments */ @@ -34,33 +30,20 @@ function value_to_key(...$any) * spl_object_hash() will return the same hash twice in a single request if an object goes out of scope * and is destructed. */ - if (PHP_VERSION_ID >= 70400) { - /** - * For PHP >=7.4, we keep a weak reference to the relevant object that we use for hashing. Once the - * object gets out of scope, the weak ref will no longer return the object, that’s how we know we - * have a collision and increment a version in the collisions array. - */ - /** @var int[] $collisions */ - static $collisions = []; + /** @var int[] $collisions */ + static $collisions = []; - if (isset($objectReferences[$hash])) { - if ($objectReferences[$hash]->get() === null) { - $collisions[$hash] = ($collisions[$hash] ?? 0) + 1; - $objectReferences[$hash] = WeakReference::create($value); - } - } else { + if (isset($objectReferences[$hash])) { + if ($objectReferences[$hash]->get() === null) { + $collisions[$hash] = ($collisions[$hash] ?? 0) + 1; $objectReferences[$hash] = WeakReference::create($value); } - - $key = \get_class($value) . ':' . $hash . ':' . ($collisions[$hash] ?? 0); } else { - /** - * For PHP < 7.4 we keep a static reference to the object so that cannot accidentally go out of - * scope and mess with the object hashes - */ - $objectReferences[$hash] = $value; - $key = \get_class($value) . ':' . $hash; + $objectReferences[$hash] = WeakReference::create($value); } + + $key = \get_class($value) . ':' . $hash . ':' . ($collisions[$hash] ?? 0); + return $key; }; } diff --git a/tests/Functional/AbstractTestCase.php b/tests/Functional/AbstractTestCase.php index 30657653..4f4e1ed5 100644 --- a/tests/Functional/AbstractTestCase.php +++ b/tests/Functional/AbstractTestCase.php @@ -42,18 +42,14 @@ protected function expectCallableArgumentError(string $fn, int $position, string { $this->expectException(TypeError::class); - if (PHP_VERSION_ID < 80000) { - $this->expectExceptionMessage(\sprintf('Argument %d passed to %s() must be callable', $position, $fn)); - } else { - $this->expectExceptionMessageMatches( - \sprintf( - '/^%s\(\): Argument \#%d( \(\$callback\))? must be of type \??callable, %s given.*/', - \preg_quote($fn, '/'), - $position, - $actualType - ) - ); - } + $this->expectExceptionMessageMatches( + \sprintf( + '/^%s\(\): Argument \#%d( \(\$callback\))? must be of type \??callable, %s given.*/', + \preg_quote($fn, '/'), + $position, + $actualType + ) + ); } public function exception(): void diff --git a/tests/Functional/MatchingTest.php b/tests/Functional/MatchingTest.php index df7b16de..5d5c5bdd 100644 --- a/tests/Functional/MatchingTest.php +++ b/tests/Functional/MatchingTest.php @@ -16,8 +16,6 @@ use function Functional\equal; use function Functional\const_function; -use const PHP_VERSION_ID; - class MatchingTest extends AbstractTestCase { public function testMatching(): void @@ -94,18 +92,4 @@ public function testMatchingConditionCallables(): void ] ); } - - public function testDeprecatedAlias(): void - { - if (PHP_VERSION_ID >= 80000) { - self::markTestSkipped('Only works with PHP <8.0'); - } - - $this->expectDeprecation(); - $this->expectDeprecationMessage( - 'Functional\match() will be unavailable with PHP 8. Use Functional\matching() instead' - ); - - \call_user_func('Functional\match', []); - } } diff --git a/tests/Functional/ValueToKeyTest.php b/tests/Functional/ValueToKeyTest.php index ef4ce0da..665e6cdc 100644 --- a/tests/Functional/ValueToKeyTest.php +++ b/tests/Functional/ValueToKeyTest.php @@ -21,7 +21,6 @@ use function Functional\value_to_key; use const NAN; -use const PHP_VERSION_ID; class ValueToKeyTest extends AbstractTestCase { @@ -120,13 +119,9 @@ public function testObjectReferencesWithStdClass(): void 'Can extract object hash from key2' ); - if (PHP_VERSION_ID >= 70400) { - self::assertSame($key1Matches['hash'], $key2Matches['hash'], 'Object hashes match'); - self::assertSame('[i:0;~stdClass:' . $key1Matches['hash'] . ':0]', $key1, 'Object versions do not match'); - self::assertSame('[i:0;~stdClass:' . $key1Matches['hash'] . ':1]', $key2, 'Object versions do not match'); - } else { - self::assertNotSame($key1Matches['hash'], $key2Matches['hash'], 'Object hashes should not match'); - } + self::assertSame($key1Matches['hash'], $key2Matches['hash'], 'Object hashes match'); + self::assertSame('[i:0;~stdClass:' . $key1Matches['hash'] . ':0]', $key1, 'Object versions do not match'); + self::assertSame('[i:0;~stdClass:' . $key1Matches['hash'] . ':1]', $key2, 'Object versions do not match'); } public function testObjectReferencesWithArrayObject(): void @@ -146,13 +141,9 @@ public function testObjectReferencesWithArrayObject(): void 'Can extract object hash from key2' ); - if (PHP_VERSION_ID >= 70400) { - self::assertSame($key1Matches['hash'], $key2Matches['hash'], 'Object hashes match'); - self::assertSame('[i:0;~ArrayObject:' . $key1Matches['hash'] . ':2[]]', $key1, 'Object versions do not match'); - self::assertSame('[i:0;~ArrayObject:' . $key1Matches['hash'] . ':3[s:3:"foo";~s:3:"bar";]]', $key2, 'Object versions do not match'); - } else { - self::assertNotSame($key1Matches['hash'], $key2Matches['hash'], 'Object hashes don’t match'); - } + self::assertSame($key1Matches['hash'], $key2Matches['hash'], 'Object hashes match'); + self::assertSame('[i:0;~ArrayObject:' . $key1Matches['hash'] . ':2[]]', $key1, 'Object versions do not match'); + self::assertSame('[i:0;~ArrayObject:' . $key1Matches['hash'] . ':3[s:3:"foo";~s:3:"bar";]]', $key2, 'Object versions do not match'); } private static function createObjectRefRegex(string $class = '.*'): string From c18be77000dbd190cc72a11d8ddb3a2ebfe24c67 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:30:04 +0100 Subject: [PATCH 02/11] style: run cs fix --- .php-cs-fixer.dist.php | 1 + src/Functional/Average.php | 2 +- src/Functional/ButLast.php | 5 +- src/Functional/Compose.php | 2 +- src/Functional/Concat.php | 2 +- src/Functional/Curry.php | 12 ++- src/Functional/CurryN.php | 8 +- src/Functional/Difference.php | 2 +- src/Functional/ErrorToException.php | 4 +- .../Exceptions/InvalidArgumentException.php | 92 +++++++++++-------- src/Functional/Exceptions/MatchException.php | 20 ++-- src/Functional/FirstIndexOf.php | 3 +- src/Functional/FlatMap.php | 3 +- src/Functional/Flatten.php | 9 +- src/Functional/Flip.php | 3 +- src/Functional/GreaterThan.php | 3 +- src/Functional/GreaterThanOrEqual.php | 3 +- src/Functional/IndexesOf.php | 3 +- src/Functional/Intersperse.php | 2 +- src/Functional/Invoke.php | 3 +- src/Functional/InvokeFirst.php | 3 +- src/Functional/InvokeIf.php | 3 +- src/Functional/InvokeLast.php | 3 +- src/Functional/LastIndexOf.php | 3 +- src/Functional/LessThan.php | 3 +- src/Functional/LessThanOrEqual.php | 3 +- src/Functional/LexicographicCompare.php | 3 +- src/Functional/Maximum.php | 2 +- src/Functional/Memoize.php | 14 +-- src/Functional/Minimum.php | 2 +- src/Functional/OmitKeys.php | 4 +- src/Functional/PartialAny.php | 7 +- src/Functional/PartialLeft.php | 2 +- src/Functional/PartialMethod.php | 3 +- src/Functional/PartialRight.php | 2 +- src/Functional/Partition.php | 3 +- src/Functional/Pick.php | 4 +- src/Functional/Pluck.php | 6 +- src/Functional/Poll.php | 6 +- src/Functional/Product.php | 2 +- src/Functional/Ratio.php | 2 +- src/Functional/ReduceRight.php | 2 +- src/Functional/Retry.php | 4 +- src/Functional/SelectKeys.php | 4 +- .../Sequences/ExponentialSequence.php | 2 +- src/Functional/Sort.php | 2 +- src/Functional/Sum.php | 2 +- src/Functional/SuppressError.php | 4 +- src/Functional/TailRecursion.php | 2 +- src/Functional/TakeLeft.php | 6 +- src/Functional/TakeRight.php | 6 +- src/Functional/Unique.php | 3 +- src/Functional/ValueToKey.php | 14 +-- src/Functional/With.php | 5 +- src/Functional/Zip.php | 7 +- src/Functional/ZipAll.php | 7 +- tests/Functional/AbstractTestCase.php | 19 ++-- tests/Functional/AnnotationsTest.php | 10 +- tests/Functional/AverageTest.php | 6 +- tests/Functional/ComposeTest.php | 10 +- tests/Functional/CurryNTest.php | 17 ++-- tests/Functional/DropTest.php | 3 +- tests/Functional/EntriesFromEntriesTest.php | 11 ++- tests/Functional/ErrorToExceptionTest.php | 8 +- tests/Functional/EveryTest.php | 2 +- .../InvalidArgumentExceptionTest.php | 24 ++--- tests/Functional/FirstTest.php | 2 +- tests/Functional/FlattenTest.php | 4 +- tests/Functional/FlipTest.php | 2 +- tests/Functional/FunctionalTest.php | 16 ++-- tests/Functional/GroupTest.php | 15 +-- tests/Functional/InvokeFirstTest.php | 6 +- tests/Functional/InvokeIfTest.php | 6 +- tests/Functional/InvokeLastTest.php | 6 +- tests/Functional/InvokeTest.php | 6 +- tests/Functional/InvokerTest.php | 2 +- tests/Functional/MathDataProvider.php | 2 +- tests/Functional/MemoizeTest.php | 6 +- tests/Functional/NoneTest.php | 3 +- tests/Functional/OmitKeysTest.php | 3 +- tests/Functional/PartialAnyTest.php | 7 +- tests/Functional/PartitionTest.php | 7 +- tests/Functional/PluckTest.php | 19 ++-- tests/Functional/PollTest.php | 2 +- tests/Functional/RejectTest.php | 3 +- tests/Functional/SelectKeysTest.php | 3 +- tests/Functional/SelectTest.php | 5 +- tests/Functional/SortTest.php | 2 +- tests/Functional/SuppressErrorTest.php | 8 +- tests/Functional/TapTest.php | 3 +- tests/Functional/ValueToKeyTest.php | 22 ++--- tests/Functional/WithTest.php | 3 +- tests/Functional/ZipAllTest.php | 5 +- tests/Functional/ZipTest.php | 2 +- 94 files changed, 353 insertions(+), 259 deletions(-) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index adf94efc..ae0f0c21 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -5,6 +5,7 @@ return (new Config()) ->setRiskyAllowed(true) ->setRules([ + 'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true], 'native_function_invocation' => true, ]) ->setFinder(PhpCsFixer\Finder::create()->in(__DIR__)); diff --git a/src/Functional/Average.php b/src/Functional/Average.php index e9915707..419001ae 100644 --- a/src/Functional/Average.php +++ b/src/Functional/Average.php @@ -28,7 +28,7 @@ function average($collection) $divisor = 0; foreach ($collection as $element) { - if (\is_numeric($element)) { + if (is_numeric($element)) { $sum += $element; ++$divisor; } diff --git a/src/Functional/ButLast.php b/src/Functional/ButLast.php index 4f6d314c..1581dbbe 100644 --- a/src/Functional/ButLast.php +++ b/src/Functional/ButLast.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_array; /** * Returns an array containing the elements of the list without its last element. @@ -24,8 +25,8 @@ function but_last($collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1); - $butLast = \is_array($collection) ? $collection : \iterator_to_array($collection); - \array_pop($butLast); + $butLast = is_array($collection) ? $collection : iterator_to_array($collection); + array_pop($butLast); return $butLast; } diff --git a/src/Functional/Compose.php b/src/Functional/Compose.php index b8202d5e..6982f541 100644 --- a/src/Functional/Compose.php +++ b/src/Functional/Compose.php @@ -21,7 +21,7 @@ */ function compose(...$functions) { - return \array_reduce( + return array_reduce( $functions, function ($carry, $item) { return function ($x) use ($carry, $item) { diff --git a/src/Functional/Concat.php b/src/Functional/Concat.php index 09426c6e..005e3e05 100644 --- a/src/Functional/Concat.php +++ b/src/Functional/Concat.php @@ -19,5 +19,5 @@ */ function concat(string ...$strings) { - return \implode('', $strings); + return implode('', $strings); } diff --git a/src/Functional/Curry.php b/src/Functional/Curry.php index 52099360..dcc35caf 100644 --- a/src/Functional/Curry.php +++ b/src/Functional/Curry.php @@ -13,6 +13,10 @@ use ReflectionMethod; use ReflectionFunction; use Closure; +use function count; +use function is_array; +use function is_object; +use function is_string; /** * Return a curryied version of the given function. You can decide if you also @@ -25,15 +29,15 @@ */ function curry(callable $function, $required = true) { - if (\method_exists('Closure', 'fromCallable')) { + if (method_exists('Closure', 'fromCallable')) { // Closure::fromCallable was introduced in PHP 7.1 $reflection = new ReflectionFunction(Closure::fromCallable($function)); } else { - if (\is_string($function) && \strpos($function, '::', 1) !== false) { + if (is_string($function) && strpos($function, '::', 1) !== false) { $reflection = new ReflectionMethod($function); - } elseif (\is_array($function) && \count($function) === 2) { + } elseif (is_array($function) && count($function) === 2) { $reflection = new ReflectionMethod($function[0], $function[1]); - } elseif (\is_object($function) && \method_exists($function, '__invoke')) { + } elseif (is_object($function) && method_exists($function, '__invoke')) { $reflection = new ReflectionMethod($function, '__invoke'); } else { $reflection = new ReflectionFunction($function); diff --git a/src/Functional/CurryN.php b/src/Functional/CurryN.php index 780e34c9..802c877b 100644 --- a/src/Functional/CurryN.php +++ b/src/Functional/CurryN.php @@ -9,6 +9,8 @@ */ namespace Functional; +use function call_user_func_array; +use function count; /** * Return a version of the given function where the $count first arguments are curryied. @@ -26,10 +28,10 @@ function curry_n($count, callable $function) { $accumulator = function (array $arguments) use ($count, $function, &$accumulator) { return function (...$newArguments) use ($count, $function, $arguments, $accumulator) { - $arguments = \array_merge($arguments, $newArguments); + $arguments = array_merge($arguments, $newArguments); - if ($count <= \count($arguments)) { - return \call_user_func_array($function, $arguments); + if ($count <= count($arguments)) { + return call_user_func_array($function, $arguments); } return $accumulator($arguments); diff --git a/src/Functional/Difference.php b/src/Functional/Difference.php index 8984eb12..dc886f5b 100644 --- a/src/Functional/Difference.php +++ b/src/Functional/Difference.php @@ -27,7 +27,7 @@ function difference($collection, $initial = 0) $result = $initial; foreach ($collection as $value) { - if (\is_numeric($value)) { + if (is_numeric($value)) { $result -= $value; } } diff --git a/src/Functional/ErrorToException.php b/src/Functional/ErrorToException.php index 5051bc45..32f30c07 100644 --- a/src/Functional/ErrorToException.php +++ b/src/Functional/ErrorToException.php @@ -24,7 +24,7 @@ function error_to_exception(callable $callback) { return function (...$arguments) use ($callback) { try { - \set_error_handler( + set_error_handler( static function ($level, $message, $file, $line) { throw new ErrorException($message, 0, $level, $file, $line); } @@ -32,7 +32,7 @@ static function ($level, $message, $file, $line) { return $callback(...$arguments); } finally { - \restore_error_handler(); + restore_error_handler(); } }; } diff --git a/src/Functional/Exceptions/InvalidArgumentException.php b/src/Functional/Exceptions/InvalidArgumentException.php index b4d61675..d87d42e0 100644 --- a/src/Functional/Exceptions/InvalidArgumentException.php +++ b/src/Functional/Exceptions/InvalidArgumentException.php @@ -9,6 +9,18 @@ */ namespace Functional\Exceptions; +use function count; +use function get_class; +use function gettype; +use function in_array; +use function is_array; +use function is_bool; +use function is_callable; +use function is_float; +use function is_int; +use function is_null; +use function is_object; +use function is_string; /** @internal */ class InvalidArgumentException extends \InvalidArgumentException @@ -21,10 +33,10 @@ class InvalidArgumentException extends \InvalidArgumentException */ public static function assertCallback($callback, $callee, $parameterPosition) { - if (!\is_callable($callback)) { - if (!\is_array($callback) && !\is_string($callback)) { + if (!is_callable($callback)) { + if (!is_array($callback) && !is_string($callback)) { throw new static( - \sprintf( + sprintf( '%s() expected parameter %d to be a valid callback, no array, string, closure or functor given', $callee, $parameterPosition @@ -32,19 +44,19 @@ public static function assertCallback($callback, $callee, $parameterPosition) ); } - $type = \gettype($callback); + $type = gettype($callback); switch ($type) { case 'array': $type = 'method'; - $callback = \array_values($callback); + $callback = array_values($callback); $sep = '::'; - if (\is_object($callback[0])) { - $callback[0] = \get_class($callback[0]); + if (is_object($callback[0])) { + $callback[0] = get_class($callback[0]); $sep = '->'; } - $callback = \implode($sep, $callback); + $callback = implode($sep, $callback); break; default: @@ -53,7 +65,7 @@ public static function assertCallback($callback, $callee, $parameterPosition) } throw new static( - \sprintf( + sprintf( "%s() expects parameter %d to be a valid callback, %s '%s' not found or invalid %s name", $callee, $parameterPosition, @@ -77,9 +89,9 @@ public static function assertArrayAccess($collection, $callee, $parameterPositio public static function assertMethodName($methodName, $callee, $parameterPosition) { - if (!\is_string($methodName)) { + if (!is_string($methodName)) { throw new static( - \sprintf( + sprintf( '%s() expects parameter %d to be string, %s given', $callee, $parameterPosition, @@ -98,13 +110,13 @@ public static function assertMethodName($methodName, $callee, $parameterPosition public static function assertPropertyName($propertyName, $callee, $parameterPosition) { if ( - !\is_string($propertyName) && - !\is_int($propertyName) && - !\is_float($propertyName) && - !\is_null($propertyName) + !is_string($propertyName) && + !is_int($propertyName) && + !is_float($propertyName) && + !is_null($propertyName) ) { throw new static( - \sprintf( + sprintf( '%s() expects parameter %d to be a valid property name or array index, %s given', $callee, $parameterPosition, @@ -121,7 +133,7 @@ public static function assertPositiveInteger($value, $callee, $parameterPosition $type = $type === 'integer' ? 'negative integer' : $type; throw new static( - \sprintf( + sprintf( '%s() expects parameter %d to be positive integer, %s given', $callee, $parameterPosition, @@ -140,16 +152,16 @@ public static function assertValidArrayKey($key, $callee) { $keyTypes = ['NULL', 'string', 'integer', 'double', 'boolean']; - $keyType = \gettype($key); + $keyType = gettype($key); - if (!\in_array($keyType, $keyTypes, true)) { + if (!in_array($keyType, $keyTypes, true)) { throw new static( - \sprintf( + sprintf( '%s(): callback returned invalid array key of type "%s". Expected %4$s or %3$s', $callee, $keyType, - \array_pop($keyTypes), - \implode(', ', $keyTypes) + array_pop($keyTypes), + implode(', ', $keyTypes) ) ); } @@ -159,7 +171,7 @@ public static function assertArrayKeyExists($collection, $key, $callee) { if (!isset($collection[$key])) { throw new static( - \sprintf( + sprintf( '%s(): unknown key "%s"', $callee, $key @@ -176,9 +188,9 @@ public static function assertArrayKeyExists($collection, $key, $callee) */ public static function assertBoolean($value, $callee, $parameterPosition) { - if (!\is_bool($value)) { + if (!is_bool($value)) { throw new static( - \sprintf( + sprintf( '%s() expects parameter %d to be boolean, %s given', $callee, $parameterPosition, @@ -196,9 +208,9 @@ public static function assertBoolean($value, $callee, $parameterPosition) */ public static function assertInteger($value, $callee, $parameterPosition) { - if (!\is_int($value)) { + if (!is_int($value)) { throw new static( - \sprintf( + sprintf( '%s() expects parameter %d to be integer, %s given', $callee, $parameterPosition, @@ -217,9 +229,9 @@ public static function assertInteger($value, $callee, $parameterPosition) */ public static function assertIntegerGreaterThanOrEqual($value, $limit, $callee, $parameterPosition) { - if (!\is_int($value) || $value < $limit) { + if (!is_int($value) || $value < $limit) { throw new static( - \sprintf( + sprintf( '%s() expects parameter %d to be an integer greater than or equal to %d', $callee, $parameterPosition, @@ -238,9 +250,9 @@ public static function assertIntegerGreaterThanOrEqual($value, $limit, $callee, */ public static function assertIntegerLessThanOrEqual($value, $limit, $callee, $parameterPosition) { - if (!\is_int($value) || $value > $limit) { + if (!is_int($value) || $value > $limit) { throw new static( - \sprintf( + sprintf( '%s() expects parameter %d to be an integer less than or equal to %d', $callee, $parameterPosition, @@ -252,9 +264,9 @@ public static function assertIntegerLessThanOrEqual($value, $limit, $callee, $pa public static function assertResolvablePlaceholder(array $args, $position) { - if (\count($args) === 0) { + if (count($args) === 0) { throw new static( - \sprintf('Cannot resolve parameter placeholder at position %d. Parameter stack is empty.', $position) + sprintf('Cannot resolve parameter placeholder at position %d. Parameter stack is empty.', $position) ); } } @@ -268,9 +280,9 @@ public static function assertResolvablePlaceholder(array $args, $position) */ private static function assertCollectionAlike($collection, $className, $callee, $parameterPosition) { - if (!\is_array($collection) && !$collection instanceof $className) { + if (!is_array($collection) && !$collection instanceof $className) { throw new static( - \sprintf( + sprintf( '%s() expects parameter %d to be array or instance of %s, %s given', $callee, $parameterPosition, @@ -283,20 +295,20 @@ private static function assertCollectionAlike($collection, $className, $callee, public static function assertNonZeroInteger($value, $callee) { - if (!\is_int($value) || $value == 0) { - throw new static(\sprintf('%s expected parameter %d to be non-zero', $callee, $value)); + if (!is_int($value) || $value == 0) { + throw new static(sprintf('%s expected parameter %d to be non-zero', $callee, $value)); } } public static function assertPair($pair, $callee, $position): void { - if (!(\is_array($pair) || $pair instanceof ArrayAccess) || !isset($pair[0], $pair[1])) { - throw new static(\sprintf('%s() expects paramter %d to be a pair (array with two elements)', $callee, $position)); + if (!(is_array($pair) || $pair instanceof ArrayAccess) || !isset($pair[0], $pair[1])) { + throw new static(sprintf('%s() expects paramter %d to be a pair (array with two elements)', $callee, $position)); } } private static function getType($value) { - return \is_object($value) ? \get_class($value) : \gettype($value); + return is_object($value) ? get_class($value) : gettype($value); } } diff --git a/src/Functional/Exceptions/MatchException.php b/src/Functional/Exceptions/MatchException.php index f2df898a..55e941f2 100644 --- a/src/Functional/Exceptions/MatchException.php +++ b/src/Functional/Exceptions/MatchException.php @@ -9,6 +9,10 @@ */ namespace Functional\Exceptions; +use function count; +use function gettype; +use function is_array; +use function is_callable; /** @internal */ class MatchException extends InvalidArgumentException @@ -24,13 +28,13 @@ public static function assert(array $conditions, $callee) private static function assertArray($key, $condition, $callee) { - if (!\is_array($condition)) { + if (!is_array($condition)) { throw new static( - \sprintf( + sprintf( '%s() expects condition at key %d to be array, %s given', $callee, $key, - \gettype($condition) + gettype($condition) ) ); } @@ -38,13 +42,13 @@ private static function assertArray($key, $condition, $callee) private static function assertLength($key, $condition, $callee) { - if (\count($condition) < 2) { + if (count($condition) < 2) { throw new static( - \sprintf( + sprintf( '%s() expects size of condition at key %d to be greater than or equals to 2, %d given', $callee, $key, - \count($condition) + count($condition) ) ); } @@ -52,9 +56,9 @@ private static function assertLength($key, $condition, $callee) private static function assertCallables($key, $condition, $callee) { - if (!\is_callable($condition[0]) || !\is_callable($condition[1])) { + if (!is_callable($condition[0]) || !is_callable($condition[1])) { throw new static( - \sprintf( + sprintf( '%s() expects first two items of condition at key %d to be callables', $callee, $key diff --git a/src/Functional/FirstIndexOf.php b/src/Functional/FirstIndexOf.php index c341942e..b97b987a 100644 --- a/src/Functional/FirstIndexOf.php +++ b/src/Functional/FirstIndexOf.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_callable; /** * Returns the first index holding specified value in the collection. Returns false if value was not found @@ -25,7 +26,7 @@ function first_index_of($collection, $value) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1); - if (\is_callable($value)) { + if (is_callable($value)) { foreach ($collection as $index => $element) { if ($element === $value($element, $index, $collection)) { return $index; diff --git a/src/Functional/FlatMap.php b/src/Functional/FlatMap.php index 6a022f49..91752088 100644 --- a/src/Functional/FlatMap.php +++ b/src/Functional/FlatMap.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_array; /** * flat_map works applying a function (callback) that returns a sequence for each element in a collection, @@ -38,7 +39,7 @@ function flat_map($collection, callable $callback) foreach ($collection as $index => $element) { $result = $callback($element, $index, $collection); - if (\is_array($result) || $result instanceof Traversable) { + if (is_array($result) || $result instanceof Traversable) { foreach ($result as $item) { $flattened[] = $item; } diff --git a/src/Functional/Flatten.php b/src/Functional/Flatten.php index 615bfb5e..085d6445 100644 --- a/src/Functional/Flatten.php +++ b/src/Functional/Flatten.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_array; /** * Takes a nested combination of collections and returns their contents as a single, flat array. @@ -29,14 +30,14 @@ function flatten($collection) $result = []; while (!empty($stack)) { - $item = \array_shift($stack); + $item = array_shift($stack); - if (\is_array($item) || $item instanceof Traversable) { + if (is_array($item) || $item instanceof Traversable) { foreach ($item as $element) { - \array_unshift($stack, $element); + array_unshift($stack, $element); } } else { - \array_unshift($result, $item); + array_unshift($result, $item); } } diff --git a/src/Functional/Flip.php b/src/Functional/Flip.php index 9beedc8a..631908dd 100644 --- a/src/Functional/Flip.php +++ b/src/Functional/Flip.php @@ -9,6 +9,7 @@ */ namespace Functional; +use function func_get_args; /** * Return a version of the given function where the arguments are provided in reverse order. @@ -22,6 +23,6 @@ function flip(callable $callback) { return function () use ($callback) { - return $callback(...\array_reverse(\func_get_args())); + return $callback(...array_reverse(func_get_args())); }; } diff --git a/src/Functional/GreaterThan.php b/src/Functional/GreaterThan.php index f3c84583..ad9f3383 100644 --- a/src/Functional/GreaterThan.php +++ b/src/Functional/GreaterThan.php @@ -9,12 +9,13 @@ */ namespace Functional; +use Closure; /** * Returns true if $a is strictly greater than $b. * * @param mixed $b - * @return \Closure(mixed) + * @return Closure(mixed) * @no-named-arguments */ function greater_than($b) diff --git a/src/Functional/GreaterThanOrEqual.php b/src/Functional/GreaterThanOrEqual.php index 266fd50f..397f51c7 100644 --- a/src/Functional/GreaterThanOrEqual.php +++ b/src/Functional/GreaterThanOrEqual.php @@ -9,12 +9,13 @@ */ namespace Functional; +use Closure; /** * Returns true if $a is greater than or equal to $b. * * @param mixed $b - * @return \Closure(mixed) + * @return Closure(mixed) * @no-named-arguments */ function greater_than_or_equal($b) diff --git a/src/Functional/IndexesOf.php b/src/Functional/IndexesOf.php index 3045df6b..b197f319 100644 --- a/src/Functional/IndexesOf.php +++ b/src/Functional/IndexesOf.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_callable; /** * Returns a list of array indexes, either matching the predicate or strictly equal to the the passed value. Returns an @@ -28,7 +29,7 @@ function indexes_of($collection, $value) $result = []; - if (\is_callable($value)) { + if (is_callable($value)) { foreach ($collection as $index => $element) { if ($element === $value($element, $index, $collection)) { $result[] = $index; diff --git a/src/Functional/Intersperse.php b/src/Functional/Intersperse.php index 4b325ad2..03fcbb81 100644 --- a/src/Functional/Intersperse.php +++ b/src/Functional/Intersperse.php @@ -33,7 +33,7 @@ function intersperse($collection, $glue) $aggregation[] = $glue; } - \array_pop($aggregation); + array_pop($aggregation); return $aggregation; } diff --git a/src/Functional/Invoke.php b/src/Functional/Invoke.php index 5970ed33..876542df 100644 --- a/src/Functional/Invoke.php +++ b/src/Functional/Invoke.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_callable; /** * Calls the method named by $methodName on each value in the collection. Any extra arguments passed to invoke will be @@ -34,7 +35,7 @@ function invoke($collection, $methodName, array $arguments = []) $value = null; $callback = [$element, $methodName]; - if (\is_callable($callback)) { + if (is_callable($callback)) { $value = $callback(...$arguments); } diff --git a/src/Functional/InvokeFirst.php b/src/Functional/InvokeFirst.php index 8fc8b935..20478b2d 100644 --- a/src/Functional/InvokeFirst.php +++ b/src/Functional/InvokeFirst.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_callable; /** * Calls the method named by $methodName on first object in the collection containing a callable method named @@ -31,7 +32,7 @@ function invoke_first($collection, $methodName, array $arguments = []) foreach ($collection as $element) { $callback = [$element, $methodName]; - if (\is_callable($callback)) { + if (is_callable($callback)) { return $callback(...$arguments); } } diff --git a/src/Functional/InvokeIf.php b/src/Functional/InvokeIf.php index 7f0a4b36..34cfacae 100644 --- a/src/Functional/InvokeIf.php +++ b/src/Functional/InvokeIf.php @@ -9,6 +9,7 @@ */ namespace Functional; +use function is_callable; /** * Calls the method named by $methodName on $object. Any extra arguments passed to invoke_if will be @@ -24,7 +25,7 @@ function invoke_if($object, $methodName, array $methodArguments = [], $defaultValue = null) { $callback = [$object, $methodName]; - if (\is_callable($callback)) { + if (is_callable($callback)) { return $callback(...$methodArguments); } diff --git a/src/Functional/InvokeLast.php b/src/Functional/InvokeLast.php index b63cfbfa..49eda8ac 100644 --- a/src/Functional/InvokeLast.php +++ b/src/Functional/InvokeLast.php @@ -12,6 +12,7 @@ use Traversable; use Functional\Exceptions\InvalidArgumentException; +use function is_callable; /** * Calls the method named by $methodName on last object in the collection containing a callable method named @@ -32,7 +33,7 @@ function invoke_last($collection, $methodName, array $arguments = []) foreach ($collection as $element) { $callback = [$element, $methodName]; - if (\is_callable($callback)) { + if (is_callable($callback)) { $lastCallback = $callback; } } diff --git a/src/Functional/LastIndexOf.php b/src/Functional/LastIndexOf.php index afca8fc5..a05762f7 100644 --- a/src/Functional/LastIndexOf.php +++ b/src/Functional/LastIndexOf.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_callable; /** * Returns the last index holding specified value in the collection. Returns false if value was not found @@ -27,7 +28,7 @@ function last_index_of($collection, $value) $matchingIndex = false; - if (\is_callable($value)) { + if (is_callable($value)) { foreach ($collection as $index => $element) { if ($element === $value($element, $index, $collection)) { $matchingIndex = $index; diff --git a/src/Functional/LessThan.php b/src/Functional/LessThan.php index 062dc865..ff178237 100644 --- a/src/Functional/LessThan.php +++ b/src/Functional/LessThan.php @@ -9,12 +9,13 @@ */ namespace Functional; +use Closure; /** * Returns true if $a is strictly less than $b. * * @param mixed $b - * @return \Closure(mixed) + * @return Closure(mixed) * @no-named-arguments */ function less_than($b) diff --git a/src/Functional/LessThanOrEqual.php b/src/Functional/LessThanOrEqual.php index d63cb50b..d65e992c 100644 --- a/src/Functional/LessThanOrEqual.php +++ b/src/Functional/LessThanOrEqual.php @@ -9,12 +9,13 @@ */ namespace Functional; +use Closure; /** * Returns true if $a is less than or equal to $b. * * @param mixed $b - * @return \Closure(mixed) + * @return Closure(mixed) * @no-named-arguments */ function less_than_or_equal($b) diff --git a/src/Functional/LexicographicCompare.php b/src/Functional/LexicographicCompare.php index c025daea..2a8bd1aa 100644 --- a/src/Functional/LexicographicCompare.php +++ b/src/Functional/LexicographicCompare.php @@ -9,13 +9,14 @@ */ namespace Functional; +use Closure; /** * Returns an integer less than, equal to, or greater than zero when * $a is respectively less than, equal to, or greater than $b. * * @param mixed $b - * @return \Closure(mixed) + * @return Closure(mixed) * @no-named-arguments */ function lexicographic_compare($b) diff --git a/src/Functional/Maximum.php b/src/Functional/Maximum.php index 8d8d5fb2..b2173054 100644 --- a/src/Functional/Maximum.php +++ b/src/Functional/Maximum.php @@ -27,7 +27,7 @@ function maximum($collection) $max = null; foreach ($collection as $element) { - if (!\is_numeric($element)) { + if (!is_numeric($element)) { continue; } diff --git a/src/Functional/Memoize.php b/src/Functional/Memoize.php index 3813e3ce..e66df8a1 100644 --- a/src/Functional/Memoize.php +++ b/src/Functional/Memoize.php @@ -11,6 +11,8 @@ namespace Functional; use const E_USER_DEPRECATED; +use function array_key_exists; +use function is_callable; /** * Memoizes callbacks and returns their value instead of calling them @@ -30,21 +32,21 @@ function memoize(callable $callback = null, $arguments = [], $key = null) return null; } - if (\is_callable($key)) { - \trigger_error('Passing a callable as key is deprecated and will be removed in 2.0', E_USER_DEPRECATED); + if (is_callable($key)) { + trigger_error('Passing a callable as key is deprecated and will be removed in 2.0', E_USER_DEPRECATED); $key = $key(); - } elseif (\is_callable($arguments)) { - \trigger_error('Passing a callable as key is deprecated and will be removed in 2.0', E_USER_DEPRECATED); + } elseif (is_callable($arguments)) { + trigger_error('Passing a callable as key is deprecated and will be removed in 2.0', E_USER_DEPRECATED); $key = $arguments(); } if ($key === null) { - $key = value_to_key(\array_merge([$callback], $arguments)); + $key = value_to_key(array_merge([$callback], $arguments)); } else { $key = value_to_key($key); } - if (!isset($storage[$key]) && !\array_key_exists($key, $storage)) { + if (!isset($storage[$key]) && !array_key_exists($key, $storage)) { $storage[$key] = $callback(...$arguments); } diff --git a/src/Functional/Minimum.php b/src/Functional/Minimum.php index 053b0beb..37a28860 100644 --- a/src/Functional/Minimum.php +++ b/src/Functional/Minimum.php @@ -27,7 +27,7 @@ function minimum($collection) $min = null; foreach ($collection as $index => $element) { - if (!\is_numeric($element)) { + if (!is_numeric($element)) { continue; } diff --git a/src/Functional/OmitKeys.php b/src/Functional/OmitKeys.php index c08a69b4..5cffca7d 100644 --- a/src/Functional/OmitKeys.php +++ b/src/Functional/OmitKeys.php @@ -26,10 +26,10 @@ function omit_keys($collection, array $keys) InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1); if ($collection instanceof Traversable) { - $array = \iterator_to_array($collection); + $array = iterator_to_array($collection); } else { $array = $collection; } - return \array_diff_key($array, \array_flip($keys)); + return array_diff_key($array, array_flip($keys)); } diff --git a/src/Functional/PartialAny.php b/src/Functional/PartialAny.php index 71a481dc..6a7f14e1 100644 --- a/src/Functional/PartialAny.php +++ b/src/Functional/PartialAny.php @@ -11,6 +11,7 @@ namespace Functional; use Functional\Exceptions\InvalidArgumentException; +use function define; /** * Return a new function with the arguments partially applied @@ -30,7 +31,7 @@ function partial_any(callable $callback, ...$arguments) foreach ($arguments as $position => &$argument) { if ($argument === $placeholder) { InvalidArgumentException::assertResolvablePlaceholder($innerArguments, $position); - $argument = \array_shift($innerArguments); + $argument = array_shift($innerArguments); } } @@ -47,7 +48,7 @@ function …() static $placeholder; if (!$placeholder) { - $placeholder = \random_bytes(32); + $placeholder = random_bytes(32); } return $placeholder; @@ -65,5 +66,5 @@ function placeholder() // phpcs:disable /** Define unicode ellipsis constant */ -\define('Functional\\…', …()); +define('Functional\\…', …()); // phpcs:enable diff --git a/src/Functional/PartialLeft.php b/src/Functional/PartialLeft.php index e4ae016c..29c36e96 100644 --- a/src/Functional/PartialLeft.php +++ b/src/Functional/PartialLeft.php @@ -23,6 +23,6 @@ function partial_left(callable $callback, ...$arguments) { return function (...$innerArguments) use ($callback, $arguments) { - return $callback(...\array_merge($arguments, $innerArguments)); + return $callback(...array_merge($arguments, $innerArguments)); }; } diff --git a/src/Functional/PartialMethod.php b/src/Functional/PartialMethod.php index ac1f7239..b42aea76 100644 --- a/src/Functional/PartialMethod.php +++ b/src/Functional/PartialMethod.php @@ -11,6 +11,7 @@ namespace Functional; use Functional\Exceptions\InvalidArgumentException; +use function is_callable; /** * Returns a function that expects an object as the first param and tries to invoke the given method on it @@ -26,7 +27,7 @@ function partial_method($methodName, array $arguments = [], $defaultValue = null InvalidArgumentException::assertMethodName($methodName, __FUNCTION__, 1); return function ($object) use ($methodName, $arguments, $defaultValue) { - if (!\is_callable([$object, $methodName])) { + if (!is_callable([$object, $methodName])) { return $defaultValue; } return $object->{$methodName}(...$arguments); diff --git a/src/Functional/PartialRight.php b/src/Functional/PartialRight.php index 601e990b..752b5fcb 100644 --- a/src/Functional/PartialRight.php +++ b/src/Functional/PartialRight.php @@ -21,6 +21,6 @@ function partial_right(callable $callback, ...$arguments) { return function (...$innerArguments) use ($callback, $arguments) { - return $callback(...\array_merge($innerArguments, $arguments)); + return $callback(...array_merge($innerArguments, $arguments)); }; } diff --git a/src/Functional/Partition.php b/src/Functional/Partition.php index 11fb36b9..0e05611d 100644 --- a/src/Functional/Partition.php +++ b/src/Functional/Partition.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function count; /** * Partitions a collection by callback predicate results. Returns an @@ -32,7 +33,7 @@ function partition($collection, callable ...$callbacks) InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1); $partition = 0; - $partitions = \array_fill(0, \count($callbacks) + 1, []); + $partitions = array_fill(0, count($callbacks) + 1, []); foreach ($collection as $index => $element) { foreach ($callbacks as $partition => $callback) { diff --git a/src/Functional/Pick.php b/src/Functional/Pick.php index b4be3c13..875dee94 100644 --- a/src/Functional/Pick.php +++ b/src/Functional/Pick.php @@ -12,6 +12,8 @@ use ArrayAccess; use Functional\Exceptions\InvalidArgumentException; +use function array_key_exists; +use function is_array; /** * Pick a single element from a collection of objects or arrays by index. @@ -29,7 +31,7 @@ function pick($collection, $index, $default = null, callable $callback = null) InvalidArgumentException::assertArrayAccess($collection, __FUNCTION__, 1); if ($callback === null) { - if (!isset($collection[$index]) && (!\is_array($collection) || !\array_key_exists($index, $collection))) { + if (!isset($collection[$index]) && (!is_array($collection) || !array_key_exists($index, $collection))) { return $default; } } else { diff --git a/src/Functional/Pluck.php b/src/Functional/Pluck.php index dd8f6c24..31c5962b 100644 --- a/src/Functional/Pluck.php +++ b/src/Functional/Pluck.php @@ -13,6 +13,8 @@ use ArrayAccess; use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_array; +use function is_object; /** * Extract a property from a collection of objects. @@ -32,9 +34,9 @@ function pluck($collection, $propertyName) foreach ($collection as $index => $element) { $value = null; - if (\is_object($element) && isset($element->{$propertyName})) { + if (is_object($element) && isset($element->{$propertyName})) { $value = $element->{$propertyName}; - } elseif ((\is_array($element) || $element instanceof ArrayAccess) && isset($element[$propertyName])) { + } elseif ((is_array($element) || $element instanceof ArrayAccess) && isset($element[$propertyName])) { $value = $element[$propertyName]; } diff --git a/src/Functional/Poll.php b/src/Functional/Poll.php index 7c632d77..1cb05a60 100644 --- a/src/Functional/Poll.php +++ b/src/Functional/Poll.php @@ -38,7 +38,7 @@ function poll(callable $callback, $timeout, Traversable $delaySequence = null) } $delays->append(new InfiniteIterator(new ArrayIterator([0]))); - $limit = \microtime(true) + ($timeout / 100000); + $limit = microtime(true) + ($timeout / 100000); foreach ($delays as $delay) { $value = $callback($retry, $delay); @@ -47,12 +47,12 @@ function poll(callable $callback, $timeout, Traversable $delaySequence = null) return $value; } - if (\microtime(true) > $limit) { + if (microtime(true) > $limit) { return false; } if ($delay > 0) { - \usleep($delay); + usleep($delay); } ++$retry; diff --git a/src/Functional/Product.php b/src/Functional/Product.php index 6421b68a..a4a09b03 100644 --- a/src/Functional/Product.php +++ b/src/Functional/Product.php @@ -27,7 +27,7 @@ function product($collection, $initial = 1) $result = $initial; foreach ($collection as $value) { - if (\is_numeric($value)) { + if (is_numeric($value)) { $result *= $value; } } diff --git a/src/Functional/Ratio.php b/src/Functional/Ratio.php index b9ee83e4..e02d5367 100644 --- a/src/Functional/Ratio.php +++ b/src/Functional/Ratio.php @@ -27,7 +27,7 @@ function ratio($collection, $initial = 1) $result = $initial; foreach ($collection as $value) { - if (\is_numeric($value)) { + if (is_numeric($value)) { $result /= $value; } } diff --git a/src/Functional/ReduceRight.php b/src/Functional/ReduceRight.php index 094d570d..1e6ae6b0 100644 --- a/src/Functional/ReduceRight.php +++ b/src/Functional/ReduceRight.php @@ -29,7 +29,7 @@ function reduce_right($collection, callable $callback, $initial = null) $data[] = [$index, $value]; } - while ((list($index, $value) = \array_pop($data))) { + while ((list($index, $value) = array_pop($data))) { $initial = $callback($value, $index, $collection, $initial); } diff --git a/src/Functional/Retry.php b/src/Functional/Retry.php index 40ef0fa7..1f8bfad0 100644 --- a/src/Functional/Retry.php +++ b/src/Functional/Retry.php @@ -39,7 +39,7 @@ function retry(callable $callback, $retries, Traversable $delaySequence = null) $delays->append(new InfiniteIterator(new ArrayIterator([0]))); $delays = new LimitIterator($delays, 0, $retries); } else { - $delays = \array_fill_keys(\range(0, $retries), 0); + $delays = array_fill_keys(range(0, $retries), 0); } $retry = 0; @@ -53,7 +53,7 @@ function retry(callable $callback, $retries, Traversable $delaySequence = null) } if ($delay > 0) { - \usleep($delay); + usleep($delay); } ++$retry; diff --git a/src/Functional/SelectKeys.php b/src/Functional/SelectKeys.php index b222631d..c3e6108e 100644 --- a/src/Functional/SelectKeys.php +++ b/src/Functional/SelectKeys.php @@ -26,10 +26,10 @@ function select_keys($collection, array $keys) InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1); if ($collection instanceof Traversable) { - $array = \iterator_to_array($collection); + $array = iterator_to_array($collection); } else { $array = $collection; } - return \array_intersect_key($array, \array_flip($keys)); + return array_intersect_key($array, array_flip($keys)); } diff --git a/src/Functional/Sequences/ExponentialSequence.php b/src/Functional/Sequences/ExponentialSequence.php index 0a8b8d47..2feac7aa 100644 --- a/src/Functional/Sequences/ExponentialSequence.php +++ b/src/Functional/Sequences/ExponentialSequence.php @@ -45,7 +45,7 @@ public function current() public function next() { - $this->value = (int) \round(\pow($this->start * (1 + $this->percentage / 100), $this->times)); + $this->value = (int) round(pow($this->start * (1 + $this->percentage / 100), $this->times)); $this->times++; } diff --git a/src/Functional/Sort.php b/src/Functional/Sort.php index 8dcc32ea..bb22da14 100644 --- a/src/Functional/Sort.php +++ b/src/Functional/Sort.php @@ -28,7 +28,7 @@ function sort($collection, callable $callback, $preserveKeys = false) InvalidArgumentException::assertBoolean($preserveKeys, __FUNCTION__, 3); if ($collection instanceof Traversable) { - $array = \iterator_to_array($collection); + $array = iterator_to_array($collection); } else { $array = $collection; } diff --git a/src/Functional/Sum.php b/src/Functional/Sum.php index e0f478b9..a0ae1864 100644 --- a/src/Functional/Sum.php +++ b/src/Functional/Sum.php @@ -27,7 +27,7 @@ function sum($collection, $initial = 0) $result = $initial; foreach ($collection as $value) { - if (\is_numeric($value)) { + if (is_numeric($value)) { $result += $value; } } diff --git a/src/Functional/SuppressError.php b/src/Functional/SuppressError.php index 49baed2f..95f8245d 100644 --- a/src/Functional/SuppressError.php +++ b/src/Functional/SuppressError.php @@ -26,11 +26,11 @@ function suppress_error(callable $callback) { return function (...$arguments) use ($callback) { try { - \set_error_handler(const_function(null)); + set_error_handler(const_function(null)); return $callback(...$arguments); } finally { - \restore_error_handler(); + restore_error_handler(); } }; } diff --git a/src/Functional/TailRecursion.php b/src/Functional/TailRecursion.php index 2fd548a0..b26fce73 100644 --- a/src/Functional/TailRecursion.php +++ b/src/Functional/TailRecursion.php @@ -29,7 +29,7 @@ function tail_recursion(callable $fn): callable $queue[] = $args; if (!$underCall) { $underCall = true; - while ($head = \array_shift($queue)) { + while ($head = array_shift($queue)) { $result = $fn(...$head); } $underCall = false; diff --git a/src/Functional/TakeLeft.php b/src/Functional/TakeLeft.php index 2520877e..88910c50 100644 --- a/src/Functional/TakeLeft.php +++ b/src/Functional/TakeLeft.php @@ -12,6 +12,8 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function array_slice; +use function is_array; /** * Creates a slice of $collection with $count elements taken from the beginning. If the collection has less than $count @@ -28,8 +30,8 @@ function take_left($collection, $count) InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1); InvalidArgumentException::assertPositiveInteger($count, __FUNCTION__, 2); - return \array_slice( - \is_array($collection) ? $collection : \iterator_to_array($collection), + return array_slice( + is_array($collection) ? $collection : iterator_to_array($collection), 0, $count ); diff --git a/src/Functional/TakeRight.php b/src/Functional/TakeRight.php index c7af137b..fc5bd806 100644 --- a/src/Functional/TakeRight.php +++ b/src/Functional/TakeRight.php @@ -12,6 +12,8 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function array_slice; +use function is_array; /** * Creates a slice of $collection with $count elements taken from the end. If the collection has less than $count @@ -31,8 +33,8 @@ function take_right($collection, $count, $preserveKeys = false) InvalidArgumentException::assertCollection($collection, __FUNCTION__, 1); InvalidArgumentException::assertPositiveInteger($count, __FUNCTION__, 2); - return \array_slice( - \is_array($collection) ? $collection : \iterator_to_array($collection), + return array_slice( + is_array($collection) ? $collection : iterator_to_array($collection), 0 - $count, $count, $preserveKeys diff --git a/src/Functional/Unique.php b/src/Functional/Unique.php index 656ac2be..802574cc 100644 --- a/src/Functional/Unique.php +++ b/src/Functional/Unique.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function in_array; /** * Returns an array of unique elements @@ -35,7 +36,7 @@ function unique($collection, callable $callback = null, $strict = true) $index = $element; } - if (!\in_array($index, $indexes, $strict)) { + if (!in_array($index, $indexes, $strict)) { $aggregation[$key] = $element; $indexes[] = $index; diff --git a/src/Functional/ValueToKey.php b/src/Functional/ValueToKey.php index 267a2e72..94371102 100644 --- a/src/Functional/ValueToKey.php +++ b/src/Functional/ValueToKey.php @@ -13,6 +13,8 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; use WeakReference; +use function get_class; +use function gettype; /** * @no-named-arguments @@ -25,7 +27,7 @@ function value_to_key(...$any) static $objectToRef = null; if (!$objectToRef) { $objectToRef = static function ($value) use (&$objectReferences) { - $hash = \spl_object_hash($value); + $hash = spl_object_hash($value); /** * spl_object_hash() will return the same hash twice in a single request if an object goes out of scope * and is destructed. @@ -42,7 +44,7 @@ function value_to_key(...$any) $objectReferences[$hash] = WeakReference::create($value); } - $key = \get_class($value) . ':' . $hash . ':' . ($collisions[$hash] ?? 0); + $key = get_class($value) . ':' . $hash . ':' . ($collisions[$hash] ?? 0); return $key; }; @@ -51,11 +53,11 @@ function value_to_key(...$any) static $valueToRef = null; if (!$valueToRef) { $valueToRef = static function ($value, $key = null) use (&$valueToRef, $objectToRef) { - $type = \gettype($value); + $type = gettype($value); if ($type === 'array') { - $ref = '[' . \implode(':', map($value, $valueToRef)) . ']'; + $ref = '[' . implode(':', map($value, $valueToRef)) . ']'; } elseif ($value instanceof Traversable) { - $ref = $objectToRef($value) . '[' . \implode(':', map($value, $valueToRef)) . ']'; + $ref = $objectToRef($value) . '[' . implode(':', map($value, $valueToRef)) . ']'; } elseif ($type === 'object') { $ref = $objectToRef($value); } elseif ($type === 'resource') { @@ -63,7 +65,7 @@ function value_to_key(...$any) 'Resource type cannot be used as part of a memoization key. Please pass a custom key instead' ); } else { - $ref = \serialize($value); + $ref = serialize($value); } return ($key !== null ? ($valueToRef($key) . '~') : '') . $ref; diff --git a/src/Functional/With.php b/src/Functional/With.php index 9e4532e5..fadaf34d 100644 --- a/src/Functional/With.php +++ b/src/Functional/With.php @@ -11,6 +11,7 @@ namespace Functional; use Functional\Exceptions\InvalidArgumentException; +use function is_callable; /** * Invoke a callback on a value if the value is not null @@ -30,8 +31,8 @@ function with($value, callable $callback, $invokeValue = true, $default = null) return $default; } - if ($invokeValue && \is_callable($value)) { - \trigger_error('Invoking the value is deprecated and will be removed in 2.0', E_USER_DEPRECATED); + if ($invokeValue && is_callable($value)) { + trigger_error('Invoking the value is deprecated and will be removed in 2.0', E_USER_DEPRECATED); $value = $value(); } diff --git a/src/Functional/Zip.php b/src/Functional/Zip.php index 23abf2e0..ed2a1f46 100644 --- a/src/Functional/Zip.php +++ b/src/Functional/Zip.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_callable; /** * Recombines arrays by index and applies a callback optionally @@ -23,8 +24,8 @@ function zip(...$args) { $callback = null; - if (\is_callable(\end($args))) { - $callback = \array_pop($args); + if (is_callable(end($args))) { + $callback = array_pop($args); } foreach ($args as $position => $arg) { @@ -32,7 +33,7 @@ function zip(...$args) } $result = []; - foreach ((array) \reset($args) as $index => $value) { + foreach ((array) reset($args) as $index => $value) { $zipped = []; foreach ($args as $arg) { diff --git a/src/Functional/ZipAll.php b/src/Functional/ZipAll.php index d8c95e20..01260e94 100644 --- a/src/Functional/ZipAll.php +++ b/src/Functional/ZipAll.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_callable; /** * Recombines arrays by index (column) and applies a callback optionally @@ -27,8 +28,8 @@ function zip_all(...$args) { /** @var callable|null $callback */ $callback = null; - if (\is_callable(\end($args))) { - $callback = \array_pop($args); + if (is_callable(end($args))) { + $callback = array_pop($args); } foreach ($args as $position => $arg) { @@ -42,7 +43,7 @@ function zip_all(...$args) } } - $resultKeys = \array_unique($resultKeys); + $resultKeys = array_unique($resultKeys); $result = []; diff --git a/tests/Functional/AbstractTestCase.php b/tests/Functional/AbstractTestCase.php index 4f4e1ed5..50e6e2ef 100644 --- a/tests/Functional/AbstractTestCase.php +++ b/tests/Functional/AbstractTestCase.php @@ -17,6 +17,9 @@ use PHPUnit\Framework\TestCase; use Traversable; use TypeError; +use function count; +use function func_get_args; +use function func_num_args; class AbstractTestCase extends TestCase { @@ -43,9 +46,9 @@ protected function expectCallableArgumentError(string $fn, int $position, string $this->expectException(TypeError::class); $this->expectExceptionMessageMatches( - \sprintf( + sprintf( '/^%s\(\): Argument \#%d( \(\$callback\))? must be of type \??callable, %s given.*/', - \preg_quote($fn, '/'), + preg_quote($fn, '/'), $position, $actualType ) @@ -54,13 +57,13 @@ protected function expectCallableArgumentError(string $fn, int $position, string public function exception(): void { - if (\func_num_args() < 3) { + if (func_num_args() < 3) { throw new DomainException('Callback exception'); } - $args = \func_get_args(); - self::assertGreaterThanOrEqual(3, \count($args)); - throw new DomainException(\sprintf('Callback exception: %s', $args[1])); + $args = func_get_args(); + self::assertGreaterThanOrEqual(3, count($args)); + throw new DomainException(sprintf('Callback exception: %s', $args[1])); } protected function sequenceToArray(Iterator $sequence, int $limit): array @@ -77,7 +80,7 @@ protected function sequenceToArray(Iterator $sequence, int $limit): array public function expectDeprecation(): void { - if (\method_exists(parent::class, __FUNCTION__)) { + if (method_exists(parent::class, __FUNCTION__)) { parent::expectDeprecation(); return; } @@ -87,7 +90,7 @@ public function expectDeprecation(): void public function expectDeprecationMessage(string $message): void { - if (\method_exists(parent::class, __FUNCTION__)) { + if (method_exists(parent::class, __FUNCTION__)) { parent::expectDeprecationMessage($message); return; } diff --git a/tests/Functional/AnnotationsTest.php b/tests/Functional/AnnotationsTest.php index 58deb4f3..a2884296 100644 --- a/tests/Functional/AnnotationsTest.php +++ b/tests/Functional/AnnotationsTest.php @@ -19,11 +19,11 @@ class AnnotationsTest extends AbstractTestCase public static function getFunctions(): array { return group( - \array_values( - \array_filter( - \get_defined_functions()['user'], + array_values( + array_filter( + get_defined_functions()['user'], static function (string $function): bool { - return \stripos($function, 'Functional\\') === 0; + return stripos($function, 'Functional\\') === 0; } ) ), @@ -38,7 +38,7 @@ public function testNamedArgumentsNotSupportedInFunctions(string $function): voi self::assertStringContainsString( '@no-named-arguments', $refl->getDocComment(), - \sprintf( + sprintf( 'Expected function "%s()" to have annotation @no-named-arguments', $function ) diff --git a/tests/Functional/AverageTest.php b/tests/Functional/AverageTest.php index 4a1c9b64..24b417ff 100644 --- a/tests/Functional/AverageTest.php +++ b/tests/Functional/AverageTest.php @@ -47,17 +47,17 @@ public function createTestData(): void { $this->hash = ['f0' => 12, 'f1' => 2, 'f3' => true, 'f4' => false, 'f5' => 'str', 'f6' => [], 'f7' => new stdClass(), 'f8' => 1]; $this->hashIterator = new ArrayIterator($this->hash); - $this->list = \array_values($this->hash); + $this->list = array_values($this->hash); $this->listIterator = new ArrayIterator($this->list); $this->hash2 = ['f0' => 1.0, 'f1' => 0.5, 'f3' => true, 'f4' => false, 'f5' => 1]; $this->hashIterator2 = new ArrayIterator($this->hash2); - $this->list2 = \array_values($this->hash2); + $this->list2 = array_values($this->hash2); $this->listIterator2 = new ArrayIterator($this->list2); $this->hash3 = ['f0' => [], 'f1' => new stdClass(), 'f2' => null, 'f3' => 'foo']; $this->hashIterator3 = new ArrayIterator($this->hash3); - $this->list3 = \array_values($this->hash3); + $this->list3 = array_values($this->hash3); $this->listIterator3 = new ArrayIterator($this->list3); } diff --git a/tests/Functional/ComposeTest.php b/tests/Functional/ComposeTest.php index c6335bec..95bb7d92 100644 --- a/tests/Functional/ComposeTest.php +++ b/tests/Functional/ComposeTest.php @@ -16,7 +16,7 @@ class ComposeTest extends AbstractTestCase { public function test(): void { - $input = \range(0, 10); + $input = range(0, 10); $plus2 = static function ($x) { return $x + 2; @@ -30,14 +30,14 @@ public function test(): void $composed = compose($plus2, $times4, $square); - $composed_values = \array_map( + $composed_values = array_map( static function ($x) use ($composed) { return $composed($x); }, $input ); - $manual_values = \array_map( + $manual_values = array_map( static function ($x) use ($plus2, $times4, $square) { return $square($times4($plus2($x))); }, @@ -49,11 +49,11 @@ static function ($x) use ($plus2, $times4, $square) { public function testPassNoFunctions(): void { - $input = \range(0, 10); + $input = range(0, 10); $composed = compose(); - $composed_values = \array_map( + $composed_values = array_map( static function ($x) use ($composed) { return $composed($x); }, diff --git a/tests/Functional/CurryNTest.php b/tests/Functional/CurryNTest.php index 336bd81e..d19b8dca 100644 --- a/tests/Functional/CurryNTest.php +++ b/tests/Functional/CurryNTest.php @@ -14,6 +14,9 @@ use function Functional\curry_n; use function Functional\invoker; +use function call_user_func_array; +use function count; +use function is_null; function add($a, $b, $c, $d) { @@ -42,7 +45,7 @@ class CurryNTest extends AbstractPartialTestCase { protected function getCurryiedCallable(callable $callback, array $params, bool $required): callable { - return curry_n(\count($params), $callback); + return curry_n(count($params), $callback); } /** @@ -50,23 +53,23 @@ protected function getCurryiedCallable(callable $callback, array $params, bool $ */ public function testCallbackTypes($callback, $params, $expected, $required, $transformer = null): void { - if (\is_null($transformer)) { + if (is_null($transformer)) { $transformer = 'Functional\id'; } $curryied = $this->getCurryiedCallable($callback, $params, $required); - self::assertEquals($transformer($expected), $transformer(\call_user_func_array($curryied, $params))); + self::assertEquals($transformer($expected), $transformer(call_user_func_array($curryied, $params))); - $length = \count($params); + $length = count($params); for ($i = 0; $i < $length; ++$i) { - $p = \array_shift($params); + $p = array_shift($params); $curryied = $curryied($p); - if (\count($params) > 0) { + if (count($params) > 0) { self::assertIsCallable($curryied); - self::assertEquals($transformer($expected), $transformer(\call_user_func_array($curryied, $params))); + self::assertEquals($transformer($expected), $transformer(call_user_func_array($curryied, $params))); } else { self::assertEquals($transformer($expected), $transformer($curryied)); } diff --git a/tests/Functional/DropTest.php b/tests/Functional/DropTest.php index bff99985..dcb111ea 100644 --- a/tests/Functional/DropTest.php +++ b/tests/Functional/DropTest.php @@ -15,6 +15,7 @@ use function Functional\drop_last; use function Functional\drop_first; +use function is_int; class DropTest extends AbstractTestCase { @@ -31,7 +32,7 @@ public function test(): void { $fn = function ($v, $k, $collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - $return = \is_int($k) ? ($k != 2) : ($v[3] != 3); + $return = is_int($k) ? ($k != 2) : ($v[3] != 3); return $return; }; self::assertSame([0 => 'value1', 1 => 'value2'], drop_last($this->list, $fn)); diff --git a/tests/Functional/EntriesFromEntriesTest.php b/tests/Functional/EntriesFromEntriesTest.php index 8a238b68..f6a0d346 100644 --- a/tests/Functional/EntriesFromEntriesTest.php +++ b/tests/Functional/EntriesFromEntriesTest.php @@ -15,6 +15,7 @@ use function Functional\entries; use function Functional\from_entries; +use function count; class EntriesFromEntriesTest extends AbstractTestCase { @@ -31,35 +32,35 @@ protected function setUp(): void public function testArray(): void { $res = entries($this->list); - self::assertSame(\array_keys($res), \range(0, \count($this->list) - 1)); + self::assertSame(array_keys($res), range(0, count($this->list) - 1)); self::assertSame(from_entries($res), $this->list); } public function testIterator(): void { $res = entries($this->listIterator); - self::assertSame(\array_keys($res), \range(0, \count($this->listIterator) - 1)); + self::assertSame(array_keys($res), range(0, count($this->listIterator) - 1)); self::assertSame(from_entries($res), $this->listIterator->getArrayCopy()); } public function testHash(): void { $res = entries($this->hash); - self::assertSame(\array_keys($res), \range(0, \count($this->hash) - 1)); + self::assertSame(array_keys($res), range(0, count($this->hash) - 1)); self::assertSame(from_entries($res), $this->hash); } public function testHashIterator(): void { $res = entries($this->hashIterator); - self::assertSame(\array_keys($res), \range(0, \count($this->hashIterator) - 1)); + self::assertSame(array_keys($res), range(0, count($this->hashIterator) - 1)); self::assertSame(from_entries($res), $this->hashIterator->getArrayCopy()); } public function testHashWithStart(): void { $res = entries($this->hash, 42); - self::assertSame(\array_keys($res), \range(42, 42 + \count($this->hash) - 1)); + self::assertSame(array_keys($res), range(42, 42 + count($this->hash) - 1)); self::assertSame(from_entries($res), $this->hash); } diff --git a/tests/Functional/ErrorToExceptionTest.php b/tests/Functional/ErrorToExceptionTest.php index e68893e0..a0b5bb31 100644 --- a/tests/Functional/ErrorToExceptionTest.php +++ b/tests/Functional/ErrorToExceptionTest.php @@ -22,7 +22,7 @@ class ErrorToExceptionTest extends AbstractTestCase public function testErrorIsThrownAsException(): void { $origFn = function () { - \trigger_error('Some error', E_USER_ERROR); + trigger_error('Some error', E_USER_ERROR); }; $fn = error_to_exception($origFn); @@ -57,14 +57,14 @@ function () use ($expectedException) { public function testErrorHandlerNestingWorks(): void { $errorMessage = null; - \set_error_handler( + set_error_handler( static function ($level, $message) use (&$errorMessage) { $errorMessage = $message; } ); $origFn = static function () { - \trigger_error('Some error', E_USER_ERROR); + trigger_error('Some error', E_USER_ERROR); }; $fn = error_to_exception($origFn); @@ -77,6 +77,6 @@ static function ($level, $message) use (&$errorMessage) { $origFn(); self::assertSame('Some error', $errorMessage); - \restore_error_handler(); + restore_error_handler(); } } diff --git a/tests/Functional/EveryTest.php b/tests/Functional/EveryTest.php index 5bba8c28..69e333d5 100644 --- a/tests/Functional/EveryTest.php +++ b/tests/Functional/EveryTest.php @@ -85,6 +85,6 @@ public function functionalCallback($value, $key, $collection): bool { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return $value == 'value' && \is_numeric($key); + return $value == 'value' && is_numeric($key); } } diff --git a/tests/Functional/Exceptions/InvalidArgumentExceptionTest.php b/tests/Functional/Exceptions/InvalidArgumentExceptionTest.php index dfa3c77a..2bc93182 100644 --- a/tests/Functional/Exceptions/InvalidArgumentExceptionTest.php +++ b/tests/Functional/Exceptions/InvalidArgumentExceptionTest.php @@ -12,6 +12,8 @@ use Functional\Exceptions\InvalidArgumentException; use PHPUnit\Framework\TestCase; +use ArrayObject; +use stdClass; class InvalidArgumentExceptionTest extends TestCase { @@ -36,7 +38,7 @@ public function testCallbackExceptionWithUndefinedMethod(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("func() expects parameter 2 to be a valid callback, method 'stdClass->method' not found or invalid method name"); - InvalidArgumentException::assertCallback([new \stdClass(), 'method'], 'func', 2); + InvalidArgumentException::assertCallback([new stdClass(), 'method'], 'func', 2); } public function testCallbackExceptionWithIncorrectArrayIndex(): void @@ -44,7 +46,7 @@ public function testCallbackExceptionWithIncorrectArrayIndex(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("func() expects parameter 1 to be a valid callback, method 'stdClass->method' not found or invalid method name"); - InvalidArgumentException::assertCallback([1 => new \stdClass(), 2 => 'method'], 'func', 1); + InvalidArgumentException::assertCallback([1 => new stdClass(), 2 => 'method'], 'func', 1); } public function testCallbackExceptionWithObject(): void @@ -52,7 +54,7 @@ public function testCallbackExceptionWithObject(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('func() expected parameter 1 to be a valid callback, no array, string, closure or functor given'); - InvalidArgumentException::assertCallback(new \stdClass(), 'func', 1); + InvalidArgumentException::assertCallback(new stdClass(), 'func', 1); } public function testExceptionIfStringIsPassedAsList(): void @@ -68,12 +70,12 @@ public function testExceptionIfObjectIsPassedAsList(): void $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage("func() expects parameter 2 to be array or instance of Traversable, stdClass given"); - InvalidArgumentException::assertCollection(new \stdClass(), 'func', 2); + InvalidArgumentException::assertCollection(new stdClass(), 'func', 2); } public function testAssertArrayAccessValidCase(): void { - $validObject = new \ArrayObject(); + $validObject = new ArrayObject(); InvalidArgumentException::assertArrayAccess($validObject, "func", 4); $this->addToAssertionCount(1); @@ -90,14 +92,14 @@ public function testAssertArrayAccessWithStandardClass(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('func() expects parameter 2 to be array or instance of ArrayAccess, stdClass given'); - InvalidArgumentException::assertArrayAccess(new \stdClass(), "func", 2); + InvalidArgumentException::assertArrayAccess(new stdClass(), "func", 2); } public function testExceptionIfInvalidMethodName(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('foo() expects parameter 2 to be string, stdClass given'); - InvalidArgumentException::assertMethodName(new \stdClass(), "foo", 2); + InvalidArgumentException::assertMethodName(new stdClass(), "foo", 2); } public function testExceptionIfInvalidPropertyName(): void @@ -107,7 +109,7 @@ public function testExceptionIfInvalidPropertyName(): void InvalidArgumentException::assertPropertyName(0.2, 'func', 2); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('func() expects parameter 2 to be a valid property name or array index, stdClass given'); - InvalidArgumentException::assertPropertyName(new \stdClass(), "func", 2); + InvalidArgumentException::assertPropertyName(new stdClass(), "func", 2); } public function testNoExceptionThrownWithPositiveInteger(): void @@ -142,7 +144,7 @@ public function testAssertIntegerAccessWithObject(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('func() expects parameter 4 to be integer, stdClass given'); - InvalidArgumentException::assertInteger(new \stdClass(), "func", 4); + InvalidArgumentException::assertInteger(new stdClass(), "func", 4); } public function testAssertBooleanAccessWithString(): void @@ -156,7 +158,7 @@ public function testAssertBooleanAccessWithObject(): void { $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('func() expects parameter 4 to be boolean, stdClass given'); - InvalidArgumentException::assertBoolean(new \stdClass(), "func", 4); + InvalidArgumentException::assertBoolean(new stdClass(), "func", 4); } public function testAssertPairWithPair(): void @@ -165,7 +167,7 @@ public function testAssertPairWithPair(): void InvalidArgumentException::assertPair([1, 2], "func", 1); InvalidArgumentException::assertPair(['1', 2], "func", 1); InvalidArgumentException::assertPair([1, '2'], "func", 1); - InvalidArgumentException::assertPair([new \stdClass(), '2'], "func", 1); + InvalidArgumentException::assertPair([new stdClass(), '2'], "func", 1); } public function testAssertPairWithEmptyArray(): void diff --git a/tests/Functional/FirstTest.php b/tests/Functional/FirstTest.php index c8f64f23..927e32f6 100644 --- a/tests/Functional/FirstTest.php +++ b/tests/Functional/FirstTest.php @@ -104,7 +104,7 @@ public function testExceptionIsThrownInCollection($functionName): void */ public function testPassNoCollection($functionName): void { - $this->expectArgumentError(\sprintf('%s() expects parameter 1 to be array or instance of Traversable', $functionName)); + $this->expectArgumentError(sprintf('%s() expects parameter 1 to be array or instance of Traversable', $functionName)); $functionName('invalidCollection', 'strlen'); } } diff --git a/tests/Functional/FlattenTest.php b/tests/Functional/FlattenTest.php index f0643da8..e28f61ea 100644 --- a/tests/Functional/FlattenTest.php +++ b/tests/Functional/FlattenTest.php @@ -39,8 +39,8 @@ protected function setUp(): void public function test(): void { - self::assertSame(\range(1, 15), flatten($this->goodArray)); - self::assertSame(\range(1, 15), flatten($this->goodIterator)); + self::assertSame(range(1, 15), flatten($this->goodArray)); + self::assertSame(range(1, 15), flatten($this->goodIterator)); self::assertSame([1, "2", "3", 5], flatten($this->goodArray2)); self::assertEquals([new stdClass()], flatten([[new stdClass()]])); self::assertSame([null, null], flatten([[null], null])); diff --git a/tests/Functional/FlipTest.php b/tests/Functional/FlipTest.php index dcbaf38a..70719eb1 100644 --- a/tests/Functional/FlipTest.php +++ b/tests/Functional/FlipTest.php @@ -49,7 +49,7 @@ public function testFlippedId(): void function merge_strings(string $head, string $tail, ...$other): string { - return $head . $tail . \implode('', $other); + return $head . $tail . implode('', $other); } function subtract(int $first, int $second, int $third): int diff --git a/tests/Functional/FunctionalTest.php b/tests/Functional/FunctionalTest.php index cefe1230..11b761b3 100644 --- a/tests/Functional/FunctionalTest.php +++ b/tests/Functional/FunctionalTest.php @@ -12,15 +12,17 @@ use Functional\Functional; use PHPUnit\Framework\TestCase; +use ReflectionClass; +use ReflectionException; class FunctionalTest extends TestCase { /** - * @throws \ReflectionException + * @throws ReflectionException */ public function testAllDefinedConstantsAreValidCallables(): void { - $functionalClass = new \ReflectionClass(Functional::class); + $functionalClass = new ReflectionClass(Functional::class); $functions = $functionalClass->getConstants(); foreach ($functions as $function) { @@ -34,16 +36,16 @@ public function testAllDefinedConstantsAreValidCallables(): void public function testShouldHaveDefinedConstantsForAllFunctions(): void { - $functions = \get_defined_functions(true); - $functionalFunctions = \preg_grep('/functional\\\(?!tests)/', $functions['user']); - $expectedFunctions = \array_map( + $functions = get_defined_functions(true); + $functionalFunctions = preg_grep('/functional\\\(?!tests)/', $functions['user']); + $expectedFunctions = array_map( static function ($function) { - return \str_replace('functional\\', '\\Functional\\', $function); + return str_replace('functional\\', '\\Functional\\', $function); }, $functionalFunctions ); - $functionalClass = new \ReflectionClass(Functional::class); + $functionalClass = new ReflectionClass(Functional::class); $constants = $functionalClass->getConstants(); foreach ($expectedFunctions as $function) { diff --git a/tests/Functional/GroupTest.php b/tests/Functional/GroupTest.php index d8ea2f1c..1c1b5b89 100644 --- a/tests/Functional/GroupTest.php +++ b/tests/Functional/GroupTest.php @@ -14,6 +14,9 @@ use Functional\Exceptions\InvalidArgumentException; use function Functional\group; +use Exception; +use stdClass; +use function is_int; class GroupTest extends AbstractTestCase { @@ -30,7 +33,7 @@ public function test(): void { $fn = function ($v, $k, $collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return (\is_int($k) ? ($k % 2 == 0) : ($v[3] % 2 == 0)) ? 'foo' : ''; + return (is_int($k) ? ($k % 2 == 0) : ($v[3] % 2 == 0)) ? 'foo' : ''; }; self::assertSame(['foo' => [0 => 'value1', 2 => 'value3'], '' => [1 => 'value2', 3 => 'value4']], group($this->list, $fn)); self::assertSame(['foo' => [0 => 'value1', 2 => 'value3'], '' => [1 => 'value2', 3 => 'value4']], group($this->listIterator, $fn)); @@ -57,8 +60,8 @@ public function testExceptionIsThrownWhenCallbacksReturnsInvalidKey(): void $invalidTypes = [ - 'resource' => \stream_context_create(), - 'object' => new \stdClass(), + 'resource' => stream_context_create(), + 'object' => new stdClass(), 'array' => [] ]; @@ -66,10 +69,10 @@ public function testExceptionIsThrownWhenCallbacksReturnsInvalidKey(): void $keyMap = [$value]; try { group(['v1'], $fn); - self::fail(\sprintf('Error expected for array key type "%s"', $type)); - } catch (\Exception $e) { + self::fail(sprintf('Error expected for array key type "%s"', $type)); + } catch (Exception $e) { self::assertSame( - \sprintf( + sprintf( 'Functional\group(): callback returned invalid array key of type "%s". Expected NULL, string, integer, double or boolean', $type ), diff --git a/tests/Functional/InvokeFirstTest.php b/tests/Functional/InvokeFirstTest.php index 4b86e102..c0f0b354 100644 --- a/tests/Functional/InvokeFirstTest.php +++ b/tests/Functional/InvokeFirstTest.php @@ -14,6 +14,8 @@ use Traversable; use function Functional\invoke_first; +use stdClass; +use function func_get_args; class InvokeFirstTest extends AbstractTestCase { @@ -73,7 +75,7 @@ public function testPassNoCollection(): void public function testPassNoPropertyName(): void { $this->expectArgumentError('Functional\invoke_first() expects parameter 2 to be string'); - invoke_first($this->list, new \stdClass()); + invoke_first($this->list, new stdClass()); } public function testException(): void @@ -90,6 +92,6 @@ public function method(): string public function returnArguments(): array { - return \func_get_args(); + return func_get_args(); } } diff --git a/tests/Functional/InvokeIfTest.php b/tests/Functional/InvokeIfTest.php index 60a1e456..31fab362 100644 --- a/tests/Functional/InvokeIfTest.php +++ b/tests/Functional/InvokeIfTest.php @@ -11,6 +11,8 @@ namespace Functional\Tests; use function Functional\invoke_if; +use stdClass; +use function func_get_args; class InvokeIfTest extends AbstractTestCase { @@ -27,7 +29,7 @@ public function test(): void public function testReturnDefaultValueUsed(): void { - $instance = new \stdClass(); + $instance = new stdClass(); self::assertSame('defaultValue', invoke_if($instance, 'someMethod', [], 'defaultValue')); self::assertSame($instance, invoke_if($this, 'someMethod', [], $instance)); self::assertNull(invoke_if($this, 'someMethod', [], null)); @@ -40,6 +42,6 @@ public function method(): string public function returnArguments(): array { - return \func_get_args(); + return func_get_args(); } } diff --git a/tests/Functional/InvokeLastTest.php b/tests/Functional/InvokeLastTest.php index e3bbe863..a84132f7 100644 --- a/tests/Functional/InvokeLastTest.php +++ b/tests/Functional/InvokeLastTest.php @@ -13,6 +13,8 @@ use ArrayIterator; use function Functional\invoke_last; +use stdClass; +use function func_get_args; class InvokeLastTest extends AbstractTestCase { @@ -62,7 +64,7 @@ public function testPassNoCollection(): void public function testPassNoPropertyName(): void { $this->expectArgumentError('Functional\invoke_last() expects parameter 2 to be string'); - invoke_last($this->list, new \stdClass()); + invoke_last($this->list, new stdClass()); } public function testException(): void @@ -79,6 +81,6 @@ public function method(): string public function returnArguments(): array { - return \func_get_args(); + return func_get_args(); } } diff --git a/tests/Functional/InvokeTest.php b/tests/Functional/InvokeTest.php index e85ca6d8..6e646d50 100644 --- a/tests/Functional/InvokeTest.php +++ b/tests/Functional/InvokeTest.php @@ -14,6 +14,8 @@ use Traversable; use function Functional\invoke; +use stdClass; +use function func_get_args; class InvokeTest extends AbstractTestCase { @@ -52,7 +54,7 @@ public function testPassNoCollection(): void public function testPassNoPropertyName(): void { $this->expectArgumentError('Functional\invoke() expects parameter 2 to be string'); - invoke($this->list, new \stdClass()); + invoke($this->list, new stdClass()); } public function testException(): void @@ -69,6 +71,6 @@ public function method(): string public function returnArguments(): array { - return \func_get_args(); + return func_get_args(); } } diff --git a/tests/Functional/InvokerTest.php b/tests/Functional/InvokerTest.php index 4709654c..9f32fbbe 100644 --- a/tests/Functional/InvokerTest.php +++ b/tests/Functional/InvokerTest.php @@ -35,7 +35,7 @@ public function testPassNoString(): void public function testInvalidMethod(): void { - if (!\class_exists('Error')) { + if (!class_exists('Error')) { self::markTestSkipped('Requires PHP 7'); } diff --git a/tests/Functional/MathDataProvider.php b/tests/Functional/MathDataProvider.php index 068a5640..d70f7a00 100644 --- a/tests/Functional/MathDataProvider.php +++ b/tests/Functional/MathDataProvider.php @@ -18,7 +18,7 @@ class MathDataProvider public static function injectErrorCollection(): array { $args = []; - foreach ([new stdClass(), \stream_context_create(), [], "str"] as $v) { + foreach ([new stdClass(), stream_context_create(), [], "str"] as $v) { $arg = [2, $v, "1.5", true, null]; $args[] = [$arg]; $args[] = [new ArrayIterator($arg)]; diff --git a/tests/Functional/MemoizeTest.php b/tests/Functional/MemoizeTest.php index 5f83c707..64db3cfa 100644 --- a/tests/Functional/MemoizeTest.php +++ b/tests/Functional/MemoizeTest.php @@ -31,7 +31,7 @@ class MemoizeTest extends AbstractTestCase public static function invoke($name): int { if (self::$invocation > 0) { - throw new BadMethodCallException(\sprintf('%s called more than once', $name)); + throw new BadMethodCallException(sprintf('%s called more than once', $name)); } self::$invocation++; return self::$invocation; @@ -187,7 +187,7 @@ public function __invoke(): int $this->actualInvocations++; if ($this->actualInvocations > $this->expectedInvocations) { throw new RuntimeException( - \sprintf( + sprintf( 'ID %d: Expected %d invocations, got %d', $this->id, $this->expectedInvocations, @@ -203,7 +203,7 @@ public function __destruct() { if ($this->actualInvocations !== $this->expectedInvocations) { throw new RuntimeException( - \sprintf( + sprintf( 'ID %d: Expected %d invocations, got %d', $this->id, $this->expectedInvocations, diff --git a/tests/Functional/NoneTest.php b/tests/Functional/NoneTest.php index a1d1a3ba..0f2d2c5d 100644 --- a/tests/Functional/NoneTest.php +++ b/tests/Functional/NoneTest.php @@ -14,6 +14,7 @@ use Functional\Exceptions\InvalidArgumentException; use function Functional\none; +use function strlen; class NoneTest extends AbstractTestCase { @@ -83,6 +84,6 @@ public function testExceptionIsThrownInIterator(): void public function functionalCallback($value, $key, $collection): bool { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return $value != 'value' && \strlen($key) > 0; + return $value != 'value' && strlen($key) > 0; } } diff --git a/tests/Functional/OmitKeysTest.php b/tests/Functional/OmitKeysTest.php index 5581b3d3..b8ea5eef 100644 --- a/tests/Functional/OmitKeysTest.php +++ b/tests/Functional/OmitKeysTest.php @@ -13,6 +13,7 @@ use ArrayIterator; use function Functional\omit_keys; +use stdclass; class OmitKeysTest extends AbstractTestCase { @@ -40,6 +41,6 @@ public function test(array $expected, array $input, array $keys): void public function testPassNonArrayOrTraversable(): void { $this->expectArgumentError("Functional\omit_keys() expects parameter 1 to be array or instance of Traversable"); - omit_keys(new \stdclass(), []); + omit_keys(new stdclass(), []); } } diff --git a/tests/Functional/PartialAnyTest.php b/tests/Functional/PartialAnyTest.php index c403ee83..e2a6ffa3 100644 --- a/tests/Functional/PartialAnyTest.php +++ b/tests/Functional/PartialAnyTest.php @@ -17,6 +17,7 @@ use function Functional\…; use const Functional\…; +use function defined; class PartialAnyTest extends AbstractPartialTestCase { @@ -29,10 +30,10 @@ public function testBindWithPlaceholder(): void public function testBindWithPlaceholderConstant(): void { - $context = \hash_init('md2'); + $context = hash_init('md2'); $hash = partial_any('hash_update', $context, …()); $hash('oh hi'); - self::assertSame('6f24cbf6005b9bfc0176abbbe309f0d0', \hash_final($context)); + self::assertSame('6f24cbf6005b9bfc0176abbbe309f0d0', hash_final($context)); } public function testBindWithMultiplePlaceholders(): void @@ -61,7 +62,7 @@ public function testAliasForUnicodePlaceholder(): void self::assertSame(…(), placeholder()); /* @see https://github.com/facebook/hhvm/issues/5548 */ - if (!\defined('HHVM_VERSION')) { + if (!defined('HHVM_VERSION')) { self::assertSame(…, placeholder()); } } diff --git a/tests/Functional/PartitionTest.php b/tests/Functional/PartitionTest.php index ad931752..616cf796 100644 --- a/tests/Functional/PartitionTest.php +++ b/tests/Functional/PartitionTest.php @@ -14,6 +14,7 @@ use Functional\Exceptions\InvalidArgumentException; use function Functional\partition; +use function is_int; class PartitionTest extends AbstractTestCase { @@ -30,7 +31,7 @@ public function test(): void { $fn = function ($v, $k, $collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return \is_int($k) ? ($k % 2 == 0) : ($v[3] % 2 == 0); + return is_int($k) ? ($k % 2 == 0) : ($v[3] % 2 == 0); }; self::assertSame([[0 => 'value1', 2 => 'value3'], [1 => 'value2']], partition($this->list, $fn)); self::assertSame([[0 => 'value1', 2 => 'value3'], [1 => 'value2']], partition($this->listIterator, $fn)); @@ -42,12 +43,12 @@ public function testMultiFn(): void { $fn1 = function ($v, $k, $collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return \is_int($k) ? ($k === 1) : ($v[3] === '2'); + return is_int($k) ? ($k === 1) : ($v[3] === '2'); }; $fn2 = function ($v, $k, $collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return \is_int($k) ? ($k === 2) : ($v[3] === '3'); + return is_int($k) ? ($k === 2) : ($v[3] === '3'); }; self::assertSame([[1 => 'value2'], [2 => 'value3'], [0 => 'value1']], partition($this->list, $fn1, $fn2)); diff --git a/tests/Functional/PluckTest.php b/tests/Functional/PluckTest.php index 4159ce56..5e9b0ccc 100644 --- a/tests/Functional/PluckTest.php +++ b/tests/Functional/PluckTest.php @@ -16,12 +16,15 @@ use Traversable; use function Functional\pluck; +use DomainException; +use Exception; +use stdClass; class MagicGetThrowException { public function __get($propertyName) { - throw new \Exception($propertyName); + throw new Exception($propertyName); } } @@ -59,7 +62,7 @@ public function __construct($throwExceptionInIsset, $throwExceptionInGet) public function __isset($propertyName): bool { if ($this->throwExceptionInIsset) { - throw new \DomainException('__isset exception: ' . $propertyName); + throw new DomainException('__isset exception: ' . $propertyName); } return true; } @@ -67,7 +70,7 @@ public function __isset($propertyName): bool public function __get($propertyName): string { if ($this->throwExceptionInGet) { - throw new \DomainException('__get exception: ' . $propertyName); + throw new DomainException('__get exception: ' . $propertyName); } return "value"; } @@ -82,7 +85,7 @@ public function call($collection, $property): array $this->property = 'value'; $plucked = pluck($collection, $property); if (!isset($this->property)) { - throw new \Exception('Property is no longer accessable'); + throw new Exception('Property is no longer accessable'); } return $plucked; } @@ -158,7 +161,7 @@ public function getNullList(): array public function variateList($hash, $asObject = true): array { - return $this->variate(\array_values($hash), $asObject); + return $this->variate(array_values($hash), $asObject); } public function variateHash($hash, $asObject = true): array @@ -221,8 +224,8 @@ public function testPluckNumericArrayIndex(): void self::assertSame(['one' => 1, 'two' => null, 'three' => null, 'four' => 2, 'five' => 3], pluck($this->numericArrayCollection, 0)); self::assertSame(['one' => 1, 'two' => null, 'three' => null, 'four' => 2, 'five' => 3], pluck($this->numericArrayCollection, 0)); self::assertSame(['one' => 1, 'two' => null, 'three' => null, 'four' => 2, 'five' => 3], pluck(new ArrayIterator($this->numericArrayCollection), 0)); - self::assertSame([1, null, null, 2, 3], pluck(\array_values($this->numericArrayCollection), 0)); - self::assertSame([1, null, null, 2, 3], pluck(new ArrayIterator(\array_values($this->numericArrayCollection)), 0)); + self::assertSame([1, null, null, 2, 3], pluck(array_values($this->numericArrayCollection), 0)); + self::assertSame([1, null, null, 2, 3], pluck(new ArrayIterator(array_values($this->numericArrayCollection)), 0)); self::assertSame(['one' => 1, 'two' => null, 'three' => null, 'four' => 2, 'five' => 3], pluck($this->numericArrayCollection, '0')); } @@ -247,7 +250,7 @@ public function testPassNoCollection(): void public function testPassNoPropertyName(): void { $this->expectArgumentError('Functional\pluck() expects parameter 2 to be a valid property name or array index, stdClass given'); - pluck($this->propertyExistsSomewhere, new \stdClass()); + pluck($this->propertyExistsSomewhere, new stdClass()); } public function testExceptionThrownInMagicIssetWhileIteratingArray(): void diff --git a/tests/Functional/PollTest.php b/tests/Functional/PollTest.php index 67aead2a..6beab0b5 100644 --- a/tests/Functional/PollTest.php +++ b/tests/Functional/PollTest.php @@ -59,7 +59,7 @@ public function testPollRetriesAndGivesUpAfterTimeout(): void ->withConsecutive([0, 0]) ->willReturnCallback( function () { - \usleep(100); + usleep(100); return false; } ); diff --git a/tests/Functional/RejectTest.php b/tests/Functional/RejectTest.php index 141e0048..63606be5 100644 --- a/tests/Functional/RejectTest.php +++ b/tests/Functional/RejectTest.php @@ -14,6 +14,7 @@ use Functional\Exceptions\InvalidArgumentException; use function Functional\reject; +use function strlen; class RejectTest extends AbstractTestCase { @@ -30,7 +31,7 @@ public function test(): void { $fn = function ($v, $k, $collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return $v == 'wrong' && \strlen($k) > 0; + return $v == 'wrong' && strlen($k) > 0; }; self::assertSame([0 => 'value', 2 => 'value'], reject($this->list, $fn)); self::assertSame([0 => 'value', 2 => 'value'], reject($this->listIterator, $fn)); diff --git a/tests/Functional/SelectKeysTest.php b/tests/Functional/SelectKeysTest.php index 6351f671..ae1ac4b1 100644 --- a/tests/Functional/SelectKeysTest.php +++ b/tests/Functional/SelectKeysTest.php @@ -13,6 +13,7 @@ use ArrayIterator; use function Functional\select_keys; +use stdclass; class SelectKeysTest extends AbstractTestCase { @@ -39,6 +40,6 @@ public function test(array $expected, array $input, array $keys): void public function testPassNonArrayOrTraversable(): void { $this->expectArgumentError("Functional\select_keys() expects parameter 1 to be array or instance of Traversable"); - select_keys(new \stdclass(), []); + select_keys(new stdclass(), []); } } diff --git a/tests/Functional/SelectTest.php b/tests/Functional/SelectTest.php index 901f8dcd..4bab34b8 100644 --- a/tests/Functional/SelectTest.php +++ b/tests/Functional/SelectTest.php @@ -14,6 +14,7 @@ use Functional\Exceptions\InvalidArgumentException; use function Functional\select; +use function strlen; class SelectTest extends AbstractTestCase { @@ -42,7 +43,7 @@ public function test($functionName): void $callback = function ($v, $k, $collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return $v == 'value' && \strlen($k) > 0; + return $v == 'value' && strlen($k) > 0; }; self::assertSame(['value', 2 => 'value'], $functionName($this->list, $callback)); self::assertSame(['value', 2 => 'value'], $functionName($this->listIterator, $callback)); @@ -74,7 +75,7 @@ public function testPassNoCallable(): void public function testPassNoCollection($functionName): void { $this->expectArgumentError( - \sprintf( + sprintf( '%s() expects parameter 1 to be array or instance of Traversable', $functionName ) diff --git a/tests/Functional/SortTest.php b/tests/Functional/SortTest.php index 5525702f..c2514917 100644 --- a/tests/Functional/SortTest.php +++ b/tests/Functional/SortTest.php @@ -28,7 +28,7 @@ protected function setUp(): void $this->hashIterator = new ArrayIterator($this->hash); $this->sortCallback = static function ($left, $right, $collection) { InvalidArgumentException::assertCollection($collection, __FUNCTION__, 3); - return \strcmp($left, $right); + return strcmp($left, $right); }; } diff --git a/tests/Functional/SuppressErrorTest.php b/tests/Functional/SuppressErrorTest.php index 527673d7..0327ea7b 100644 --- a/tests/Functional/SuppressErrorTest.php +++ b/tests/Functional/SuppressErrorTest.php @@ -21,7 +21,7 @@ class SuppressErrorTest extends AbstractTestCase public function testErrorIsSuppressed(): void { $origFn = function () { - \trigger_error('Some error', E_USER_ERROR); + trigger_error('Some error', E_USER_ERROR); }; $fn = suppress_error($origFn); @@ -53,14 +53,14 @@ function () use ($expectedException) { public function testErrorHandlerNestingWorks(): void { $errorMessage = null; - \set_error_handler( + set_error_handler( static function ($level, $message) use (&$errorMessage) { $errorMessage = $message; } ); $origFn = static function () { - \trigger_error('Some error', E_USER_ERROR); + trigger_error('Some error', E_USER_ERROR); }; $fn = suppress_error($origFn); @@ -69,6 +69,6 @@ static function ($level, $message) use (&$errorMessage) { self::assertNull($errorMessage); $origFn(); self::assertSame('Some error', $errorMessage); - \restore_error_handler(); + restore_error_handler(); } } diff --git a/tests/Functional/TapTest.php b/tests/Functional/TapTest.php index 00f6056e..c05bc639 100644 --- a/tests/Functional/TapTest.php +++ b/tests/Functional/TapTest.php @@ -11,6 +11,7 @@ namespace Functional\Tests; use function Functional\tap; +use stdClass; class TapTest extends AbstractTestCase { @@ -27,7 +28,7 @@ public function testPassNonCallable(): void public function testTap(): void { - $input = new \stdClass(); + $input = new stdClass(); $input->property = 'foo'; $output = tap($input, function ($o) { diff --git a/tests/Functional/ValueToKeyTest.php b/tests/Functional/ValueToKeyTest.php index 665e6cdc..d46c78a5 100644 --- a/tests/Functional/ValueToKeyTest.php +++ b/tests/Functional/ValueToKeyTest.php @@ -28,7 +28,7 @@ class ValueToKeyTest extends AbstractTestCase public static function getSimpleTypeExpectations(): array { - $binary = \random_bytes(10); + $binary = random_bytes(10); return [ 'Nothing' => [[], '[]'], @@ -75,7 +75,7 @@ public function testValueToRefOnSimpleTypes(array $input, $constraint): void public function testExpectationsAreNonIdentical(): void { $strings = filter(pluck(self::getSimpleTypeExpectations(), 1), ary('is_string', 1)); - while ($string = \array_pop($strings)) { + while ($string = array_pop($strings)) { foreach ($strings as $otherString) { if ($string === $otherString) { self::fail($string); @@ -88,10 +88,10 @@ public function testExpectationsAreNonIdentical(): void public static function getErrorCases(): array { return [ - [\stream_context_create()], - [[\stream_context_create()]], - [['key' => \stream_context_create()]], - [new ArrayObject(['key' => \stream_context_create()])], + [stream_context_create()], + [[stream_context_create()]], + [['key' => stream_context_create()]], + [new ArrayObject(['key' => stream_context_create()])], ]; } @@ -110,12 +110,12 @@ public function testObjectReferencesWithStdClass(): void self::assertSame( 1, - \preg_match(self::createObjectRefRegex('stdClass'), $key1, $key1Matches), + preg_match(self::createObjectRefRegex('stdClass'), $key1, $key1Matches), 'Can extract object hash from key1' ); self::assertSame( 1, - \preg_match(self::createObjectRefRegex('stdClass'), $key2, $key2Matches), + preg_match(self::createObjectRefRegex('stdClass'), $key2, $key2Matches), 'Can extract object hash from key2' ); @@ -132,12 +132,12 @@ public function testObjectReferencesWithArrayObject(): void self::assertSame( 1, - \preg_match(self::createObjectRefRegex('ArrayObject'), $key1, $key1Matches), + preg_match(self::createObjectRefRegex('ArrayObject'), $key1, $key1Matches), 'Can extract object hash from key1' ); self::assertSame( 1, - \preg_match(self::createObjectRefRegex('ArrayObject'), $key2, $key2Matches), + preg_match(self::createObjectRefRegex('ArrayObject'), $key2, $key2Matches), 'Can extract object hash from key2' ); @@ -148,6 +148,6 @@ public function testObjectReferencesWithArrayObject(): void private static function createObjectRefRegex(string $class = '.*'): string { - return \sprintf(self::OBJECT_REF_REGEX, $class); + return sprintf(self::OBJECT_REF_REGEX, $class); } } diff --git a/tests/Functional/WithTest.php b/tests/Functional/WithTest.php index 86723dae..6484c950 100644 --- a/tests/Functional/WithTest.php +++ b/tests/Functional/WithTest.php @@ -11,6 +11,7 @@ namespace Functional\Tests; use function Functional\with; +use Exception; class WithTest extends AbstractTestCase { @@ -18,7 +19,7 @@ public function testWithNull(): void { self::assertNull( with(null, function () { - throw new \Exception('Should not be called'); + throw new Exception('Should not be called'); }) ); } diff --git a/tests/Functional/ZipAllTest.php b/tests/Functional/ZipAllTest.php index 6776657e..cd3f2395 100644 --- a/tests/Functional/ZipAllTest.php +++ b/tests/Functional/ZipAllTest.php @@ -13,6 +13,7 @@ use BadFunctionCallException; use function Functional\zip_all; +use ArrayIterator; class ZipAllTest extends AbstractTestCase { @@ -56,8 +57,8 @@ public function testIterator(): void self::assertSame( ['a' => [2, 4], 'b' => [3, 5]], zip_all( - new \ArrayIterator(['a' => 2, 'b' => 3]), - new \ArrayIterator(['a' => 4, 'b' => 5]) + new ArrayIterator(['a' => 2, 'b' => 3]), + new ArrayIterator(['a' => 4, 'b' => 5]) ) ); } diff --git a/tests/Functional/ZipTest.php b/tests/Functional/ZipTest.php index 79d426c3..39252b20 100644 --- a/tests/Functional/ZipTest.php +++ b/tests/Functional/ZipTest.php @@ -101,7 +101,7 @@ function ($one, $two, $three, $four) { public function testZippingArraysWithVariousElements(): void { $object = new stdClass(); - $resource = \stream_context_create(); + $resource = stream_context_create(); $result = [ [[1], $object, [2]], [null, 'foo', null], From 118f33e67c1cb94a6444c77bbc8a70d61a707dc3 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:32:27 +0100 Subject: [PATCH 03/11] ci: drop experimental since it should not be needed --- .github/workflows/test.yaml | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 96e9dea7..f22374b1 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -4,7 +4,7 @@ on: [push, pull_request] jobs: test: - name: PHP ${{ matrix.php-version }} (${{ matrix.experimental && 'experimental' || 'full support' }}) + name: PHP ${{ matrix.php-version }} runs-on: ubuntu-18.04 @@ -15,12 +15,7 @@ jobs: - 8.1 - 8.2 - 8.3 - experimental: [false] - include: - - php-version: 8.1 - experimental: true - continue-on-error: ${{ matrix.experimental }} steps: - name: Checkout uses: actions/checkout@v2 @@ -36,7 +31,6 @@ jobs: uses: ramsey/composer-install@v1 with: composer-options: --prefer-dist - continue-on-error: ${{ matrix.experimental }} - name: Setup PCOV run: | @@ -46,8 +40,6 @@ jobs: - name: Run Tests run: composer tests - continue-on-error: ${{ matrix.experimental }} - name: Check coding style run: composer coding-style - continue-on-error: ${{ matrix.experimental }} From 1590256f97113b84f7a99e6ef37438cd68e6b32a Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:32:53 +0100 Subject: [PATCH 04/11] ci: bump ubuntu --- .github/workflows/test.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f22374b1..a30d4c49 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -6,7 +6,7 @@ jobs: test: name: PHP ${{ matrix.php-version }} - runs-on: ubuntu-18.04 + runs-on: ubuntu-22.04 strategy: fail-fast: false From c913e268c554914eceb9c4133ce7a2424c68a537 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:36:23 +0100 Subject: [PATCH 05/11] fix: add return types to ExponentialSequence --- src/Functional/Sequences/ExponentialSequence.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Functional/Sequences/ExponentialSequence.php b/src/Functional/Sequences/ExponentialSequence.php index 2feac7aa..0902e6c3 100644 --- a/src/Functional/Sequences/ExponentialSequence.php +++ b/src/Functional/Sequences/ExponentialSequence.php @@ -38,28 +38,28 @@ public function __construct($start, $percentage) $this->percentage = $percentage; } - public function current() + public function current(): int { return $this->value; } - public function next() + public function next(): void { $this->value = (int) round(pow($this->start * (1 + $this->percentage / 100), $this->times)); $this->times++; } - public function key() + public function key(): mixed { return null; } - public function valid() + public function valid(): bool { return true; } - public function rewind() + public function rewind(): void { $this->times = 1; $this->value = $this->start; From e193323b5d2fa908b6c974d06d731e84f9976cb6 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:37:28 +0100 Subject: [PATCH 06/11] fix: add return types to LinearSequence --- src/Functional/Sequences/LinearSequence.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Functional/Sequences/LinearSequence.php b/src/Functional/Sequences/LinearSequence.php index ad99dfbb..e7345a6a 100644 --- a/src/Functional/Sequences/LinearSequence.php +++ b/src/Functional/Sequences/LinearSequence.php @@ -34,27 +34,27 @@ public function __construct($start, $amount) $this->amount = $amount; } - public function current() + public function current(): int { return $this->value; } - public function next() + public function next(): void { $this->value += $this->amount; } - public function key() + public function key(): int { return 0; } - public function valid() + public function valid(): bool { return true; } - public function rewind() + public function rewind(): void { $this->value = $this->start; } From cfabae958be02d0dee6fd7541d8e2e2ddb255b63 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:39:01 +0100 Subject: [PATCH 07/11] ci: remove pcov/clobber --- .github/workflows/test.yaml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index a30d4c49..228ec9ef 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -32,12 +32,6 @@ jobs: with: composer-options: --prefer-dist - - name: Setup PCOV - run: | - composer require pcov/clobber - vendor/bin/pcov clobber - continue-on-error: true - - name: Run Tests run: composer tests From 70732bb9d247b861c8a779cc33a5e39dc08f9344 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:42:09 +0100 Subject: [PATCH 08/11] fix: handle implicit conversion from float to int > Implicit conversion from float 2.1 to int loses precision --- src/Functional/Group.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Functional/Group.php b/src/Functional/Group.php index af2ed3a1..ff4d7136 100644 --- a/src/Functional/Group.php +++ b/src/Functional/Group.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; +use function is_float; /** * Groups a collection by index returned by callback. @@ -32,6 +33,7 @@ function group($collection, callable $callback) InvalidArgumentException::assertValidArrayKey($groupKey, __FUNCTION__); + $groupKey = is_float($groupKey) ? (int) $groupKey : $groupKey; if (!isset($groups[$groupKey])) { $groups[$groupKey] = []; } From da1a46c89241ad1210e68c170f8cd85e43498314 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:43:56 +0100 Subject: [PATCH 09/11] style: fix cs vol.2 --- phpcs.xml.dist | 2 ++ src/Functional/ButLast.php | 1 + src/Functional/Curry.php | 1 + src/Functional/CurryN.php | 1 + src/Functional/Exceptions/InvalidArgumentException.php | 1 + src/Functional/Exceptions/MatchException.php | 1 + src/Functional/FirstIndexOf.php | 1 + src/Functional/FlatMap.php | 1 + src/Functional/Flatten.php | 1 + src/Functional/Flip.php | 1 + src/Functional/Functional.php | 1 - src/Functional/GreaterThan.php | 1 + src/Functional/GreaterThanOrEqual.php | 1 + src/Functional/Group.php | 1 + src/Functional/IndexesOf.php | 1 + src/Functional/Invoke.php | 1 + src/Functional/InvokeFirst.php | 1 + src/Functional/InvokeIf.php | 1 + src/Functional/InvokeLast.php | 1 + src/Functional/LastIndexOf.php | 1 + src/Functional/LessThan.php | 1 + src/Functional/LessThanOrEqual.php | 1 + src/Functional/LexicographicCompare.php | 1 + src/Functional/Memoize.php | 1 + src/Functional/PartialAny.php | 1 + src/Functional/PartialMethod.php | 1 + src/Functional/Partition.php | 1 + src/Functional/Pick.php | 1 + src/Functional/Pluck.php | 1 + src/Functional/TakeLeft.php | 1 + src/Functional/TakeRight.php | 1 + src/Functional/Unique.php | 1 + src/Functional/ValueToKey.php | 1 + src/Functional/With.php | 1 + src/Functional/Zip.php | 1 + src/Functional/ZipAll.php | 1 + tests/Functional/AbstractTestCase.php | 1 + tests/Functional/GroupTest.php | 2 ++ tests/Functional/InvokeFirstTest.php | 2 ++ tests/Functional/InvokeIfTest.php | 2 ++ tests/Functional/InvokeLastTest.php | 2 ++ tests/Functional/InvokeTest.php | 2 ++ tests/Functional/OmitKeysTest.php | 1 + tests/Functional/PartialAnyTest.php | 1 + tests/Functional/PartialMethodTest.php | 1 - tests/Functional/PluckTest.php | 1 + tests/Functional/SelectKeysTest.php | 1 + tests/Functional/TapTest.php | 1 + tests/Functional/WithTest.php | 1 + tests/Functional/ZipAllTest.php | 1 + 50 files changed, 54 insertions(+), 2 deletions(-) diff --git a/phpcs.xml.dist b/phpcs.xml.dist index c8fb9e17..f2e08457 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -10,6 +10,8 @@ + + diff --git a/src/Functional/ButLast.php b/src/Functional/ButLast.php index 1581dbbe..8d7c0655 100644 --- a/src/Functional/ButLast.php +++ b/src/Functional/ButLast.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_array; /** diff --git a/src/Functional/Curry.php b/src/Functional/Curry.php index dcc35caf..8f81ea6a 100644 --- a/src/Functional/Curry.php +++ b/src/Functional/Curry.php @@ -13,6 +13,7 @@ use ReflectionMethod; use ReflectionFunction; use Closure; + use function count; use function is_array; use function is_object; diff --git a/src/Functional/CurryN.php b/src/Functional/CurryN.php index 802c877b..73113b2f 100644 --- a/src/Functional/CurryN.php +++ b/src/Functional/CurryN.php @@ -9,6 +9,7 @@ */ namespace Functional; + use function call_user_func_array; use function count; diff --git a/src/Functional/Exceptions/InvalidArgumentException.php b/src/Functional/Exceptions/InvalidArgumentException.php index d87d42e0..be541a06 100644 --- a/src/Functional/Exceptions/InvalidArgumentException.php +++ b/src/Functional/Exceptions/InvalidArgumentException.php @@ -9,6 +9,7 @@ */ namespace Functional\Exceptions; + use function count; use function get_class; use function gettype; diff --git a/src/Functional/Exceptions/MatchException.php b/src/Functional/Exceptions/MatchException.php index 55e941f2..6c75b534 100644 --- a/src/Functional/Exceptions/MatchException.php +++ b/src/Functional/Exceptions/MatchException.php @@ -9,6 +9,7 @@ */ namespace Functional\Exceptions; + use function count; use function gettype; use function is_array; diff --git a/src/Functional/FirstIndexOf.php b/src/Functional/FirstIndexOf.php index b97b987a..ad397b46 100644 --- a/src/Functional/FirstIndexOf.php +++ b/src/Functional/FirstIndexOf.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_callable; /** diff --git a/src/Functional/FlatMap.php b/src/Functional/FlatMap.php index 91752088..8e8b265a 100644 --- a/src/Functional/FlatMap.php +++ b/src/Functional/FlatMap.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_array; /** diff --git a/src/Functional/Flatten.php b/src/Functional/Flatten.php index 085d6445..7fd57472 100644 --- a/src/Functional/Flatten.php +++ b/src/Functional/Flatten.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_array; /** diff --git a/src/Functional/Flip.php b/src/Functional/Flip.php index 631908dd..92dcd026 100644 --- a/src/Functional/Flip.php +++ b/src/Functional/Flip.php @@ -9,6 +9,7 @@ */ namespace Functional; + use function func_get_args; /** diff --git a/src/Functional/Functional.php b/src/Functional/Functional.php index caaed895..59936572 100644 --- a/src/Functional/Functional.php +++ b/src/Functional/Functional.php @@ -12,7 +12,6 @@ final class Functional { - /** * @see \Function\ary */ diff --git a/src/Functional/GreaterThan.php b/src/Functional/GreaterThan.php index ad9f3383..3d682d90 100644 --- a/src/Functional/GreaterThan.php +++ b/src/Functional/GreaterThan.php @@ -9,6 +9,7 @@ */ namespace Functional; + use Closure; /** diff --git a/src/Functional/GreaterThanOrEqual.php b/src/Functional/GreaterThanOrEqual.php index 397f51c7..d17b0654 100644 --- a/src/Functional/GreaterThanOrEqual.php +++ b/src/Functional/GreaterThanOrEqual.php @@ -9,6 +9,7 @@ */ namespace Functional; + use Closure; /** diff --git a/src/Functional/Group.php b/src/Functional/Group.php index ff4d7136..c7ca6202 100644 --- a/src/Functional/Group.php +++ b/src/Functional/Group.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_float; /** diff --git a/src/Functional/IndexesOf.php b/src/Functional/IndexesOf.php index b197f319..afadaf84 100644 --- a/src/Functional/IndexesOf.php +++ b/src/Functional/IndexesOf.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_callable; /** diff --git a/src/Functional/Invoke.php b/src/Functional/Invoke.php index 876542df..4a10d921 100644 --- a/src/Functional/Invoke.php +++ b/src/Functional/Invoke.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_callable; /** diff --git a/src/Functional/InvokeFirst.php b/src/Functional/InvokeFirst.php index 20478b2d..f0d0ef5a 100644 --- a/src/Functional/InvokeFirst.php +++ b/src/Functional/InvokeFirst.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_callable; /** diff --git a/src/Functional/InvokeIf.php b/src/Functional/InvokeIf.php index 34cfacae..8b6ebd03 100644 --- a/src/Functional/InvokeIf.php +++ b/src/Functional/InvokeIf.php @@ -9,6 +9,7 @@ */ namespace Functional; + use function is_callable; /** diff --git a/src/Functional/InvokeLast.php b/src/Functional/InvokeLast.php index 49eda8ac..4b566eb0 100644 --- a/src/Functional/InvokeLast.php +++ b/src/Functional/InvokeLast.php @@ -12,6 +12,7 @@ use Traversable; use Functional\Exceptions\InvalidArgumentException; + use function is_callable; /** diff --git a/src/Functional/LastIndexOf.php b/src/Functional/LastIndexOf.php index a05762f7..561390a6 100644 --- a/src/Functional/LastIndexOf.php +++ b/src/Functional/LastIndexOf.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_callable; /** diff --git a/src/Functional/LessThan.php b/src/Functional/LessThan.php index ff178237..5dbf12e7 100644 --- a/src/Functional/LessThan.php +++ b/src/Functional/LessThan.php @@ -9,6 +9,7 @@ */ namespace Functional; + use Closure; /** diff --git a/src/Functional/LessThanOrEqual.php b/src/Functional/LessThanOrEqual.php index d65e992c..ba8a5918 100644 --- a/src/Functional/LessThanOrEqual.php +++ b/src/Functional/LessThanOrEqual.php @@ -9,6 +9,7 @@ */ namespace Functional; + use Closure; /** diff --git a/src/Functional/LexicographicCompare.php b/src/Functional/LexicographicCompare.php index 2a8bd1aa..c5c529fa 100644 --- a/src/Functional/LexicographicCompare.php +++ b/src/Functional/LexicographicCompare.php @@ -9,6 +9,7 @@ */ namespace Functional; + use Closure; /** diff --git a/src/Functional/Memoize.php b/src/Functional/Memoize.php index e66df8a1..83152c6c 100644 --- a/src/Functional/Memoize.php +++ b/src/Functional/Memoize.php @@ -11,6 +11,7 @@ namespace Functional; use const E_USER_DEPRECATED; + use function array_key_exists; use function is_callable; diff --git a/src/Functional/PartialAny.php b/src/Functional/PartialAny.php index 6a7f14e1..21cba641 100644 --- a/src/Functional/PartialAny.php +++ b/src/Functional/PartialAny.php @@ -11,6 +11,7 @@ namespace Functional; use Functional\Exceptions\InvalidArgumentException; + use function define; /** diff --git a/src/Functional/PartialMethod.php b/src/Functional/PartialMethod.php index b42aea76..f8b46e65 100644 --- a/src/Functional/PartialMethod.php +++ b/src/Functional/PartialMethod.php @@ -11,6 +11,7 @@ namespace Functional; use Functional\Exceptions\InvalidArgumentException; + use function is_callable; /** diff --git a/src/Functional/Partition.php b/src/Functional/Partition.php index 0e05611d..289e558c 100644 --- a/src/Functional/Partition.php +++ b/src/Functional/Partition.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function count; /** diff --git a/src/Functional/Pick.php b/src/Functional/Pick.php index 875dee94..ffbc9188 100644 --- a/src/Functional/Pick.php +++ b/src/Functional/Pick.php @@ -12,6 +12,7 @@ use ArrayAccess; use Functional\Exceptions\InvalidArgumentException; + use function array_key_exists; use function is_array; diff --git a/src/Functional/Pluck.php b/src/Functional/Pluck.php index 31c5962b..ba203bad 100644 --- a/src/Functional/Pluck.php +++ b/src/Functional/Pluck.php @@ -13,6 +13,7 @@ use ArrayAccess; use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_array; use function is_object; diff --git a/src/Functional/TakeLeft.php b/src/Functional/TakeLeft.php index 88910c50..0143eb2e 100644 --- a/src/Functional/TakeLeft.php +++ b/src/Functional/TakeLeft.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function array_slice; use function is_array; diff --git a/src/Functional/TakeRight.php b/src/Functional/TakeRight.php index fc5bd806..0e2a1bc2 100644 --- a/src/Functional/TakeRight.php +++ b/src/Functional/TakeRight.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function array_slice; use function is_array; diff --git a/src/Functional/Unique.php b/src/Functional/Unique.php index 802574cc..f2a67e97 100644 --- a/src/Functional/Unique.php +++ b/src/Functional/Unique.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function in_array; /** diff --git a/src/Functional/ValueToKey.php b/src/Functional/ValueToKey.php index 94371102..4c58eab2 100644 --- a/src/Functional/ValueToKey.php +++ b/src/Functional/ValueToKey.php @@ -13,6 +13,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; use WeakReference; + use function get_class; use function gettype; diff --git a/src/Functional/With.php b/src/Functional/With.php index fadaf34d..2ab40dfe 100644 --- a/src/Functional/With.php +++ b/src/Functional/With.php @@ -11,6 +11,7 @@ namespace Functional; use Functional\Exceptions\InvalidArgumentException; + use function is_callable; /** diff --git a/src/Functional/Zip.php b/src/Functional/Zip.php index ed2a1f46..c5769e8b 100644 --- a/src/Functional/Zip.php +++ b/src/Functional/Zip.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_callable; /** diff --git a/src/Functional/ZipAll.php b/src/Functional/ZipAll.php index 01260e94..526a97be 100644 --- a/src/Functional/ZipAll.php +++ b/src/Functional/ZipAll.php @@ -12,6 +12,7 @@ use Functional\Exceptions\InvalidArgumentException; use Traversable; + use function is_callable; /** diff --git a/tests/Functional/AbstractTestCase.php b/tests/Functional/AbstractTestCase.php index 50e6e2ef..0b33c572 100644 --- a/tests/Functional/AbstractTestCase.php +++ b/tests/Functional/AbstractTestCase.php @@ -17,6 +17,7 @@ use PHPUnit\Framework\TestCase; use Traversable; use TypeError; + use function count; use function func_get_args; use function func_num_args; diff --git a/tests/Functional/GroupTest.php b/tests/Functional/GroupTest.php index 1c1b5b89..2a604826 100644 --- a/tests/Functional/GroupTest.php +++ b/tests/Functional/GroupTest.php @@ -14,8 +14,10 @@ use Functional\Exceptions\InvalidArgumentException; use function Functional\group; + use Exception; use stdClass; + use function is_int; class GroupTest extends AbstractTestCase diff --git a/tests/Functional/InvokeFirstTest.php b/tests/Functional/InvokeFirstTest.php index c0f0b354..27aa3957 100644 --- a/tests/Functional/InvokeFirstTest.php +++ b/tests/Functional/InvokeFirstTest.php @@ -14,7 +14,9 @@ use Traversable; use function Functional\invoke_first; + use stdClass; + use function func_get_args; class InvokeFirstTest extends AbstractTestCase diff --git a/tests/Functional/InvokeIfTest.php b/tests/Functional/InvokeIfTest.php index 31fab362..b358ce6a 100644 --- a/tests/Functional/InvokeIfTest.php +++ b/tests/Functional/InvokeIfTest.php @@ -11,7 +11,9 @@ namespace Functional\Tests; use function Functional\invoke_if; + use stdClass; + use function func_get_args; class InvokeIfTest extends AbstractTestCase diff --git a/tests/Functional/InvokeLastTest.php b/tests/Functional/InvokeLastTest.php index a84132f7..872a9c8d 100644 --- a/tests/Functional/InvokeLastTest.php +++ b/tests/Functional/InvokeLastTest.php @@ -13,7 +13,9 @@ use ArrayIterator; use function Functional\invoke_last; + use stdClass; + use function func_get_args; class InvokeLastTest extends AbstractTestCase diff --git a/tests/Functional/InvokeTest.php b/tests/Functional/InvokeTest.php index 6e646d50..2d9be826 100644 --- a/tests/Functional/InvokeTest.php +++ b/tests/Functional/InvokeTest.php @@ -14,7 +14,9 @@ use Traversable; use function Functional\invoke; + use stdClass; + use function func_get_args; class InvokeTest extends AbstractTestCase diff --git a/tests/Functional/OmitKeysTest.php b/tests/Functional/OmitKeysTest.php index b8ea5eef..df97f08d 100644 --- a/tests/Functional/OmitKeysTest.php +++ b/tests/Functional/OmitKeysTest.php @@ -13,6 +13,7 @@ use ArrayIterator; use function Functional\omit_keys; + use stdclass; class OmitKeysTest extends AbstractTestCase diff --git a/tests/Functional/PartialAnyTest.php b/tests/Functional/PartialAnyTest.php index e2a6ffa3..dca62178 100644 --- a/tests/Functional/PartialAnyTest.php +++ b/tests/Functional/PartialAnyTest.php @@ -17,6 +17,7 @@ use function Functional\…; use const Functional\…; + use function defined; class PartialAnyTest extends AbstractPartialTestCase diff --git a/tests/Functional/PartialMethodTest.php b/tests/Functional/PartialMethodTest.php index 2417ed90..e52946b1 100644 --- a/tests/Functional/PartialMethodTest.php +++ b/tests/Functional/PartialMethodTest.php @@ -14,7 +14,6 @@ class PartialMethodTest extends AbstractPartialTestCase { - public function testWithNoArgs(): void { $method = partial_method('execute'); diff --git a/tests/Functional/PluckTest.php b/tests/Functional/PluckTest.php index 5e9b0ccc..fde17a26 100644 --- a/tests/Functional/PluckTest.php +++ b/tests/Functional/PluckTest.php @@ -16,6 +16,7 @@ use Traversable; use function Functional\pluck; + use DomainException; use Exception; use stdClass; diff --git a/tests/Functional/SelectKeysTest.php b/tests/Functional/SelectKeysTest.php index ae1ac4b1..6d5b7eb3 100644 --- a/tests/Functional/SelectKeysTest.php +++ b/tests/Functional/SelectKeysTest.php @@ -13,6 +13,7 @@ use ArrayIterator; use function Functional\select_keys; + use stdclass; class SelectKeysTest extends AbstractTestCase diff --git a/tests/Functional/TapTest.php b/tests/Functional/TapTest.php index c05bc639..08f33a83 100644 --- a/tests/Functional/TapTest.php +++ b/tests/Functional/TapTest.php @@ -11,6 +11,7 @@ namespace Functional\Tests; use function Functional\tap; + use stdClass; class TapTest extends AbstractTestCase diff --git a/tests/Functional/WithTest.php b/tests/Functional/WithTest.php index 6484c950..13dfaacd 100644 --- a/tests/Functional/WithTest.php +++ b/tests/Functional/WithTest.php @@ -11,6 +11,7 @@ namespace Functional\Tests; use function Functional\with; + use Exception; class WithTest extends AbstractTestCase diff --git a/tests/Functional/ZipAllTest.php b/tests/Functional/ZipAllTest.php index cd3f2395..72cc059b 100644 --- a/tests/Functional/ZipAllTest.php +++ b/tests/Functional/ZipAllTest.php @@ -13,6 +13,7 @@ use BadFunctionCallException; use function Functional\zip_all; + use ArrayIterator; class ZipAllTest extends AbstractTestCase From a3f971dbd8cbff825af030974ebca35939499171 Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:45:04 +0100 Subject: [PATCH 10/11] ci(php-cs-fixer): use proper config --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index d12bae3f..7a9d967e 100644 --- a/composer.json +++ b/composer.json @@ -133,7 +133,7 @@ }, "scripts": { "tests": "vendor/bin/phpunit", - "coding-style": "vendor/bin/phpcs && vendor/bin/php-cs-fixer fix --dry-run --diff --config=.php_cs.dist", + "coding-style": "vendor/bin/phpcs && vendor/bin/php-cs-fixer fix --dry-run --diff", "clear": "rm -rf vendor/" } } From 9db7aa4b1ecf4e79233dbd66f27e31fcfa4dbc2b Mon Sep 17 00:00:00 2001 From: Simon Podlipsky Date: Fri, 9 Feb 2024 13:52:32 +0100 Subject: [PATCH 11/11] style: fix cs vol.3 --- src/Functional/Memoize.php | 4 ++-- tests/Functional/GroupTest.php | 4 +--- tests/Functional/InvokeFirstTest.php | 4 +--- tests/Functional/InvokeIfTest.php | 3 +-- tests/Functional/InvokeLastTest.php | 4 +--- tests/Functional/InvokeTest.php | 4 +--- tests/Functional/OmitKeysTest.php | 3 +-- tests/Functional/PartialAnyTest.php | 8 ++++---- tests/Functional/PluckTest.php | 5 ++--- tests/Functional/SelectKeysTest.php | 3 +-- tests/Functional/TapTest.php | 4 ++-- tests/Functional/WithTest.php | 4 ++-- tests/Functional/ZipAllTest.php | 3 +-- 13 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/Functional/Memoize.php b/src/Functional/Memoize.php index 83152c6c..bef8416f 100644 --- a/src/Functional/Memoize.php +++ b/src/Functional/Memoize.php @@ -10,11 +10,11 @@ namespace Functional; -use const E_USER_DEPRECATED; - use function array_key_exists; use function is_callable; +use const E_USER_DEPRECATED; + /** * Memoizes callbacks and returns their value instead of calling them * diff --git a/tests/Functional/GroupTest.php b/tests/Functional/GroupTest.php index 2a604826..d0c78d97 100644 --- a/tests/Functional/GroupTest.php +++ b/tests/Functional/GroupTest.php @@ -12,12 +12,10 @@ use ArrayIterator; use Functional\Exceptions\InvalidArgumentException; - -use function Functional\group; - use Exception; use stdClass; +use function Functional\group; use function is_int; class GroupTest extends AbstractTestCase diff --git a/tests/Functional/InvokeFirstTest.php b/tests/Functional/InvokeFirstTest.php index 27aa3957..4699037d 100644 --- a/tests/Functional/InvokeFirstTest.php +++ b/tests/Functional/InvokeFirstTest.php @@ -12,11 +12,9 @@ use ArrayIterator; use Traversable; - -use function Functional\invoke_first; - use stdClass; +use function Functional\invoke_first; use function func_get_args; class InvokeFirstTest extends AbstractTestCase diff --git a/tests/Functional/InvokeIfTest.php b/tests/Functional/InvokeIfTest.php index b358ce6a..e1e8d0ef 100644 --- a/tests/Functional/InvokeIfTest.php +++ b/tests/Functional/InvokeIfTest.php @@ -10,10 +10,9 @@ namespace Functional\Tests; -use function Functional\invoke_if; - use stdClass; +use function Functional\invoke_if; use function func_get_args; class InvokeIfTest extends AbstractTestCase diff --git a/tests/Functional/InvokeLastTest.php b/tests/Functional/InvokeLastTest.php index 872a9c8d..665275dc 100644 --- a/tests/Functional/InvokeLastTest.php +++ b/tests/Functional/InvokeLastTest.php @@ -11,11 +11,9 @@ namespace Functional\Tests; use ArrayIterator; - -use function Functional\invoke_last; - use stdClass; +use function Functional\invoke_last; use function func_get_args; class InvokeLastTest extends AbstractTestCase diff --git a/tests/Functional/InvokeTest.php b/tests/Functional/InvokeTest.php index 2d9be826..c42bebd1 100644 --- a/tests/Functional/InvokeTest.php +++ b/tests/Functional/InvokeTest.php @@ -12,11 +12,9 @@ use ArrayIterator; use Traversable; - -use function Functional\invoke; - use stdClass; +use function Functional\invoke; use function func_get_args; class InvokeTest extends AbstractTestCase diff --git a/tests/Functional/OmitKeysTest.php b/tests/Functional/OmitKeysTest.php index df97f08d..54d3471f 100644 --- a/tests/Functional/OmitKeysTest.php +++ b/tests/Functional/OmitKeysTest.php @@ -11,11 +11,10 @@ namespace Functional\Tests; use ArrayIterator; +use stdclass; use function Functional\omit_keys; -use stdclass; - class OmitKeysTest extends AbstractTestCase { public static function getData(): array diff --git a/tests/Functional/PartialAnyTest.php b/tests/Functional/PartialAnyTest.php index dca62178..ba0cb797 100644 --- a/tests/Functional/PartialAnyTest.php +++ b/tests/Functional/PartialAnyTest.php @@ -12,13 +12,13 @@ use Functional\Exceptions\InvalidArgumentException; -use function Functional\partial_any; -use function Functional\placeholder; -use function Functional\…; - use const Functional\…; +// phpcs:ignore PSR12.Files.FileHeader.IncorrectOrder use function defined; +use function Functional\partial_any; +use function Functional\placeholder; +use function Functional\…; class PartialAnyTest extends AbstractPartialTestCase { diff --git a/tests/Functional/PluckTest.php b/tests/Functional/PluckTest.php index fde17a26..c455ad8c 100644 --- a/tests/Functional/PluckTest.php +++ b/tests/Functional/PluckTest.php @@ -14,13 +14,12 @@ use ArrayObject; use SplFixedArray; use Traversable; - -use function Functional\pluck; - use DomainException; use Exception; use stdClass; +use function Functional\pluck; + class MagicGetThrowException { public function __get($propertyName) diff --git a/tests/Functional/SelectKeysTest.php b/tests/Functional/SelectKeysTest.php index 6d5b7eb3..5029ccf2 100644 --- a/tests/Functional/SelectKeysTest.php +++ b/tests/Functional/SelectKeysTest.php @@ -11,11 +11,10 @@ namespace Functional\Tests; use ArrayIterator; +use stdclass; use function Functional\select_keys; -use stdclass; - class SelectKeysTest extends AbstractTestCase { public static function getData(): array diff --git a/tests/Functional/TapTest.php b/tests/Functional/TapTest.php index 08f33a83..3eefb7fd 100644 --- a/tests/Functional/TapTest.php +++ b/tests/Functional/TapTest.php @@ -10,10 +10,10 @@ namespace Functional\Tests; -use function Functional\tap; - use stdClass; +use function Functional\tap; + class TapTest extends AbstractTestCase { protected function setUp(): void diff --git a/tests/Functional/WithTest.php b/tests/Functional/WithTest.php index 13dfaacd..cb3ff3e6 100644 --- a/tests/Functional/WithTest.php +++ b/tests/Functional/WithTest.php @@ -10,10 +10,10 @@ namespace Functional\Tests; -use function Functional\with; - use Exception; +use function Functional\with; + class WithTest extends AbstractTestCase { public function testWithNull(): void diff --git a/tests/Functional/ZipAllTest.php b/tests/Functional/ZipAllTest.php index 72cc059b..5e0a2e3c 100644 --- a/tests/Functional/ZipAllTest.php +++ b/tests/Functional/ZipAllTest.php @@ -11,11 +11,10 @@ namespace Functional\Tests; use BadFunctionCallException; +use ArrayIterator; use function Functional\zip_all; -use ArrayIterator; - class ZipAllTest extends AbstractTestCase { public function testEmpty(): void