Skip to content

Commit 191012d

Browse files
authored
Fix some more quality issues (#1674)
* Fix some more quality issues * One more * Remove useless spaces
1 parent 9d32962 commit 191012d

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
@@ -226,46 +226,49 @@ private function addSelect(QueryBuilder $queryBuilder, string $entity, string $a
226226
$select = [];
227227
$entityManager = $queryBuilder->getEntityManager();
228228
$targetClassMetadata = $entityManager->getClassMetadata($entity);
229-
if ($targetClassMetadata->subClasses) {
229+
if (!empty($targetClassMetadata->subClasses)) {
230230
$queryBuilder->addSelect($associationAlias);
231-
} else {
232-
foreach ($this->propertyNameCollectionFactory->create($entity) as $property) {
233-
$propertyMetadata = $this->propertyMetadataFactory->create($entity, $property, $propertyMetadataOptions);
234231

235-
if (true === $propertyMetadata->isIdentifier()) {
236-
$select[] = $property;
237-
continue;
238-
}
232+
return;
233+
}
239234

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

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

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

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

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'] = $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)