Skip to content

Commit 8c95af6

Browse files
authored
fix(phpstan): correct json_decode args and prune stale ignores (#8203)
1 parent 90ae514 commit 8c95af6

5 files changed

Lines changed: 12 additions & 7 deletions

File tree

phpstan.neon.dist

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ parameters:
8585
# Expected, due to backward compatibility
8686
- '#Method GraphQL\\Type\\Definition\\WrappingType::getWrappedType\(\) invoked with 1 parameter, 0 required\.#'
8787
- '#Access to an undefined property GraphQL\\Type\\Definition\\NamedType&GraphQL\\Type\\Definition\\Type::\$name\.#'
88-
- "#Call to function method_exists\\(\\) with GraphQL\\\\Type\\\\Definition\\\\Type&GraphQL\\\\Type\\\\Definition\\\\WrappingType and 'getInnermostType' will always evaluate to true\\.#"
8988
- "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component\\\\\\\\PropertyInfo\\\\\\\\PropertyInfoExtractor' and 'getType' will always evaluate to true\\.#"
9089
- "#Call to function method_exists\\(\\) with 'Symfony\\\\\\\\Component\\\\\\\\HttpFoundation\\\\\\\\Request' and 'getContentTypeFormat' will always evaluate to true\\.#"
9190
- '#Call to an undefined method Symfony\\Component\\HttpFoundation\\Request::getContentType\(\)\.#'

src/GraphQl/Action/EntrypointAction.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ private function parseRequest(Request $request): array
125125
*/
126126
private function parseData(?string $query, ?string $operationName, array $variables, string $jsonContent): array
127127
{
128-
if (!\is_array($data = json_decode($jsonContent, true, 512, \JSON_ERROR_NONE))) {
128+
if (!\is_array($data = json_decode($jsonContent, true))) {
129129
throw new BadRequestHttpException('GraphQL data is not valid JSON.');
130130
}
131131

@@ -162,7 +162,7 @@ private function parseMultipartRequest(?string $query, ?string $operationName, a
162162
[$query, $operationName, $variables] = $this->parseData($query, $operationName, $variables, $operations);
163163

164164
/** @var string $map */
165-
if (!\is_array($decodedMap = json_decode($map, true, 512, \JSON_ERROR_NONE))) {
165+
if (!\is_array($decodedMap = json_decode($map, true))) {
166166
throw new BadRequestHttpException('GraphQL multipart request map is not valid JSON.');
167167
}
168168

@@ -218,7 +218,7 @@ private function applyMapToVariables(array $map, array $variables, array $files)
218218
*/
219219
private function decodeVariables(string $variables): array
220220
{
221-
if (!\is_array($decoded = json_decode($variables, true, 512, \JSON_ERROR_NONE))) {
221+
if (!\is_array($decoded = json_decode($variables, true))) {
222222
throw new BadRequestHttpException('GraphQL variables are not valid JSON.');
223223
}
224224

src/Laravel/Eloquent/Metadata/Factory/Resource/EloquentResourceCollectionMetadataFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,13 @@ public function create(string $resourceClass): ResourceMetadataCollection
111111
if ($this->partialPatchValidation && $operation instanceof Patch) {
112112
$rules = $operation->getRules();
113113
if (\is_array($rules)) {
114-
$operation = $operation->withRules($this->replaceRequiredWithSometimes($rules));
114+
$stringKeyedRules = [];
115+
foreach ($rules as $field => $fieldRules) {
116+
if (\is_string($field)) {
117+
$stringKeyedRules[$field] = $fieldRules;
118+
}
119+
}
120+
$operation = $operation->withRules($this->replaceRequiredWithSometimes($stringKeyedRules));
115121
}
116122
}
117123

src/Metadata/Resource/Factory/ParameterResourceMetadataCollectionFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ private function getProperties(string $resourceClass, ?Parameter $parameter = nu
212212
}
213213

214214
if (($filter = $this->getFilterInstance($parameter->getFilter())) && $filter instanceof PropertyAwareFilterInterface) {
215-
if (!method_exists($filter, 'getProperties')) { // @phpstan-ignore-line todo 5.x remove this check
215+
if (!method_exists($filter, 'getProperties')) { // todo 5.x remove this check
216216
trigger_deprecation('api-platform/core', 'In API Platform 5.0 "%s" will implement a method named "getProperties"', PropertyAwareFilterInterface::class);
217217
$refl = new \ReflectionClass($filter);
218218
$filterProperties = $refl->hasProperty('properties') ? $refl->getProperty('properties')->getValue($filter) : [];

src/Symfony/Bundle/Test/ApiTestAssertionsTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public static function getMercureMessage(int $index = 0, ?string $hubName = null
166166
public static function assertMercureUpdateMatchesJsonSchema(Update $update, array $topics, array|object|string $jsonSchema = '', bool $private = false, ?string $id = null, ?string $type = null, ?int $retry = null, string $message = ''): void
167167
{
168168
static::assertSame($topics, $update->getTopics(), $message);
169-
static::assertThat(json_decode($update->getData(), true, \JSON_THROW_ON_ERROR), new MatchesJsonSchema($jsonSchema), $message);
169+
static::assertThat(json_decode($update->getData(), true, flags: \JSON_THROW_ON_ERROR), new MatchesJsonSchema($jsonSchema), $message);
170170
static::assertSame($private, $update->isPrivate(), $message);
171171
static::assertSame($id, $update->getId(), $message);
172172
static::assertSame($type, $update->getType(), $message);

0 commit comments

Comments
 (0)