Skip to content
Closed
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
32 changes: 0 additions & 32 deletions .github/workflows/php.yml

This file was deleted.

28 changes: 28 additions & 0 deletions .github/workflows/project-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Unit tests & static analysis

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
check:
runs-on: ubuntu-latest
strategy:
matrix:
php_version: [ "8.2", "8.3", "8.4" ]
container:
image: ghcr.io/shoppingflux/php:${{ matrix.php_version }}-unit
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
XDEBUG_MODE: off
credentials:
username: ${{ secrets.CR_USER }}
password: ${{ secrets.CR_PAT }}
steps:
- name: Composer install
uses: shoppingflux/github-actions/composer-install@main

- name: Run test script
run: composer test
26 changes: 26 additions & 0 deletions .github/workflows/project-sonar.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Sonarcloud reporting

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
sonarcloud:
runs-on: ubuntu-latest
container:
image: ghcr.io/shoppingflux/php:8.2-unit
env:
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
XDEBUG_MODE: coverage
credentials:
username: ${{ secrets.CR_USER }}
password: ${{ secrets.CR_PAT }}

steps:
- name: Sonarcloud scan
uses: shoppingflux/github-actions/sonarcloud@main
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
sonar-token: ${{ secrets.SONARCLOUD_TOKEN }}
1 change: 0 additions & 1 deletion README.md

This file was deleted.

24 changes: 17 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,35 @@
"license": "MIT",
"description": "Provide reusable iterators",
"require": {
"php": ">=5.6"
"php": ">=8.2"
},
"autoload": {
"psr-4": {
"ShoppingFeed\\Iterator\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"shoppingfeed/coding-style-php": "~2.1.0",
"overtrue/phplint": "^1.1"
"phpunit/phpunit": "^11.0",
"shoppingfeed/coding-style-php": "^2.1.0",
"overtrue/phplint": "^9.1",
"phpstan/phpstan": "^2.1"
},
"scripts": {
"phpunit": "vendor/bin/phpunit --testsuite=unit",
"phpcs": "vendor/bin/sfcs src --progress -vvv",
"phpcsfix": "vendor/bin/sfcs src --progress -vvv --autofix",
"phpunit": "vendor/bin/phpunit",
"phpcs": "vendor/bin/sfcs --progress -vvv -- src test",
"phpcsfix": "vendor/bin/sfcs --progress -vvv --autofix -- src test",
"phplint": "vendor/bin/phplint src --cache=build/phplint.cache",
"phpstan": "vendor/bin/phpstan analyse --memory-limit=1G",
"test": [
"@phplint",
"@phpunit",
"@phpstan",
"@phpcs"
]
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": false
}
}
}
115 changes: 115 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
parameters:
ignoreErrors:
-
message: '#^Method ShoppingFeed\\Iterator\\AbstractIterator\:\:toArray\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/AbstractIterator.php

-
message: '#^Property ShoppingFeed\\Iterator\\AbstractIterator\:\:\$items type has no value type specified in iterable type Traversable\.$#'
identifier: missingType.iterableValue
count: 1
path: src/AbstractIterator.php

-
message: '#^Property ShoppingFeed\\Iterator\\AbstractIterator\:\:\$items type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/AbstractIterator.php

-
message: '#^Property ShoppingFeed\\Iterator\\AbstractIterator\:\:\$items type has no value type specified in iterable type array\|Traversable\.$#'
identifier: missingType.iterableValue
count: 1
path: src/AbstractIterator.php

-
message: '#^Method ShoppingFeed\\Iterator\\CallbackIterator\:\:__construct\(\) has parameter \$arrayOrIterator with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/CallbackIterator.php

-
message: '#^Property ShoppingFeed\\Iterator\\CallbackIterator\:\:\$iterator \(Iterator\) does not accept Traversable\.$#'
identifier: assign.propertyType
count: 1
path: src/CallbackIterator.php

-
message: '#^Interface ShoppingFeed\\Iterator\\CountableTraversable extends generic interface Traversable but does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: src/CountableTraversable.php

-
message: '#^Interface ShoppingFeed\\Iterator\\CountableTraversable has type alias CountableIterable with no value type specified in iterable type ShoppingFeed\\Iterator\\CountableTraversable\.$#'
identifier: missingType.iterableValue
count: 1
path: src/CountableTraversable.php

-
message: '#^Interface ShoppingFeed\\Iterator\\CountableTraversable has type alias CountableIterable with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/CountableTraversable.php

-
message: '#^Interface ShoppingFeed\\Iterator\\CountableTraversable has type alias CountableIterable with no value type specified in iterable type array\|ShoppingFeed\\Iterator\\CountableTraversable\.$#'
identifier: missingType.iterableValue
count: 1
path: src/CountableTraversable.php

-
message: '#^Method ShoppingFeed\\Iterator\\FilterAggregateIterator\:\:__construct\(\) has parameter \$arrayOrTraversable with no type specified\.$#'
identifier: missingType.parameter
count: 1
path: src/FilterAggregateIterator.php

