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

PHP 8 Compatibility #104

Merged
merged 11 commits into from
Jun 6, 2021
Merged
Show file tree
Hide file tree
Changes from 5 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
8 changes: 8 additions & 0 deletions .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,21 @@ branches:
strict: true
contexts:
- "Static Analysis (ubuntu-latest, 7.4)"
- "Static Analysis (ubuntu-latest, 8.0)"
- "Static Analysis (windows-latest, 7.4)"
- "Static Analysis (windows-latest, 8.0)"
AlexandruGG marked this conversation as resolved.
Show resolved Hide resolved
- "Static Analysis (macOS-latest, 7.4)"
- "Static Analysis (macOS-latest, 8.0)"
- "Unit Tests (ubuntu-latest, 7.4)"
- "Unit Tests (ubuntu-latest, 8.0)"
- "Unit Tests (windows-latest, 7.4)"
- "Unit Tests (windows-latest, 8.0)"
- "Unit Tests (macOS-latest, 7.4)"
- "Unit Tests (macOS-latest, 8.0)"
- "Mutation Testing (ubuntu-latest, 7.4)"
- "Mutation Testing (ubuntu-latest, 8.0)"
- "Code Style (ubuntu-latest, 7.4)"
- "Code Style (ubuntu-latest, 8.0)"

restrictions: null
required_linear_history: true
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4']
php-versions: ['7.4', '8.0']

steps:
- name: Set git to use LF
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mutation-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest]
php-versions: ['7.4']
php-versions: ['7.4', '8.0']

steps:
- name: Set git to use LF
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.4']
php-versions: ['7.4', '8.0']

steps:
- name: Set git to use LF
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
operating-system: [ubuntu-latest, windows-latest, macOS-latest]
php-versions: ['7.4']
php-versions: ['7.4', '8.0']

steps:
- name: Set git to use LF
Expand Down
9 changes: 8 additions & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
build:
nodes:
analysis:
php74:
environment:
php:
version: 7.4
tests:
override:
- php-scrutinizer-run
php80:
environment:
php:
version: 8.0
tests:
override:
- php-scrutinizer-run
drupol marked this conversation as resolved.
Show resolved Hide resolved

filter:
paths:
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": ">= 7.4"
"php": "^7.4 || ^8.0"
AlexandruGG marked this conversation as resolved.
Show resolved Hide resolved
},
"require-dev": {
"amphp/parallel-functions": "^1",
Expand Down
5 changes: 0 additions & 5 deletions phpstan-docs-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,3 @@ parameters:
message: "#^Unable to resolve the template type NewTKey in call to method static method loophp\\\\collection\\\\Collection\\<mixed,mixed\\>\\:\\:fromIterable\\(\\)$#"
count: 1
path: docs/pages/code/parse-git-log.php

-
message: "#^Parameter \\#1 \\$str of function mb_strtolower expects string, int given\\.$#"
count: 1
path: docs/pages/code/simple.php
19 changes: 16 additions & 3 deletions spec/loophp/collection/CollectionSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use ArrayIterator;
use ArrayObject;
use Closure;
use Error;
use Exception;
use Generator;
use InvalidArgumentException;
Expand All @@ -27,9 +28,12 @@
use stdClass;
use const INF;
use const PHP_EOL;
use const PHP_VERSION_ID;

class CollectionSpec extends ObjectBehavior
{
private const PHP_VERSION_8 = 80000;

public function it_can_append(): void
{
$generator = static function (): Generator {
Expand Down Expand Up @@ -226,9 +230,18 @@ public function it_can_asyncMap(): void
return $v * 2;
};

$this::fromIterable(['c' => 3, 'b' => 2, 'a' => 1])
->asyncMap($callback1, $callback2)
->shouldIterateAs(['a' => 2, 'b' => 4, 'c' => 6]);
$this->beConstructedThrough('fromIterable', [['c' => 3, 'b' => 2, 'a' => 1]]);

if (PHP_VERSION_ID >= self::PHP_VERSION_8) {
$this
->asyncMap($callback1, $callback2)
->shouldThrow(Error::class)
->during('all');
} else {
$this
drupol marked this conversation as resolved.
Show resolved Hide resolved
->asyncMap($callback1, $callback2)
->shouldIterateAs(['a' => 2, 'b' => 4, 'c' => 6]);
}
}

public function it_can_be_constructed_from_a_file(): void
Expand Down
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,9 @@ public function append(...$items): CollectionInterface
return new self(Append::of()(...$items), $this->getIterator());
}

public function apply(callable ...$callables): CollectionInterface
public function apply(callable ...$callbacks): CollectionInterface
AlexandruGG marked this conversation as resolved.
Show resolved Hide resolved
{
return new self(Apply::of()(...$callables), $this->getIterator());
return new self(Apply::of()(...$callbacks), $this->getIterator());
}

public function associate(
Expand Down
7 changes: 4 additions & 3 deletions src/Contract/Operation/Applyable.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace loophp\collection\Contract\Operation;

use Iterator;
use loophp\collection\Contract\Collection;

/**
Expand All @@ -20,9 +21,9 @@ interface Applyable
/**
* Execute a callback for each element of the collection.
*
* @param callable(TKey, T):bool ...$callables
* @param callable(T, TKey, Iterator<TKey, T>): bool ...$callbacks
drupol marked this conversation as resolved.
Show resolved Hide resolved
*
* @return \loophp\collection\Collection<TKey, T>
* @return Collection<TKey, T>
*/
public function apply(callable ...$callables): Collection;
public function apply(callable ...$callbacks): Collection;
}
2 changes: 1 addition & 1 deletion src/Operation/Apply.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __invoke(): Closure
{
return
/**
* @param callable(T, TKey, Iterator<TKey, T>):bool ...$callbacks
* @param callable(T, TKey, Iterator<TKey, T>): bool ...$callbacks
*
* @return Closure(Iterator<TKey, T>): Generator<TKey, T>
*/
Expand Down