diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml
index 2c581fd1..228ec9ef 100644
--- a/.github/workflows/test.yaml
+++ b/.github/workflows/test.yaml
@@ -4,25 +4,18 @@ 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
+ runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
php-version:
- - 7.1
- - 7.2
- - 7.3
- - 7.4
- - 8.0
- experimental: [false]
- include:
- - php-version: 8.1
- experimental: true
-
- continue-on-error: ${{ matrix.experimental }}
+ - 8.1
+ - 8.2
+ - 8.3
+
steps:
- name: Checkout
uses: actions/checkout@v2
@@ -38,18 +31,9 @@ jobs:
uses: ramsey/composer-install@v1
with:
composer-options: --prefer-dist
- continue-on-error: ${{ matrix.experimental }}
-
- - name: Setup PCOV
- run: |
- composer require pcov/clobber
- vendor/bin/pcov clobber
- continue-on-error: true
- name: Run Tests
run: composer tests
- continue-on-error: ${{ matrix.experimental }}
- name: Check coding style
run: composer coding-style
- continue-on-error: ${{ matrix.experimental }}
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-fixer.dist.php b/.php-cs-fixer.dist.php
new file mode 100644
index 00000000..ae0f0c21
--- /dev/null
+++ b/.php-cs-fixer.dist.php
@@ -0,0 +1,11 @@
+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/.php_cs.dist b/.php_cs.dist
deleted file mode 100644
index 4238d7e8..00000000
--- a/.php_cs.dist
+++ /dev/null
@@ -1,8 +0,0 @@
-setRiskyAllowed(true)
- ->setRules([
- 'native_function_invocation' => true,
- ])
- ->setFinder(PhpCsFixer\Finder::create()->in(__DIR__));
diff --git a/composer.json b/composer.json
index ebfe9738..7a9d967e 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": {
@@ -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/"
}
}
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/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..8d7c0655 100644
--- a/src/Functional/ButLast.php
+++ b/src/Functional/ButLast.php
@@ -13,6 +13,8 @@
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 +26,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..8f81ea6a 100644
--- a/src/Functional/Curry.php
+++ b/src/Functional/Curry.php
@@ -14,6 +14,11 @@
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
* want to curry optional parameters or not.
@@ -25,15 +30,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..73113b2f 100644
--- a/src/Functional/CurryN.php
+++ b/src/Functional/CurryN.php
@@ -10,6 +10,9 @@
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 +29,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..be541a06 100644
--- a/src/Functional/Exceptions/InvalidArgumentException.php
+++ b/src/Functional/Exceptions/InvalidArgumentException.php
@@ -10,6 +10,19 @@
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 +34,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 +45,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 +66,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 +90,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 +111,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 +134,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 +153,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 +172,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 +189,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 +209,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 +230,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 +251,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 +265,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 +281,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 +296,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..6c75b534 100644
--- a/src/Functional/Exceptions/MatchException.php
+++ b/src/Functional/Exceptions/MatchException.php
@@ -10,6 +10,11 @@
namespace Functional\Exceptions;
+use function count;
+use function gettype;
+use function is_array;
+use function is_callable;
+
/** @internal */
class MatchException extends InvalidArgumentException
{
@@ -24,13 +29,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 +43,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 +57,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..ad397b46 100644
--- a/src/Functional/FirstIndexOf.php
+++ b/src/Functional/FirstIndexOf.php
@@ -13,6 +13,8 @@
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 +27,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..8e8b265a 100644
--- a/src/Functional/FlatMap.php
+++ b/src/Functional/FlatMap.php
@@ -13,6 +13,8 @@
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,
* and flattening the results into the resulting array.
@@ -38,7 +40,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..7fd57472 100644
--- a/src/Functional/Flatten.php
+++ b/src/Functional/Flatten.php
@@ -13,6 +13,8 @@
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.
* Does not preserve indexes.
@@ -29,14 +31,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..92dcd026 100644
--- a/src/Functional/Flip.php
+++ b/src/Functional/Flip.php
@@ -10,6 +10,8 @@
namespace Functional;
+use function func_get_args;
+
/**
* Return a version of the given function where the arguments are provided in reverse order.
*
@@ -22,6 +24,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/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 f3c84583..3d682d90 100644
--- a/src/Functional/GreaterThan.php
+++ b/src/Functional/GreaterThan.php
@@ -10,11 +10,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..d17b0654 100644
--- a/src/Functional/GreaterThanOrEqual.php
+++ b/src/Functional/GreaterThanOrEqual.php
@@ -10,11 +10,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/Group.php b/src/Functional/Group.php
index af2ed3a1..c7ca6202 100644
--- a/src/Functional/Group.php
+++ b/src/Functional/Group.php
@@ -13,6 +13,8 @@
use Functional\Exceptions\InvalidArgumentException;
use Traversable;
+use function is_float;
+
/**
* Groups a collection by index returned by callback.
*
@@ -32,6 +34,7 @@ function group($collection, callable $callback)
InvalidArgumentException::assertValidArrayKey($groupKey, __FUNCTION__);
+ $groupKey = is_float($groupKey) ? (int) $groupKey : $groupKey;
if (!isset($groups[$groupKey])) {
$groups[$groupKey] = [];
}
diff --git a/src/Functional/IndexesOf.php b/src/Functional/IndexesOf.php
index 3045df6b..afadaf84 100644
--- a/src/Functional/IndexesOf.php
+++ b/src/Functional/IndexesOf.php
@@ -13,6 +13,8 @@
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
* empty array if no values were found.
@@ -28,7 +30,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..4a10d921 100644
--- a/src/Functional/Invoke.php
+++ b/src/Functional/Invoke.php
@@ -13,6 +13,8 @@
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
* forwarded on to the method invocation.
@@ -34,7 +36,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..f0d0ef5a 100644
--- a/src/Functional/InvokeFirst.php
+++ b/src/Functional/InvokeFirst.php
@@ -13,6 +13,8 @@
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
* $methodName. Any extra arguments passed to invoke will be forwarded on to the method invocation.
@@ -31,7 +33,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..8b6ebd03 100644
--- a/src/Functional/InvokeIf.php
+++ b/src/Functional/InvokeIf.php
@@ -10,6 +10,8 @@
namespace Functional;
+use function is_callable;
+
/**
* Calls the method named by $methodName on $object. Any extra arguments passed to invoke_if will be
* forwarded on to the method invocation. If $method is not callable on $object, $defaultValue is returned.
@@ -24,7 +26,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..4b566eb0 100644
--- a/src/Functional/InvokeLast.php
+++ b/src/Functional/InvokeLast.php
@@ -13,6 +13,8 @@
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
* $methodName. Any extra arguments passed to invoke will be forwarded on to the method invocation.
@@ -32,7 +34,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..561390a6 100644
--- a/src/Functional/LastIndexOf.php
+++ b/src/Functional/LastIndexOf.php
@@ -13,6 +13,8 @@
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 +29,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..5dbf12e7 100644
--- a/src/Functional/LessThan.php
+++ b/src/Functional/LessThan.php
@@ -10,11 +10,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..ba8a5918 100644
--- a/src/Functional/LessThanOrEqual.php
+++ b/src/Functional/LessThanOrEqual.php
@@ -10,11 +10,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..c5c529fa 100644
--- a/src/Functional/LexicographicCompare.php
+++ b/src/Functional/LexicographicCompare.php
@@ -10,12 +10,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/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/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..bef8416f 100644
--- a/src/Functional/Memoize.php
+++ b/src/Functional/Memoize.php
@@ -10,6 +10,9 @@
namespace Functional;
+use function array_key_exists;
+use function is_callable;
+
use const E_USER_DEPRECATED;
/**
@@ -30,21 +33,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..21cba641 100644
--- a/src/Functional/PartialAny.php
+++ b/src/Functional/PartialAny.php
@@ -12,6 +12,8 @@
use Functional\Exceptions\InvalidArgumentException;
+use function define;
+
/**
* Return a new function with the arguments partially applied
*
@@ -30,7 +32,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 +49,7 @@ function …()
static $placeholder;
if (!$placeholder) {
- $placeholder = \random_bytes(32);
+ $placeholder = random_bytes(32);
}
return $placeholder;
@@ -65,5 +67,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..f8b46e65 100644
--- a/src/Functional/PartialMethod.php
+++ b/src/Functional/PartialMethod.php
@@ -12,6 +12,8 @@
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 +28,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..289e558c 100644
--- a/src/Functional/Partition.php
+++ b/src/Functional/Partition.php
@@ -13,6 +13,8 @@
use Functional\Exceptions\InvalidArgumentException;
use Traversable;
+use function count;
+
/**
* Partitions a collection by callback predicate results. Returns an
* array of partition arrays, one for each predicate, and one for
@@ -32,7 +34,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..ffbc9188 100644
--- a/src/Functional/Pick.php
+++ b/src/Functional/Pick.php
@@ -13,6 +13,9 @@
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.
* If no such index exists, return the default value.
@@ -29,7 +32,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..ba203bad 100644
--- a/src/Functional/Pluck.php
+++ b/src/Functional/Pluck.php
@@ -14,6 +14,9 @@
use Functional\Exceptions\InvalidArgumentException;
use Traversable;
+use function is_array;
+use function is_object;
+
/**
* Extract a property from a collection of objects.
*
@@ -32,9 +35,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..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->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;
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;
}
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..0143eb2e 100644
--- a/src/Functional/TakeLeft.php
+++ b/src/Functional/TakeLeft.php
@@ -13,6 +13,9 @@
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
* elements, the whole collection will be returned as an array.
@@ -28,8 +31,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..0e2a1bc2 100644
--- a/src/Functional/TakeRight.php
+++ b/src/Functional/TakeRight.php
@@ -13,6 +13,9 @@
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
* elements, the whole collection will be returned as an array.
@@ -31,8 +34,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..f2a67e97 100644
--- a/src/Functional/Unique.php
+++ b/src/Functional/Unique.php
@@ -13,6 +13,8 @@
use Functional\Exceptions\InvalidArgumentException;
use Traversable;
+use function in_array;
+
/**
* Returns an array of unique elements
*
@@ -35,7 +37,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 345723f7..4c58eab2 100644
--- a/src/Functional/ValueToKey.php
+++ b/src/Functional/ValueToKey.php
@@ -14,9 +14,8 @@
use Traversable;
use WeakReference;
-use function serialize;
-
-use const PHP_VERSION_ID;
+use function get_class;
+use function gettype;
/**
* @no-named-arguments
@@ -29,38 +28,25 @@ 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.
*/
- 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;
};
}
@@ -68,11 +54,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') {
@@ -80,7 +66,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..2ab40dfe 100644
--- a/src/Functional/With.php
+++ b/src/Functional/With.php
@@ -12,6 +12,8 @@
use Functional\Exceptions\InvalidArgumentException;
+use function is_callable;
+
/**
* Invoke a callback on a value if the value is not null
*
@@ -30,8 +32,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..c5769e8b 100644
--- a/src/Functional/Zip.php
+++ b/src/Functional/Zip.php
@@ -13,6 +13,8 @@
use Functional\Exceptions\InvalidArgumentException;
use Traversable;
+use function is_callable;
+
/**
* Recombines arrays by index and applies a callback optionally
*
@@ -23,8 +25,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 +34,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..526a97be 100644
--- a/src/Functional/ZipAll.php
+++ b/src/Functional/ZipAll.php
@@ -13,6 +13,8 @@
use Functional\Exceptions\InvalidArgumentException;
use Traversable;
+use function is_callable;
+
/**
* Recombines arrays by index (column) and applies a callback optionally
*
@@ -27,8 +29,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 +44,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 30657653..0b33c572 100644
--- a/tests/Functional/AbstractTestCase.php
+++ b/tests/Functional/AbstractTestCase.php
@@ -18,6 +18,10 @@
use Traversable;
use TypeError;
+use function count;
+use function func_get_args;
+use function func_num_args;
+
class AbstractTestCase extends TestCase
{
/** @var array */
@@ -42,29 +46,25 @@ 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
{
- 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
@@ -81,7 +81,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;
}
@@ -91,7 +91,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..d0c78d97 100644
--- a/tests/Functional/GroupTest.php
+++ b/tests/Functional/GroupTest.php
@@ -12,8 +12,11 @@
use ArrayIterator;
use Functional\Exceptions\InvalidArgumentException;
+use Exception;
+use stdClass;
use function Functional\group;
+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..4699037d 100644
--- a/tests/Functional/InvokeFirstTest.php
+++ b/tests/Functional/InvokeFirstTest.php
@@ -12,8 +12,10 @@
use ArrayIterator;
use Traversable;
+use stdClass;
use function Functional\invoke_first;
+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..e1e8d0ef 100644
--- a/tests/Functional/InvokeIfTest.php
+++ b/tests/Functional/InvokeIfTest.php
@@ -10,7 +10,10 @@
namespace Functional\Tests;
+use stdClass;
+
use function Functional\invoke_if;
+use function func_get_args;
class InvokeIfTest extends AbstractTestCase
{
@@ -27,7 +30,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 +43,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..665275dc 100644
--- a/tests/Functional/InvokeLastTest.php
+++ b/tests/Functional/InvokeLastTest.php
@@ -11,8 +11,10 @@
namespace Functional\Tests;
use ArrayIterator;
+use stdClass;
use function Functional\invoke_last;
+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..c42bebd1 100644
--- a/tests/Functional/InvokeTest.php
+++ b/tests/Functional/InvokeTest.php
@@ -12,8 +12,10 @@
use ArrayIterator;
use Traversable;
+use stdClass;
use function Functional\invoke;
+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/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/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..54d3471f 100644
--- a/tests/Functional/OmitKeysTest.php
+++ b/tests/Functional/OmitKeysTest.php
@@ -11,6 +11,7 @@
namespace Functional\Tests;
use ArrayIterator;
+use stdclass;
use function Functional\omit_keys;
@@ -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..ba0cb797 100644
--- a/tests/Functional/PartialAnyTest.php
+++ b/tests/Functional/PartialAnyTest.php
@@ -12,12 +12,14 @@
use Functional\Exceptions\InvalidArgumentException;
+use const Functional\…;
+
+// phpcs:ignore PSR12.Files.FileHeader.IncorrectOrder
+use function defined;
use function Functional\partial_any;
use function Functional\placeholder;
use function Functional\…;
-use const Functional\…;
-
class PartialAnyTest extends AbstractPartialTestCase
{
public function testBindWithPlaceholder(): void
@@ -29,10 +31,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 +63,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/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/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..c455ad8c 100644
--- a/tests/Functional/PluckTest.php
+++ b/tests/Functional/PluckTest.php
@@ -14,6 +14,9 @@
use ArrayObject;
use SplFixedArray;
use Traversable;
+use DomainException;
+use Exception;
+use stdClass;
use function Functional\pluck;
@@ -21,7 +24,7 @@ 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..5029ccf2 100644
--- a/tests/Functional/SelectKeysTest.php
+++ b/tests/Functional/SelectKeysTest.php
@@ -11,6 +11,7 @@
namespace Functional\Tests;
use ArrayIterator;
+use stdclass;
use function Functional\select_keys;
@@ -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..3eefb7fd 100644
--- a/tests/Functional/TapTest.php
+++ b/tests/Functional/TapTest.php
@@ -10,6 +10,8 @@
namespace Functional\Tests;
+use stdClass;
+
use function Functional\tap;
class TapTest extends AbstractTestCase
@@ -27,7 +29,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 ef4ce0da..d46c78a5 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
{
@@ -29,7 +28,7 @@ class ValueToKeyTest extends AbstractTestCase
public static function getSimpleTypeExpectations(): array
{
- $binary = \random_bytes(10);
+ $binary = random_bytes(10);
return [
'Nothing' => [[], '[]'],
@@ -76,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);
@@ -89,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()])],
];
}
@@ -111,22 +110,18 @@ 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'
);
- 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
@@ -137,26 +132,22 @@ 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'
);
- 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
{
- 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..cb3ff3e6 100644
--- a/tests/Functional/WithTest.php
+++ b/tests/Functional/WithTest.php
@@ -10,6 +10,8 @@
namespace Functional\Tests;
+use Exception;
+
use function Functional\with;
class WithTest extends AbstractTestCase
@@ -18,7 +20,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..5e0a2e3c 100644
--- a/tests/Functional/ZipAllTest.php
+++ b/tests/Functional/ZipAllTest.php
@@ -11,6 +11,7 @@
namespace Functional\Tests;
use BadFunctionCallException;
+use ArrayIterator;
use function Functional\zip_all;
@@ -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],