Skip to content

Commit 33dbc8f

Browse files
committed
update thecodingmachine/safe 2.4
1 parent 526a691 commit 33dbc8f

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"illuminate/contracts": "^6.0|^8.0|^9.0",
4040
"illuminate/support": "^6.0|^8.0|^9.0",
4141
"laragraph/utils": "^1",
42-
"thecodingmachine/safe": "^1.1 || ^2",
42+
"thecodingmachine/safe": "^1.1|^2.4",
4343
"webonyx/graphql-php": "^14.6.4"
4444
},
4545
"require-dev": {

src/Helpers.php

+13-11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Rebing\GraphQL;
55

66
use Closure;
7+
use OutOfBoundsException;
78

89
class Helpers
910
{
@@ -27,31 +28,32 @@ public static function applyEach(Closure $callback, $valueOrValues)
2728
/**
2829
* Check compatible ability to use thecodingmachine/safe.
2930
*
30-
* @param string $methodName
31-
* @return bool
31+
* @return string|false
3232
*/
33-
public static function shouldUseSafe(string $methodName): bool
33+
public static function shouldUseSafe(string $methodName)
3434
{
35-
$safeVersion = \Composer\InstalledVersions::getVersion('thecodingmachine/safe');
35+
$packageName = 'thecodingmachine/safe';
36+
$safeVersion = \Composer\InstalledVersions::getVersion($packageName);
37+
38+
if (!$safeVersion) {
39+
throw new OutOfBoundsException("Package {$packageName} is being replaced or provided but is not really installed");
40+
}
3641

3742
$skipFunctions = [
3843
'uksort',
3944
];
4045

4146
// Version 2.
42-
if (version_compare($safeVersion, '2', '>='))
43-
{
44-
if (in_array($methodName, $skipFunctions))
45-
{
47+
if (version_compare($safeVersion, '2', '>=')) {
48+
if (\in_array(str_replace('\\Safe\\', '', $methodName), $skipFunctions)) {
4649
return false;
4750
}
4851
}
4952

50-
if (!is_callable('\\Safe\\' . $methodName))
51-
{
53+
if (!\is_callable($methodName)) {
5254
return false;
5355
}
5456

55-
return true;
57+
return $methodName;
5658
}
5759
}

src/Support/AliasArguments/ArrayKeyChange.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ private function orderPaths(array $paths): array
2727
return $this->pathLevels($b) <=> $this->pathLevels($a);
2828
};
2929

30-
if (Helpers::shouldUseSafe('uksort')) {
31-
\Safe\uksort($paths, $callback);
30+
$functionName = Helpers::shouldUseSafe('\\Safe\\uksort');
31+
32+
if (\is_callable($functionName)) {
33+
$functionName($paths, $callback);
3234
} else {
3335
uksort($paths, $callback);
3436
}

0 commit comments

Comments
 (0)