Skip to content

Commit 77ad64b

Browse files
authored
Merge pull request #12 from simPod/php
Drop EOLed php versions
2 parents 92fbe97 + 3aba740 commit 77ad64b

17 files changed

+156
-196
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
pull_request:
5+
push:
6+
schedule:
7+
- cron: "0 0 1 * *"
8+
9+
jobs:
10+
phpunit:
11+
name: "PHPUnit"
12+
runs-on: "ubuntu-20.04"
13+
14+
strategy:
15+
matrix:
16+
php-version:
17+
- "7.3"
18+
- "7.4"
19+
- "8.0"
20+
dependencies:
21+
- "highest"
22+
include:
23+
- dependencies: "lowest"
24+
php-version: "7.3"
25+
26+
steps:
27+
- name: "Checkout"
28+
uses: "actions/checkout@v2"
29+
with:
30+
fetch-depth: 2
31+
32+
- name: "Install PHP"
33+
uses: "shivammathur/setup-php@v2"
34+
with:
35+
php-version: "${{ matrix.php-version }}"
36+
coverage: "pcov"
37+
ini-values: "zend.assertions=1"
38+
39+
- name: "Install dependencies with Composer"
40+
uses: "ramsey/composer-install@v1"
41+
with:
42+
dependency-versions: "${{ matrix.dependencies }}"
43+
44+
- name: "Run PHPUnit"
45+
run: "vendor/bin/phpunit --coverage-clover=coverage.xml"
46+
47+
- name: "Upload coverage file"
48+
uses: "actions/upload-artifact@v2"
49+
with:
50+
name: "phpunit-${{ matrix.deps }}-${{ matrix.php-version }}.coverage"
51+
path: "coverage.xml"
52+
53+
upload_coverage:
54+
name: "Upload coverage to Codecov"
55+
runs-on: "ubuntu-20.04"
56+
needs:
57+
- "phpunit"
58+
59+
steps:
60+
- name: "Checkout"
61+
uses: "actions/checkout@v2"
62+
with:
63+
fetch-depth: 2
64+
65+
- name: "Download coverage files"
66+
uses: "actions/download-artifact@v2"
67+
with:
68+
path: "reports"
69+
70+
- name: "Upload to Codecov"
71+
uses: "codecov/codecov-action@v1"
72+
with:
73+
directory: reports

.scrutinizer.yml

