Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: drop support for EOLed php #251

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 6 additions & 22 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build/
vendor/
.php_cs.cache
.php-cs-fixer.cache
composer.lock
phpcs.xml
phpunit.xml
Expand Down
11 changes: 11 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

use PhpCsFixer\Config;

return (new Config())
->setRiskyAllowed(true)
->setRules([
'global_namespace_import' => ['import_classes' => true, 'import_constants' => true, 'import_functions' => true],
'native_function_invocation' => true,
])
->setFinder(PhpCsFixer\Finder::create()->in(__DIR__));
8 changes: 0 additions & 8 deletions .php_cs.dist

This file was deleted.

8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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/"
}
}
2 changes: 2 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
<arg name="colors" />
<arg value="n" />

<config name="php_version" value="80100"/>

<rule ref="PSR12" />

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Average.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function average($collection)
$divisor = 0;

foreach ($collection as $element) {
if (\is_numeric($element)) {
if (is_numeric($element)) {
$sum += $element;
++$divisor;
}
Expand Down
6 changes: 4 additions & 2 deletions src/Functional/ButLast.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}
2 changes: 1 addition & 1 deletion src/Functional/Compose.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
*/
function compose(...$functions)
{
return \array_reduce(
return array_reduce(
$functions,
function ($carry, $item) {
return function ($x) use ($carry, $item) {
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Concat.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
*/
function concat(string ...$strings)
{
return \implode('', $strings);
return implode('', $strings);
}
13 changes: 9 additions & 4 deletions src/Functional/Curry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
Expand Down
9 changes: 6 additions & 3 deletions src/Functional/CurryN.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Functional/Difference.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Functional/ErrorToException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ 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);
}
);

return $callback(...$arguments);
} finally {
\restore_error_handler();
restore_error_handler();
}
};
}
Loading