Skip to content

Commit ac46ebd

Browse files
committed
style: various code smells
1 parent bbba5d8 commit ac46ebd

File tree

13 files changed

+26
-28
lines changed

13 files changed

+26
-28
lines changed

features/graphql/authorization.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ Feature: Authorization checking
410410
"""
411411
Then the response status code should be 200
412412
And the response should be in JSON
413-
And the JSON node "data.securedDummy.ownerOnlyProperty" should be equal to the string ""
413+
And the JSON node "data.securedDummy.ownerOnlyProperty" should be equal to ""
414414

415415
Scenario: A user cannot retrieve an item they doesn't own
416416
When I add "Authorization" header equal to "Basic ZHVuZ2xhczprZXZpbg=="

features/main/custom_operation.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Feature: Custom operation
9696

9797
@createSchema
9898
Scenario: Void a payment
99-
Given There is a payment
99+
Given there is a payment
100100
When I send a "POST" request to "/payments/1/void"
101101
Then the response status code should be 201
102102
And the response should be in JSON

src/Action/ExceptionAction.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,13 @@ private function getOperationExceptionToStatus(Request $request): array
8585
$resourceMetadataCollection = $this->resourceMetadataCollectionFactory->create($attributes['resource_class']);
8686
/** @var HttpOperation $operation */
8787
$operation = $resourceMetadataCollection->getOperation($attributes['operation_name'] ?? null);
88-
$exceptionToStatus = $operation->getExceptionToStatus() ?: [];
88+
$exceptionToStatus = [$operation->getExceptionToStatus() ?: []];
89+
8990
foreach ($resourceMetadataCollection as $resourceMetadata) {
90-
/** @var ApiResource $resourceMetadata */
91-
$exceptionToStatus = array_merge($exceptionToStatus, $resourceMetadata->getExceptionToStatus() ?: []);
91+
/* @var ApiResource $resourceMetadata */
92+
$exceptionToStatus[] = $resourceMetadata->getExceptionToStatus() ?: [];
9293
}
9394

94-
return $exceptionToStatus;
95+
return array_merge(...$exceptionToStatus);
9596
}
9697
}

src/Api/IdentifiersExtractor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ public function getIdentifiersFromItem(object $item, Operation $operation = null
7575
continue;
7676
}
7777

78-
$identifiers[$link->getParameterName()] = $this->getIdentifierValue($item, $link->getFromClass(), $link->getIdentifiers()[0], $link->getParameterName());
78+
$parameterName = $link->getParameterName();
79+
$identifiers[$parameterName] = $this->getIdentifierValue($item, $link->getFromClass(), $link->getIdentifiers()[0], $parameterName);
7980
}
8081

8182
return $identifiers;

src/Api/QueryParameterValidator/QueryParameterValidator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,15 @@ public function validateFilters(string $resourceClass, array $resourceFilters, a
6161

6262
foreach ($filter->getDescription($resourceClass) as $name => $data) {
6363
foreach ($this->validators as $validator) {
64-
$errorList = array_merge($errorList, $validator->validate($name, $data, $queryParameters));
64+
if ($errors = $validator->validate($name, $data, $queryParameters)) {
65+
$errorList[] = $errors;
66+
}
6567
}
6668
}
6769
}
6870

6971
if ($errorList) {
70-
throw new FilterValidationException($errorList);
72+
throw new FilterValidationException(array_merge(...$errorList));
7173
}
7274
}
7375
}

src/Doctrine/Common/State/LinksHandlerTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ private function getLinks(string $resourceClass, Operation $operation, array $co
5353

5454
// Instead, we'll look for the first Query available.
5555
foreach ($resourceMetadataCollection as $resourceMetadata) {
56-
foreach ($resourceMetadata->getGraphQlOperations() as $operation) {
57-
if ($operation instanceof Query) {
58-
$linkedOperation = $operation;
56+
foreach ($resourceMetadata->getGraphQlOperations() as $op) {
57+
if ($op instanceof Query) {
58+
$linkedOperation = $op;
5959
}
6060
}
6161
}

src/GraphQl/Action/EntrypointAction.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ private function applyMapToVariables(array $map, array $variables, array $files)
156156
throw new BadRequestHttpException('GraphQL multipart request file has not been sent correctly.');
157157
}
158158

159-
foreach ($map[$key] as $mapValue) {
159+
foreach ($value as $mapValue) {
160160
$path = explode('.', (string) $mapValue);
161161

162162
if ('variables' !== $path[0]) {

src/GraphQl/Serializer/SerializerContextBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ private function replaceIdKeys(array $fields, ?string $resourceClass, array $con
8888
continue;
8989
}
9090

91-
$denormalizedFields[$this->denormalizePropertyName((string) $key, $resourceClass, $context)] = \is_array($fields[$key]) ? $this->replaceIdKeys($fields[$key], $resourceClass, $context) : $value;
91+
$denormalizedFields[$this->denormalizePropertyName((string) $key, $resourceClass, $context)] = \is_array($value) ? $this->replaceIdKeys($value, $resourceClass, $context) : $value;
9292
}
9393

9494
return $denormalizedFields;

src/Metadata/Property/Factory/SerializerPropertyMetadataFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ private function getClassSerializerGroups(string $class): array
198198

199199
$groups = [];
200200
foreach ($serializerClassMetadata->getAttributesMetadata() as $serializerAttributeMetadata) {
201-
$groups = array_merge($groups, $serializerAttributeMetadata->getGroups());
201+
$groups[] = $serializerAttributeMetadata->getGroups();
202202
}
203203

204-
return array_unique($groups);
204+
return array_unique(array_merge(...$groups));
205205
}
206206
}

src/Serializer/AbstractItemNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ protected function instantiateObject(array &$data, string $class, array &$contex
263263
throw new RuntimeException(sprintf('Cannot create an instance of %s from serialized data because the variadic parameter %s can only accept an array.', $class, $constructorParameter->name));
264264
}
265265

266-
$params = array_merge($params, $data[$paramName]);
266+
$params[] = $data[$paramName];
267267
}
268268
} elseif ($allowed && !$ignored && (isset($data[$key]) || \array_key_exists($key, $data))) {
269269
$params[] = $this->createConstructorArgument($data[$key], $key, $constructorParameter, $context, $format);

src/Symfony/Routing/ApiLoader.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,8 @@ public function load(mixed $data, string $type = null): RouteCollection
7575
$path = str_replace(sprintf('{%s}', $parameterName), $expandedValue, $path);
7676
}
7777

78-
if ($controller = $operation->getController()) {
79-
if (!$this->container->has($controller)) {
80-
throw new RuntimeException(sprintf('There is no builtin action for the "%s" operation. You need to define the controller yourself.', $operationName));
81-
}
78+
if (($controller = $operation->getController()) && !$this->container->has($controller)) {
79+
throw new RuntimeException(sprintf('There is no builtin action for the "%s" operation. You need to define the controller yourself.', $operationName));
8280
}
8381

8482
$route = new Route(

tests/Fixtures/TestBundle/Entity/SubresourceOrganization.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,9 @@ public function addSubresourceEmployee(SubresourceEmployee $employee): self
7575

7676
public function removeSubresourceEmployee(SubresourceEmployee $employee): self
7777
{
78-
if ($this->employees->removeElement($employee)) {
79-
// set the owning side to null (unless already changed)
80-
if ($employee->getSubresourceOrganization() === $this) {
81-
$employee->setSubresourceOrganization(null);
82-
}
78+
// set the owning side to null (unless already changed)
79+
if ($this->employees->removeElement($employee) && $employee->getSubresourceOrganization() === $this) {
80+
$employee->setSubresourceOrganization(null);
8381
}
8482

8583
return $this;

tests/Fixtures/TestBundle/GraphQl/Resolver/UploadMultipleMediaObjectResolver.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class UploadMultipleMediaObjectResolver implements MutationResolverInterface
2626
{
2727
public function __invoke(?object $item, array $context): MediaObject
2828
{
29-
$result = [];
3029
$mediaObject = null;
3130

3231
/**
@@ -40,7 +39,6 @@ public function __invoke(?object $item, array $context): MediaObject
4039
$mediaObject = new MediaObject();
4140
$mediaObject->id = $key;
4241
$mediaObject->contentUrl = $uploadedFile->getFilename();
43-
$result[] = $mediaObject;
4442
}
4543

4644
// Currently API Platform does not support custom mutation with collections so for now, we are returning the last created media object.

0 commit comments

Comments
 (0)