Skip to content

Commit

Permalink
[breaking] Support PHP versions 7.4 and 8
Browse files Browse the repository at this point in the history
This necessarily drops support for PHP <7.4.

All unit tests pass, but code coverage reporting doesn't work with these changes due to autoloading errors that I haven't yet solved.
  • Loading branch information
mpetrovich committed Jun 9, 2021
1 parent 035ff51 commit a4b7043
Show file tree
Hide file tree
Showing 102 changed files with 730 additions and 507 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
vendor/
test-coverage/
coverage.xml
test-coverage.*
.DS_Store
9 changes: 3 additions & 6 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ language: php
dist: xenial

php:
- "5.6"
- "7.0"
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"

before_script:
- composer install --no-interaction

script:
- make test-coverage
- make test
- make check-style

after_success:
Expand Down
41 changes: 29 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
Contributing
===
# Contributing

Dash's modular design makes it easy to contribute. Operations are implemented as pure functions that can be reused and composed to make new operations. The best way to understand how Dash works is to examine the source code of any of the existing operations.

If you encounter a bug or have a suggestion, please [create a new GitHub issue](https://github.com/mpetrovich/dash/issues/new). We want your feedback!

### Organization

This repository is organized as follows:
- `src/`: Individual operations implemented as pure functions.
- `src/Curry/`: Curried versions of most operations.
- `tests/`: Unit tests for all operations. Curried and non-curried versions of the same operation are tested in the same test class.
- `docs/`: Documentation.
- `bin/`: Utility scripts, such as one for generating documentation from all operations' docblock comments.
- `Makefile`: Makefile used to build, run tests, check coding style, and more.

- `src/`: Individual operations implemented as pure functions.
- `src/Curry/`: Curried versions of most operations.
- `tests/`: Unit tests for all operations. Curried and non-curried versions of the same operation are tested in the same test class.
- `docs/`: Documentation.
- `bin/`: Utility scripts, such as one for generating documentation from all operations' docblock comments.
- `Makefile`: Makefile used to build, run tests, check coding style, and more.

### Important notes
- Dash supports legacy versions of PHP, so make sure your contributions work on the oldest supported version of PHP.
- Dash uses [PHPUnit](https://phpunit.de/) for unit testing, and unit tests are automatically run on [Travis CI](https://travis-ci.org/mpetrovich/dash) against new branches and pull requests. Tests are run across all supported PHP versions.
- Dash uses [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for linting.
- Dash is **strict** about following [semantic versioning](https://semver.org/).

- Dash supports legacy versions of PHP, so make sure your contributions work on the oldest supported version of PHP.
- Dash uses [PHPUnit](https://phpunit.de/) for unit testing, and unit tests are automatically run on [Travis CI](https://travis-ci.org/mpetrovich/dash) against new branches and pull requests. Tests are run across all supported PHP versions.
- Dash uses [PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) for linting.
- Dash is **strict** about following [semantic versioning](https://semver.org/).

### Docker tips

Build the Docker container:

```
docker build . -t dash
```

Run the Docker container in an interactive shell:

```
docker run -it dash /bin/bash
```
7 changes: 7 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
FROM php:7.4-fpm
ENV DRIVER pcov

COPY ./php.ini /usr/local/etc/php/php.ini
COPY . /usr/src/dash
WORKDIR /usr/src/dash

RUN apt-get update && \
apt-get install --yes --no-install-recommends git zip unzip libzip-dev
RUN pecl install pcov
RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
RUN composer update --with-all-dependencies

RUN make
CMD make test
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ default:
#
test:
ifdef op
@vendor/bin/phpunit tests/$(op)Test --no-coverage
@vendor/bin/phpunit tests/$(op)Test.php --no-coverage
else
@vendor/bin/phpunit tests/ --no-coverage
endif
Expand All @@ -28,11 +28,11 @@ endif
#
test-coverage:
ifdef op
@vendor/bin/phpunit tests/$(op)Test
@vendor/bin/phpunit tests/$(op)Test.php --coverage-text
else
@vendor/bin/phpunit tests/
@vendor/bin/phpunit tests/ --coverage-text
endif
@echo "Test coverage visible at:" $(shell pwd)/test-coverage/index.html
# @echo "Test coverage visible at:" $(shell pwd)/test-coverage/index.html


# Checks code against style rules
Expand Down Expand Up @@ -92,4 +92,3 @@ release:

# Forces these commands to always run
.PHONY: test test-coverage docs

6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ $males = array_filter($people, function ($person) {
$avgMaleAge = array_sum(array_column($males, 'age')) / count($males);
```

Dash makes common data transformation operations like these clearer and more fluid:
Dash makes common data transformation operations simpler:

```php
$avgMaleAge = Dash\chain($people)
Expand All @@ -88,7 +88,7 @@ This is just a tiny subset of what Dash can do. [**See the full list of operatio

## Installation

Requires PHP 5.6+
Requires PHP 7.4+

```sh
composer require mpetrovich/dash
Expand Down Expand Up @@ -189,7 +189,7 @@ Dash can work with a wide variety of data types, including:

- arrays
- objects (eg. `stdClass`)
- generators ([coming soon](https://github.com/mpetrovich/dash/issues/3))
- generators ([still in development](https://github.com/mpetrovich/dash/issues/3))
- anything that implements the [`Traversable`](http://php.net/manual/en/class.traversable.php) interface
- [`DirectoryIterator`](http://php.net/manual/en/class.directoryiterator.php), which is also a `Traversable` but cannot normally be used with `iterator_to_array()` [due to a PHP bug](https://bugs.php.net/bug.php?id=49755). Dash works around this transparently.

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}
],
"require": {
"php": ">=5.6.0"
"php": ">=7.4"
},
"autoload": {
"psr-4": {
Expand Down Expand Up @@ -189,8 +189,8 @@
]
},
"require-dev": {
"phpunit/phpunit": "^4.7",
"phpdocumentor/phpdocumentor": "^2.8",
"phpunit/phpunit": "^9.5",
"phpdocumentor/phpdocumentor": "^3.0",
"squizlabs/php_codesniffer": "^3.0"
}
}
2 changes: 2 additions & 0 deletions php.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extension = pcov
pcov.enabled = 1
25 changes: 8 additions & 17 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,15 @@
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
>
<?xml version="1.0" encoding="UTF-8"?>

<phpunit>
<testsuites>
<testsuite>
<testsuite name="unit">
<directory suffix="Test.php">src</directory>
</testsuite>
</testsuites>

<filter>
<whitelist checkForUnintentionallyCoveredCode="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
<exclude>
<directory suffix="Test.php">src</directory>
</exclude>
</whitelist>
</filter>

<logging>
<log type="coverage-html" target="test-coverage" lowUpperBound="50" highLowerBound="70" />
<log type="coverage-clover" target="coverage.xml" />
</logging>
</include>
</coverage>
</phpunit>
16 changes: 7 additions & 9 deletions src/getDirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,19 @@ function getDirect($input, $key, $default = null)
return $default;
}

if ($input instanceof \ArrayAccess && $input->offsetExists($key)) {
if (is_null($input)) {
$value = $default;
} elseif ($input instanceof \ArrayAccess && $input->offsetExists($key)) {
$value = $input[$key];
}
elseif (is_array($input) && array_key_exists($key, $input)) {
} elseif (is_array($input) && array_key_exists($key, $input)) {
$value = $input[$key];
}
elseif (is_object($input) && property_exists($input, $key)) {
} elseif (is_object($input) && property_exists($input, $key)) {
$value = $input->$key;
}
elseif (method_exists($input, $key)) {
} elseif ((is_string($input) || is_object($input)) && method_exists($input, $key)) {
$value = function () use ($input, $key) {
return call_user_func_array([$input, $key], func_get_args());
};
}
else {
} else {
$array = toArray($input);
$value = isset($array[$key]) ? $array[$key] : $default;
}
Expand Down
6 changes: 3 additions & 3 deletions src/hasDirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function hasDirect($input, $key)
}

return is_array($input) && array_key_exists($key, $input)
|| is_object($input) && property_exists($input, $key)
|| $input instanceof \ArrayAccess && $input->offsetExists($key)
|| method_exists($input, $key);
|| (is_object($input) || is_string($input) && class_exists($input))
&& (property_exists($input, $key) || method_exists($input, $key))
|| $input instanceof \ArrayAccess && $input->offsetExists($key);
}
Loading

0 comments on commit a4b7043

Please sign in to comment.