Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow safe ^2.0 #6

Merged
merged 4 commits into from
Mar 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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