Skip to content

Commit 35bad12

Browse files
committed
fix-style
1 parent 526a691 commit 35bad12

File tree

2 files changed

+16
-12
lines changed

2 files changed

+16
-12
lines changed

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

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ 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);
32-
} else {
34+
}
35+
36+
if (!$shouldUseSafe) {
3337
uksort($paths, $callback);
3438
}
3539

0 commit comments

Comments
 (0)