Skip to content

Commit d6e3c1e

Browse files
Fix PHPStan type annotations and code style
- Add proper type annotation for $requestData parameter - Fix code style to match project standards
1 parent f478f3d commit d6e3c1e

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,6 @@ parameters:
5454
count: 1
5555
path: src/Support/AliasArguments/AliasArguments.php
5656

57-
-
58-
rawMessage: 'Method Rebing\GraphQL\Support\AliasArguments\AliasArguments::getAliasesInFields() has parameter $fields with no value type specified in iterable type array.'
59-
identifier: missingType.iterableValue
60-
count: 1
61-
path: src/Support/AliasArguments/AliasArguments.php
62-
63-
-
64-
rawMessage: 'Method Rebing\GraphQL\Support\AliasArguments\AliasArguments::getAliasesInFields() has parameter $prefix with no type specified.'
65-
identifier: missingType.parameter
66-
count: 1
67-
path: src/Support/AliasArguments/AliasArguments.php
68-
69-
-
70-
rawMessage: 'Method Rebing\GraphQL\Support\AliasArguments\AliasArguments::getAliasesInFields() return type has no value type specified in iterable type array.'
71-
identifier: missingType.iterableValue
72-
count: 1
73-
path: src/Support/AliasArguments/AliasArguments.php
74-
7557
-
7658
rawMessage: 'Method Rebing\GraphQL\Support\AliasArguments\ArrayKeyChange::changeKey() has parameter $segments with no value type specified in iterable type array.'
7759
identifier: missingType.iterableValue

src/Support/AliasArguments/AliasArguments.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,15 @@ protected function getArrayDepth(array $array): int
6161

6262
/**
6363
* Get aliases from fields, only traversing fields present in request data.
64-
*
64+
*
6565
* This prevents exponential time complexity with circular type references by only
6666
* exploring the actual data structure sent by the client, not all possible fields
6767
* in the type schema.
6868
*
69-
* @param array $fields Type field definitions
70-
* @param array|null $requestData Actual request data at this level (null for initial call)
69+
* @param array<string,mixed> $fields Type field definitions
70+
* @param array<string,mixed>|null $requestData Actual request data at this level (null for initial call)
7171
* @param string $prefix Path prefix for nested fields
72+
*
7273
* @return array<string,string> Map of field paths to their aliases
7374
*/
7475
protected function getAliasesInFields(array $fields, ?array $requestData = null, string $prefix = ''): array
@@ -83,7 +84,7 @@ protected function getAliasesInFields(array $fields, ?array $requestData = null,
8384
foreach ($fields as $name => $arg) {
8485
// KEY FIX: Skip fields not present in actual request data
8586
// This prevents exponential explosion with circular type references
86-
if ($requestData !== null && !array_key_exists($name, $requestData)) {
87+
if (null !== $requestData && !\array_key_exists($name, $requestData)) {
8788
continue;
8889
}
8990

@@ -110,6 +111,7 @@ protected function getAliasesInFields(array $fields, ?array $requestData = null,
110111
}
111112

112113
$isWrappedInList = $this->isWrappedInList($type);
114+
113115
if ($isWrappedInList) {
114116
$newPrefix .= '.*';
115117
}
@@ -121,20 +123,20 @@ protected function getAliasesInFields(array $fields, ?array $requestData = null,
121123
}
122124

123125
// Get the actual data at this field (if requestData provided)
124-
$fieldData = $requestData !== null ? ($requestData[$name] ?? null) : null;
126+
$fieldData = null !== $requestData ? ($requestData[$name] ?? null) : null;
125127

126128
// If it's a list, process each item
127-
if ($isWrappedInList && is_array($fieldData)) {
129+
if ($isWrappedInList && \is_array($fieldData)) {
128130
foreach ($fieldData as $item) {
129-
if (is_array($item)) {
131+
if (\is_array($item)) {
130132
$pathAndAlias = $pathAndAlias + $this->getAliasesInFields(
131133
$type->getFields(),
132134
$item,
133135
$newPrefix
134136
);
135137
}
136138
}
137-
} elseif ($fieldData !== null && is_array($fieldData)) {
139+
} elseif (null !== $fieldData && \is_array($fieldData)) {
138140
// Single object
139141
$pathAndAlias = $pathAndAlias + $this->getAliasesInFields(
140142
$type->getFields(),

0 commit comments

Comments
 (0)