Skip to content

Commit

Permalink
allow safe ^2.0 (#6)
Browse files Browse the repository at this point in the history
* allow safe ^2.0
* fixed tests for php>=8.2 and safe>=2.0

---------

Co-authored-by: Alessandro Chitolina <alekitto@gmail.com>
  • Loading branch information
lemorragia and alekitto committed Mar 29, 2023
1 parent f74bfb2 commit 0727196
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 29 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"minimum-stability": "stable",
"require": {
"php": "^8.0",
"thecodingmachine/safe": "^1.0"
"thecodingmachine/safe": "^1.0 || ^2.0"
},
"require-dev": {
"doctrine/annotations": "^1.0",
Expand Down
52 changes: 26 additions & 26 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 17 additions & 2 deletions lib/Iterator/PhpDocumentorIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@
use function assert;
use function class_exists;
use function defined;
use function function_exists;
use function is_callable;
use function is_dir;
use function is_file;
use function iterator_to_array;
use function ltrim;
use function Safe\glob;
use function Safe\preg_match;
use function Safe\uasort;
use function strpos;

use const GLOB_BRACE;
use const GLOB_ONLYDIR;
use const PHP_VERSION_ID;

final class PhpDocumentorIterator extends ClassIterator
{
Expand Down Expand Up @@ -210,7 +212,20 @@ static function (SplFileInfo $file) {
),
RecursiveIteratorIterator::LEAVES_ONLY,
));
uasort($files, static function (SplFileInfo $a, SplFileInfo $b) {

/**
* Compatibility layer for uasort:
*
* @see https://www.php.net/manual/en/function.uasort.php
* - in php 8.2.0 uasort always returns true instead of bool
* - subsequently the function has been removed from thecodingmachine\safe >= 2.0
*/
$uasort = function_exists('\Safe\uasort') && PHP_VERSION_ID <= 80200
? '\Safe\uasort'
: '\uasort';

assert(is_callable($uasort));
$uasort($files, static function (SplFileInfo $a, SplFileInfo $b) {
return (string) $a <=> (string) $b;
});

Expand Down

0 comments on commit 0727196

Please sign in to comment.