Lines changed: 0 additions & 32 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
[![Latest Stable Version](https://poser.pugx.org/bentools/iterable-functions/v/stable)](https://packagist.org/packages/bentools/iterable-functions)
2-
[![License](https://poser.pugx.org/bentools/iterable-functions/license)](https://packagist.org/packages/bentools/iterable-functions)
3-
[![Build Status](https://img.shields.io/travis/bpolaszek/php-iterable-functions/master.svg?style=flat-square)](https://travis-ci.org/bpolaszek/php-iterable-functions)
4-
[![Coverage Status](https://coveralls.io/repos/github/bpolaszek/php-iterable-functions/badge.svg?branch=master)](https://coveralls.io/github/bpolaszek/php-iterable-functions?branch=master)
5-
[![Quality Score](https://img.shields.io/scrutinizer/g/bpolaszek/php-iterable-functions.svg?style=flat-square)](https://scrutinizer-ci.com/g/bpolaszek/php-iterable-functions)
2+
[![GitHub Actions][GA master image]][GA master]
3+
[![Code Coverage][Coverage image]][CodeCov Master]
64
[![Total Downloads](https://poser.pugx.org/bentools/iterable-functions/downloads)](https://packagist.org/packages/bentools/iterable-functions)
75

86
Iterable functions
@@ -191,3 +189,8 @@ Unit tests
191189
```
192190
./vendor/bin/phpunit
193191
```
192+
193+
[CodeCov Master]: https://codecov.io/gh/bpolaszek/php-iterable-functions/branch/2.0.x-dev
194+
[Coverage image]: https://codecov.io/gh/bpolaszek/php-iterable-functions/branch/2.0.x-dev/graph/badge.svg
195+
[GA master]: https://github.com/bpolaszek/php-iterable-functions/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A2.0.x-dev
196+
[GA master image]: https://github.com/bpolaszek/php-iterable-functions/workflows/Continuous%20Integration/badge.svg

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
]
1616
},
1717
"require": {
18-
"php": ">=5.3"
18+
"php": "^7.3 || ^8.0"
1919
},
2020
"require-dev": {
21-
"phpunit/phpunit": "^4.0|^5.0|^6.0|^7.0",
21+
"phpunit/phpunit": "^9",
2222
"squizlabs/php_codesniffer": "^2.0|^3.4",
23-
"symfony/var-dumper": "@stable"
23+
"symfony/var-dumper": "^5.2"
2424
}
2525
}

phpunit.xml.dist

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
4-
beStrictAboutTestsThatDoNotTestAnything="true"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
beStrictAboutChangesToGlobalState="true"
55
beStrictAboutOutputDuringTests="true"
6-
bootstrap="vendor/autoload.php"
6+
beStrictAboutTodoAnnotatedTests="true"
7+
executionOrder="random"
78
colors="true"
8-
convertErrorsToExceptions="true"
9-
convertNoticesToExceptions="true"
10-
convertWarningsToExceptions="true"
11-
failOnRisky="true"
12-
failOnWarning="true"
13-
processIsolation="false"
14-
stopOnError="false"
15-
stopOnFailure="false"
16-
verbose="true"
9+
bootstrap="tests/bootstrap.php"
1710
>
1811
<testsuites>
1912
<testsuite name="Test Suite">
20-
<file>tests/TestIsIterable.php</file>
21-
<file>tests/TestIterableToArray.php</file>
22-
<file>tests/TestIterableToTraversable.php</file>
23-
<file>tests/TestIterableFilter.php</file>
24-
<file>tests/TestIterableMap.php</file>
25-
<file>tests/TestIterableObject.php</file>
13+
<directory>tests</directory>
2614
</testsuite>
2715
</testsuites>
28-
<filter>
29-
<whitelist processUncoveredFilesFromWhitelist="true">
30-
<directory suffix=".php">./src</directory>
31-
<exclude>
32-
<file>src/iterable-map-php53.php</file>
33-
<file>src/iterable-map-php55.php</file>
34-
</exclude>
35-
</whitelist>
36-
</filter>
16+
<coverage>
17+
<include>
18+
<directory suffix=".php">src</directory>
19+
</include>
20+
</coverage>
3721
</phpunit>

src/iterable-functions.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,41 @@
22

33
use BenTools\IterableFunctions\IterableObject;
44

5-
if (version_compare(PHP_VERSION, '5.5') >= 0) {
6-
include_once __DIR__ . '/iterable-map-php55.php';
7-
} else {
8-
include_once __DIR__ . '/iterable-map-php53.php';
5+
if (!function_exists('iterable_map')) {
6+
7+
/**
8+
* Maps a callable to an iterable.
9+
*
10+
* @param iterable|array|\Traversable $iterable
11+
* @param callable $map
12+
* @return array|ArrayIterator
13+
* @throws InvalidArgumentException
14+
*/
15+
function iterable_map($iterable, $map)
16+
{
17+
if (!is_iterable($iterable)) {
18+
throw new \InvalidArgumentException(
19+
sprintf('Expected array or Traversable, got %s', is_object($iterable) ? get_class($iterable) : gettype($iterable))
20+
);
21+
}
22+
23+
// Cannot rely on callable type-hint on PHP 5.3
24+
if (null !== $map && !is_callable($map) && !$map instanceof Closure) {
25+
throw new InvalidArgumentException(
26+
sprintf('Expected callable, got %s', is_object($map) ? get_class($map) : gettype($map))
27+
);
28+
}
29+
30+
if ($iterable instanceof Traversable) {
31+
return new ArrayIterator(array_map($map, iterator_to_array($iterable)));
32+
}
33+
34+
return array_map($map, $iterable);
35+
}
36+
937
}
1038

39+
1140
if (!function_exists('is_iterable')) {
1241

1342
/**

src/iterable-map-php53.php

Lines changed: 0 additions & 35 deletions
This file was deleted.

src/iterable-map-php55.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

tests/TestIsIterable.php renamed to tests/IsIterableTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
use PHPUnit\Framework\TestCase;
44

5-
class TestIsIterable extends TestCase
5+
final class IsIterableTest extends TestCase
66
{
77

88
public function testFunctionExists()

0 commit comments

Comments
 (0)