Skip to content

Commit 14497f5

Browse files
committed
fix-style
1 parent 526a691 commit 14497f5

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
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

+10-10
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
{
@@ -26,29 +27,28 @@ public static function applyEach(Closure $callback, $valueOrValues)
2627

2728
/**
2829
* Check compatible ability to use thecodingmachine/safe.
29-
*
30-
* @param string $methodName
31-
* @return bool
3230
*/
3331
public static function shouldUseSafe(string $methodName): bool
3432
{
35-
$safeVersion = \Composer\InstalledVersions::getVersion('thecodingmachine/safe');
33+
$packageName = 'thecodingmachine/safe';
34+
$safeVersion = \Composer\InstalledVersions::getVersion($packageName);
35+
36+
if (!$safeVersion) {
37+
throw new OutOfBoundsException("Package {$packageName} is being replaced or provided but is not really installed");
38+
}
3639

3740
$skipFunctions = [
3841
'uksort',
3942
];
4043

4144
// Version 2.
42-
if (version_compare($safeVersion, '2', '>='))
43-
{
44-
if (in_array($methodName, $skipFunctions))
45-
{
45+
if (version_compare($safeVersion, '2', '>=')) {
46+
if (\in_array($methodName, $skipFunctions)) {
4647
return false;
4748
}
4849
}
4950

50-
if (!is_callable('\\Safe\\' . $methodName))
51-
{
51+
if (!\is_callable('\\Safe\\' . $methodName)) {
5252
return false;
5353
}
5454

src/Support/AliasArguments/ArrayKeyChange.php

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

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

0 commit comments

Comments
 (0)