Skip to content

Commit 6166a56

Browse files
dunglasabluchet
authored andcommitted
Fix some more quality issues (#1674)
* Fix some more quality issues * One more * Remove useless spaces
1 parent 5c1d808 commit 6166a56

File tree

6 files changed

+43
-30
lines changed

6 files changed

+43
-30
lines changed

src/Bridge/Doctrine/Orm/Extension/EagerLoadingExtension.php

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -228,46 +228,49 @@ private function addSelect(QueryBuilder $queryBuilder, string $entity, string $a
228228
$select = [];
229229
$entityManager = $queryBuilder->getEntityManager();
230230
$targetClassMetadata = $entityManager->getClassMetadata($entity);
231-
if ($targetClassMetadata->subClasses) {
231+
if (!empty($targetClassMetadata->subClasses)) {
232232
$queryBuilder->addSelect($associationAlias);
233-
} else {
234-
foreach ($this->propertyNameCollectionFactory->create($entity) as $property) {
235-
$propertyMetadata = $this->propertyMetadataFactory->create($entity, $property, $propertyMetadataOptions);
236233

237-
if (true === $propertyMetadata->isIdentifier()) {
238-
$select[] = $property;
239-
continue;
240-
}
234+
return;
235+
}
241236

242-
//the field test allows to add methods to a Resource which do not reflect real database fields
243-
if ($targetClassMetadata->hasField($property) && (true === $propertyMetadata->getAttribute('fetchable') || $propertyMetadata->isReadable())) {
244-
$select[] = $property;
245-
}
237+
foreach ($this->propertyNameCollectionFactory->create($entity) as $property) {
238+
$propertyMetadata = $this->propertyMetadataFactory->create($entity, $property, $propertyMetadataOptions);
246239

247-
if (array_key_exists($property, $targetClassMetadata->embeddedClasses)) {
248-
foreach ($this->propertyNameCollectionFactory->create($targetClassMetadata->embeddedClasses[$property]['class']) as $embeddedProperty) {
249-
$propertyMetadata = $this->propertyMetadataFactory->create($entity, $property, $propertyMetadataOptions);
250-
$propertyName = "$property.$embeddedProperty";
251-
if ($targetClassMetadata->hasField($propertyName) && (true === $propertyMetadata->getAttribute('fetchable') || $propertyMetadata->isReadable())) {
252-
$select[] = $propertyName;
253-
}
254-
}
255-
}
240+
if (true === $propertyMetadata->isIdentifier()) {
241+
$select[] = $property;
242+
continue;
256243
}
257244

258-
$queryBuilder->addSelect(sprintf('partial %s.{%s}', $associationAlias, implode(',', $select)));
245+
//the field test allows to add methods to a Resource which do not reflect real database fields
246+
if ($targetClassMetadata->hasField($property) && (true === $propertyMetadata->getAttribute('fetchable') || $propertyMetadata->isReadable())) {
247+
$select[] = $property;
248+
}
249+
250+
if (!array_key_exists($property, $targetClassMetadata->embeddedClasses)) {
251+
continue;
252+
}
253+
254+
foreach ($this->propertyNameCollectionFactory->create($targetClassMetadata->embeddedClasses[$property]['class']) as $embeddedProperty) {
255+
$propertyMetadata = $this->propertyMetadataFactory->create($entity, $property, $propertyMetadataOptions);
256+
$propertyName = "$property.$embeddedProperty";
257+
if ($targetClassMetadata->hasField($propertyName) && (true === $propertyMetadata->getAttribute('fetchable') || $propertyMetadata->isReadable())) {
258+
$select[] = $propertyName;
259+
}
260+
}
259261
}
262+
263+
$queryBuilder->addSelect(sprintf('partial %s.{%s}', $associationAlias, implode(',', $select)));
260264
}
261265

262266
/**
263-
* Gets serializer context.
267+
* Gets the serializer context.
264268
*
265269
* @param string $contextType normalization_context or denormalization_context
266270
* @param array $options represents the operation name so that groups are the one of the specific operation
267271
*/
268272
private function getNormalizationContext(string $resourceClass, string $contextType, array $options): array
269273
{
270-
$request = null;
271274
if (null !== $this->requestStack && null !== $this->serializerContextBuilder && null !== $request = $this->requestStack->getCurrentRequest()) {
272275
return $this->serializerContextBuilder->createFromRequest($request, 'normalization_context' === $contextType);
273276
}

src/Bridge/Doctrine/Orm/Filter/DateFilter.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ protected function addWhere(QueryBuilder $queryBuilder, QueryNameGeneratorInterf
171171
} catch (\Exception $e) {
172172
// Silently ignore this filter if it can not be transformed to a \DateTime
173173
$this->logger->notice('Invalid filter ignored', [
174-
'exception' => new InvalidArgumentException(sprintf('The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor', $field)),
175-
]);
174+
'exception' => new InvalidArgumentException(sprintf('The field "%s" has a wrong date format. Use one accepted by the \DateTime constructor', $field)),
175+
]);
176176

177177
return;
178178
}

src/GraphQl/Resolver/Factory/CollectionResolverFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public function __construct(CollectionDataProviderInterface $collectionDataProvi
6363
public function __invoke(string $resourceClass = null, string $rootClass = null, string $operationName = null): callable
6464
{
6565
return function ($source, $args, $context, ResolveInfo $info) use ($resourceClass, $rootClass) {
66+
if (null === $resourceClass) {
67+
return null;
68+
}
69+
6670
if ($this->requestStack && null !== $request = $this->requestStack->getCurrentRequest()) {
6771
$request->attributes->set(
6872
'_graphql_collections_args',
@@ -75,7 +79,7 @@ public function __invoke(string $resourceClass = null, string $rootClass = null,
7579
$dataProviderContext['attributes'] = $this->fieldsToAttributes($info);
7680
$dataProviderContext['filters'] = $this->getNormalizedFilters($args);
7781

78-
if (isset($source[$rootProperty = $info->fieldName], $source[ItemNormalizer::ITEM_KEY])) {
82+
if (isset($rootClass, $source[$rootProperty = $info->fieldName], $source[ItemNormalizer::ITEM_KEY])) {
7983
$rootResolvedFields = $this->identifiersExtractor->getIdentifiersFromItem(unserialize($source[ItemNormalizer::ITEM_KEY]));
8084
$subresource = $this->getSubresource($rootClass, $rootResolvedFields, array_keys($rootResolvedFields), $rootProperty, $resourceClass, true, $dataProviderContext);
8185
$collection = $subresource ?? [];

src/GraphQl/Resolver/Factory/ItemMutationResolverFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,15 @@ public function __construct(IriConverterInterface $iriConverter, DataPersisterIn
6464
public function __invoke(string $resourceClass = null, string $rootClass = null, string $operationName = null): callable
6565
{
6666
return function ($root, $args, $context, ResolveInfo $info) use ($resourceClass, $operationName) {
67+
if (null === $resourceClass) {
68+
return null;
69+
}
70+
6771
$data = ['clientMutationId' => $args['input']['clientMutationId'] ?? null];
6872
$item = null;
6973

7074
$resourceMetadata = $this->resourceMetadataFactory->create($resourceClass);
71-
$normalizationContext = $resourceMetadata->getGraphqlAttribute($operationName, 'normalization_context', [], true);
75+
$normalizationContext = $resourceMetadata->getGraphqlAttribute($operationName ?? '', 'normalization_context', [], true);
7276
$normalizationContext['attributes'] = $info->getFieldSelection(PHP_INT_MAX);
7377

7478
if (isset($args['input']['id'])) {

src/GraphQl/Resolver/ResourceAccessCheckerTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
trait ResourceAccessCheckerTrait
3838
{
3939
/**
40-
* @param object $object
40+
* @param mixed $object
4141
*
4242
* @throws Error
4343
*/
@@ -47,7 +47,7 @@ public function canAccess(ResourceAccessCheckerInterface $resourceAccessChecker
4747
return;
4848
}
4949

50-
$isGranted = $resourceMetadata->getGraphqlAttribute($operationName, 'access_control', null, true);
50+
$isGranted = $resourceMetadata->getGraphqlAttribute($operationName ?? '', 'access_control', null, true);
5151
if (null === $isGranted || $resourceAccessChecker->isGranted($resourceClass, $isGranted, ['object' => $object])) {
5252
return;
5353
}

src/GraphQl/Type/Definition/IterableType.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public function parseLiteral($valueNode)
7777

7878
/**
7979
* @param StringValueNode|BooleanValueNode|IntValueNode|FloatValueNode|ObjectValueNode|ListValueNode $valueNode
80+
*
81+
* @return mixed
8082
*/
8183
private function parseIterableLiteral($valueNode)
8284
{

0 commit comments

Comments
 (0)