Skip to content

Commit

Permalink
Merge pull request #1 from camille-hdl/feature/php81
Browse files Browse the repository at this point in the history
PHP 8.1 and migrate CI to github actions
  • Loading branch information
camille-hdl committed Jul 19, 2023
2 parents 141e391 + 40ef6db commit bae8e78
Show file tree
Hide file tree
Showing 38 changed files with 277 additions and 321 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Tests

on:
push:
branches: [ master ]
tags:
- '!*' # Do not execute on tags
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [8.1]

steps:
- uses: actions/checkout@v3
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '${{ matrix.php-versions }}'
extensions: dom, curl, libxml, mbstring, zip, pcntl, bcmath, intl, iconv
coverage: xdebug
tools: 'cs2pr, php-cs-fixer, phpstan, phpunit'

- name: Create build dir
run: mkdir -p build/logs

- name: Run composer install
run: composer install -n --prefer-dist --no-progress --no-suggest

- name: Run tests
id: run-tests
run: composer run test-ci

- name: Upload coverage results to Coveralls
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php-coveralls --coverage_clover=build/logs/clover.xml -v
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.phpunit.result.cache
.phpunit.cache
/build/
/composer.lock
/phpunit.xml
Expand Down
30 changes: 0 additions & 30 deletions .travis.yml

This file was deleted.

31 changes: 16 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "camille\u002Dhdl\/lazy\u002Dlists",
"description": "Lazy list processing helpers",
"description": "Lazy list processing and transducers",
"type": "library",
"keywords": ["filter", "map", "reduce", "lazy", "iteration", "array", "iterator", "transducers"],
"homepage": "https://github.com/camille\u002Dhdl/lazy\u002Dlists",
"license": "MIT",
"authors": [
{
"name": "Camille\u0020Hodoul",
"email": "camille.hodoul\u0040gmail.com",
"email": "camilleh\u0040hey.com",
"homepage": "https\u003A\/\/camillehdl.dev"
}
],
Expand All @@ -19,16 +19,7 @@
"source": "https://github.com/camille\u002Dhdl/lazy\u002Dlists.git"
},
"require": {
"php": "^7.2"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "^1",
"mockery/mockery": "^1",
"phpbench/phpbench": "^0.17.1",
"phpstan/phpstan": "^0.11",
"phpstan/phpstan-mockery": "^0.11",
"phpunit/phpunit": "^8",
"squizlabs/php_codesniffer": "^3"
"php": "^8.1"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -65,9 +56,10 @@
"phpbench run benchmarks/PipeFilterMapReduceBench.php --report=aggregate",
"phpbench run benchmarks/PipeMapFilterTakeBench.php --report=aggregate"
],
"phpunit": "phpunit --verbose --colors=always",
"phpunit-ci": "phpunit --verbose --coverage-clover build/logs/clover.xml",
"phpunit-coverage": "phpunit --verbose --colors=always --coverage-html build/coverage",
"phpunit": "phpunit --colors=always",
"phpunit-migrate": "phpunit --migrate-configuration",
"phpunit-ci": "phpunit --coverage-clover build/logs/clover.xml",
"phpunit-coverage": "phpunit --colors=always --coverage-html build/coverage",
"test": [
"@lint",
"@phpcs",
Expand All @@ -83,5 +75,14 @@
},
"config": {
"sort-packages": true
},
"require-dev": {
"mockery/mockery": "^1.6",
"php-parallel-lint/php-parallel-lint": "^1.3",
"phpbench/phpbench": "^1.2",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan-mockery": "^1.1",
"phpunit/phpunit": "^10.2",
"squizlabs/php_codesniffer": "^3.7"
}
}
2 changes: 1 addition & 1 deletion phpbench.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"bootstrap": "vendor/autoload.php"
"runner.bootstrap": "vendor/autoload.php"
}
23 changes: 12 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php" colors="true" verbose="true">
<testsuites>
<testsuite name="camille-hdl/lazy-lists unit tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" cacheDirectory=".phpunit.cache">
<coverage/>
<testsuites>
<testsuite name="camille-hdl/lazy-lists unit tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">./src</directory>
</include>
</source>
</phpunit>
13 changes: 13 additions & 0 deletions phpunit.xml.dist.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="./vendor/autoload.php" colors="true" verbose="true">
<testsuites>
<testsuite name="camille-hdl/lazy-lists unit tests">
<directory>./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
66 changes: 0 additions & 66 deletions src/Exception/InvalidArgumentException.php

This file was deleted.

44 changes: 23 additions & 21 deletions src/LazyIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,24 @@
*
* This class can be instanciated by `LazyLists\iterate()`
* @see \LazyLists\iterate
* @template InputType
* @implements \Iterator<int, mixed>
*/
class LazyIterator extends LazyWorker implements \Iterator
{
protected $key = 0;
protected $currentValueBuffer = [];
protected $currentValue = null;
protected $hasValue = false;
protected $canLoop = false;
protected int $key = 0;
/**
* @param array|\Iterator $subject
* @param array $transducers
* @var array<mixed>
*/
public function __construct($subject, array $transducers)
protected array $currentValueBuffer = [];
protected mixed $currentValue = null;
protected bool $hasValue = false;
protected bool $canLoop = false;
/**
* @param array<InputType>|\Iterator<InputType> $subject
* @param \LazyLists\Transducer\TransducerInterface[] $transducers
*/
public function __construct(array|\Iterator $subject, array $transducers)
{
parent::__construct($subject, $transducers);
$this->registerValueCallback(function ($value) {
Expand All @@ -40,13 +45,13 @@ public function __construct($subject, array $transducers)
});
}

public function iteratorInitialization()
public function iteratorInitialization(): void
{
$this->key = 0;
$this->reset();
if ($this->iterator->valid()) {
$this->currentWorkingValue = $this->iterator->current();
$this->finalResultSoFar = $this->getLastTransducer()->getEmptyFinalResult();
$this->finalResultSoFar = $this->getLastTransducer()?->getEmptyFinalResult();
}
$this->computeFirstValue();
}
Expand All @@ -63,10 +68,7 @@ protected function reset()
$this->iterator->rewind();
}

/**
* @return void
*/
public function rewind()
public function rewind(): void
{
$this->iteratorInitialization();
}
Expand All @@ -89,21 +91,21 @@ protected function computeFirstValue()
$this->setCurrentValueFromBuffer();
}

protected function loopUntilNextValue()
protected function loopUntilNextValue(): void
{
$this->canLoop = true;
$this->loop();
}

protected function setCurrentValueFromBuffer()
protected function setCurrentValueFromBuffer(): void
{
if (\count($this->currentValueBuffer) > 0) {
$this->hasValue = true;
$this->currentValue = \array_shift($this->currentValueBuffer);
}
}

protected function computeCurrentValue()
protected function computeCurrentValue(): void
{
$this->hasValue = false;
$this->key++;
Expand All @@ -113,22 +115,22 @@ protected function computeCurrentValue()
$this->setCurrentValueFromBuffer();
}

public function valid()
public function valid(): bool
{
return $this->hasValue;
}

public function next()
public function next(): void
{
$this->computeCurrentValue();
}

public function current()
public function current(): mixed
{
return $this->currentValue;
}

public function key()
public function key(): mixed
{
return $this->key;
}
Expand Down

0 comments on commit bae8e78

Please sign in to comment.