-
message: '#^Parameter \#1 \$value of function count expects array\|Countable, array\|Traversable given\.$#'
identifier: argument.type
count: 1
path: src/FilterAggregateIterator.php

-
message: '#^Interface ShoppingFeed\\Iterator\\IteratorInterface extends generic interface IteratorAggregate but does not specify its types\: TKey, TValue$#'
identifier: missingType.generics
count: 1
path: src/IteratorInterface.php

-
message: '#^Method ShoppingFeed\\Iterator\\IteratorInterface\:\:toArray\(\) return type has no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/IteratorInterface.php

-
message: '#^Instanceof between Traversable and Traversable will always evaluate to true\.$#'
identifier: instanceof.alwaysTrue
count: 1
path: src/KeyThenValueIterator.php

-
message: '#^Method ShoppingFeed\\Iterator\\KeyThenValueIterator\:\:__construct\(\) has parameter \$iterable with no value type specified in iterable type Traversable\.$#'
identifier: missingType.iterableValue
count: 1
path: src/KeyThenValueIterator.php

-
message: '#^Method ShoppingFeed\\Iterator\\KeyThenValueIterator\:\:__construct\(\) has parameter \$iterable with no value type specified in iterable type array\.$#'
identifier: missingType.iterableValue
count: 1
path: src/KeyThenValueIterator.php

-
message: '#^Method ShoppingFeed\\Iterator\\KeyThenValueIterator\:\:__construct\(\) has parameter \$iterable with no value type specified in iterable type array\|Traversable\.$#'
identifier: missingType.iterableValue
count: 1
path: src/KeyThenValueIterator.php

-
message: '#^Result of && is always false\.$#'
identifier: booleanAnd.alwaysFalse
count: 1
path: src/KeyThenValueIterator.php
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
paths:
- src
level: 8

includes:
- phpstan-baseline.neon
24 changes: 12 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<phpunit bootstrap="./tests/unit/bootstrap.php" colors="true">
<testsuites>
<testsuite name="AppTest\\">
<directory>./tests/unit</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true" cacheDirectory=".phpunit.cache">
<testsuites>
<testsuite name="Project">
<directory>test/unit</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
19 changes: 19 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# shoppingfeed/iterator

### Installation

```
composer require shoppingfeed/iterator
```

### Contributing

To connect to a php 8.2 container correctly configured

- Create a container : `docker run --name iterator-php -v $PWD:/var/www -d ghcr.io/shoppingflux/php:8.2-unit`
- Connect to container : `docker exec -it iterator-php bash`

Once connected to the container you can :

- Update composer dependencies : `composer update`
- Run test : `composer test`
2 changes: 2 additions & 0 deletions sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
sonar.organization=shoppingfeed
sonar.projectKey=shoppingflux_iterator
sonar.sources=./src
sonar.php.coverage.reportPaths=build/clover.xml
sonar.php.tests.reportPath=build/junit.xml
Expand Down
5 changes: 2 additions & 3 deletions src/AbstractIterator.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace ShoppingFeed\Iterator;

abstract class AbstractIterator implements IteratorInterface
{
/**
* @var array|\Traversable
*/
/** @var array|\Traversable */
protected $items;

/**
Expand Down
21 changes: 11 additions & 10 deletions src/CallbackIterator.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php

namespace ShoppingFeed\Iterator;

use ArrayIterator;
use ReturnTypeWillChange;
use Traversable;

class CallbackIterator extends AbstractIterator
{
/**
* @var \Iterator
*/
/** @var \Iterator */
private $iterator;

/**
* @var callable
*/
/** @var callable */
private $callback;

/**
Expand All @@ -20,20 +21,20 @@ class CallbackIterator extends AbstractIterator
public function __construct($arrayOrIterator, callable $callback)
{
if (is_array($arrayOrIterator)) {
$arrayOrIterator = new \ArrayIterator($arrayOrIterator);
$arrayOrIterator = new ArrayIterator($arrayOrIterator);
}

if (! $arrayOrIterator instanceof \Traversable) {
if (! $arrayOrIterator instanceof Traversable) {
throw new Exception\InvalidArgumentException(
'Expecting an array or an instance of \Traversable'
'Expecting an array or an instance of \Traversable',
);
}

$this->iterator = $arrayOrIterator;
$this->callback = $callback;
}

#[\ReturnTypeWillChange]
#[ReturnTypeWillChange]
public function getIterator()
{
foreach ($this->iterator as $key => $item) {
Expand Down
1 change: 0 additions & 1 deletion src/CountableTraversable.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
*/
interface CountableTraversable extends Traversable, Countable
{

}
5 changes: 4 additions & 1 deletion src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

namespace ShoppingFeed\Iterator\Exception;

class InvalidArgumentException extends \InvalidArgumentException
use InvalidArgumentException as BaseInvalidArgumentException;

class InvalidArgumentException extends BaseInvalidArgumentException
{
}
Loading
Loading