Skip to content
This repository has been archived by the owner on Jun 8, 2020. It is now read-only.

Commit

Permalink
Fix CS
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentchalamon committed Oct 8, 2018
1 parent d48e75f commit a0109b3
Show file tree
Hide file tree
Showing 27 changed files with 44 additions and 44 deletions.
4 changes: 2 additions & 2 deletions src/Context/ApiContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public function validateItemJsonSchema(string $name, $schema = null)
if (null === $schema) {
$schema = $this->schemaGenerator->generate($this->helper->getReflectionClass($name), ['collection' => false, 'root' => true]);
}
$this->jsonContext->theJsonShouldBeValidAccordingToThisSchema(new PyStringNode([is_array($schema) ? json_encode($schema) : $schema], 0));
$this->jsonContext->theJsonShouldBeValidAccordingToThisSchema(new PyStringNode([\is_array($schema) ? json_encode($schema) : $schema], 0));
}

/**
Expand All @@ -347,7 +347,7 @@ public function validateCollectionJsonSchema(string $name, int $total = null, $s
if (null === $schema) {
$schema = $this->schemaGenerator->generate($this->helper->getReflectionClass($name), ['collection' => true, 'root' => true]);
}
$this->jsonContext->theJsonShouldBeValidAccordingToThisSchema(new PyStringNode([is_array($schema) ? json_encode($schema) : $schema], 0));
$this->jsonContext->theJsonShouldBeValidAccordingToThisSchema(new PyStringNode([\is_array($schema) ? json_encode($schema) : $schema], 0));
if (null !== $total) {
$this->jsonContext->theJsonNodeShouldHaveElements('hydra:member', $total);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Context/Argument/ArgumentResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class ArgumentResolver implements ArgumentResolverInterface

public function __construct(/* ... */)
{
$this->dependencies = func_get_args();
$this->dependencies = \func_get_args();
}

public function setMetadataFactory(ResourceMetadataFactoryInterface $metadataFactory)
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/ApiHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getReflectionClass(string $name): \ReflectionClass
$classes = array_filter($allClasses, function (\ReflectionClass $reflectionClass) use ($result) {
return strtolower($result) === strtolower($reflectionClass->getShortName());
});
if (count($classes)) {
if (\count($classes)) {
return array_shift($classes);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Populator/Guesser/ArrayGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ArrayGuesser extends AbstractGuesser
{
public function supports(array $mapping): bool
{
return in_array($mapping['type'], [Type::TARRAY, Type::SIMPLE_ARRAY, Type::JSON_ARRAY], true);
return \in_array($mapping['type'], [Type::TARRAY, Type::SIMPLE_ARRAY, Type::JSON_ARRAY], true);
}

public function getValue(array $mapping): array
Expand Down
2 changes: 1 addition & 1 deletion src/Populator/Guesser/BooleanGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BooleanGuesser extends AbstractGuesser
{
public function supports(array $mapping): bool
{
return in_array($mapping['type'], ['boolean', 'bool'], true);
return \in_array($mapping['type'], ['boolean', 'bool'], true);
}

public function getValue(array $mapping): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Populator/Guesser/CollectionGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function setRegistry(ManagerRegistry $registry)

public function supports(array $mapping): bool
{
return null !== $mapping['targetEntity'] && in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY], true);
return null !== $mapping['targetEntity'] && \in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY], true);
}

public function getValue(array $mapping): array
Expand Down
2 changes: 1 addition & 1 deletion src/Populator/Guesser/DateTimeGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DateTimeGuesser extends AbstractGuesser
{
public function supports(array $mapping): bool
{
return in_array($mapping['type'], ['datetime', 'date', 'time'], true);
return \in_array($mapping['type'], ['datetime', 'date', 'time'], true);
}

public function getValue(array $mapping): \DateTime
Expand Down
2 changes: 1 addition & 1 deletion src/Populator/Guesser/EntityGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function setRegistry(ManagerRegistry $registry)

public function supports(array $mapping): bool
{
return null !== $mapping['targetEntity'] && in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE], true);
return null !== $mapping['targetEntity'] && \in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE], true);
}

public function getValue(array $mapping)
Expand Down
2 changes: 1 addition & 1 deletion src/Populator/Guesser/IntegerGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class IntegerGuesser extends AbstractGuesser
{
public function supports(array $mapping): bool
{
return in_array($mapping['type'], ['int', 'integer', 'smallint', 'bigint'], true);
return \in_array($mapping['type'], ['int', 'integer', 'smallint', 'bigint'], true);
}

public function getValue(array $mapping): int
Expand Down
2 changes: 1 addition & 1 deletion src/Populator/Guesser/StringGuesser.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class StringGuesser extends AbstractGuesser
{
public function supports(array $mapping): bool
{
return in_array($mapping['type'], ['string', 'text'], true);
return \in_array($mapping['type'], ['string', 'text'], true);
}

public function getValue(array $mapping): string
Expand Down
18 changes: 9 additions & 9 deletions src/Populator/Populator.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public function getObject(\ReflectionClass $reflectionClass, array $values = [])
foreach ($values as $property => $value) {
$value = $this->transformer->toObject($this->getMapping($classMetadata, $property), $value);
if ($reflectionClass->hasMethod($property)) {
call_user_func([$object, $property], $value);
\call_user_func([$object, $property], $value);
} elseif ($reflectionClass->hasMethod('set'.Inflector::camelize($property))) {
call_user_func([$object, 'set'.Inflector::camelize($property)], $value);
\call_user_func([$object, 'set'.Inflector::camelize($property)], $value);
} elseif ($reflectionClass->hasProperty($property)) {
$reflectionProperty = $reflectionClass->getProperty($property);
$reflectionProperty->setAccessible(true);
Expand All @@ -124,14 +124,14 @@ public function getRequestData(\ReflectionClass $reflectionClass, string $operat
// Get serialization groups
$resourceMetadata = $this->metadataFactory->create($className);
$itemOperations = $this->filterOperations($resourceMetadata->getItemOperations() ?: ['get', 'put', 'delete'], $operation);
if (0 < count($itemOperations)) {
if (0 < \count($itemOperations)) {
$methodName = 'getItemOperationAttribute';
} else {
$methodName = 'getCollectionOperationAttribute';
}
$groups = array_merge($extraGroups, call_user_func([$resourceMetadata, $methodName], $operation, 'denormalization_context', [], true)['groups'] ?? []);
$validationGroups = call_user_func([$resourceMetadata, $methodName], $operation, 'validation_groups', ['Default'], true);
if (is_string($validationGroups)) {
$groups = array_merge($extraGroups, \call_user_func([$resourceMetadata, $methodName], $operation, 'denormalization_context', [], true)['groups'] ?? []);
$validationGroups = \call_user_func([$resourceMetadata, $methodName], $operation, 'validation_groups', ['Default'], true);
if (\is_string($validationGroups)) {
$validationGroups = [];
}
$originalValues = $values;
Expand All @@ -140,7 +140,7 @@ public function getRequestData(\ReflectionClass $reflectionClass, string $operat
/** @var ClassMetadataInfo $classMetadata */
$classMetadata = $this->registry->getManagerForClass($className)->getClassMetadata($className);
foreach ($this->propertyInfo->getProperties($className, $groups ? ['serializer_groups' => $groups] : []) as $property) {
if (!$reflectionClass->hasProperty($property) || !$this->isRequired($reflectionClass->getProperty($property), $validationGroups) || array_key_exists($property, $values) || ('put' === $operation && 0 < count($originalValues))) {
if (!$reflectionClass->hasProperty($property) || !$this->isRequired($reflectionClass->getProperty($property), $validationGroups) || array_key_exists($property, $values) || ('put' === $operation && 0 < \count($originalValues))) {
continue;
}
$values[$property] = $this->guesser->getValue($this->getMapping($classMetadata, $property));
Expand Down Expand Up @@ -227,7 +227,7 @@ private function isRequired(\ReflectionProperty $reflectionProperty, $groups): b

foreach ([NotBlank::class, NotNull::class, Count::class] as $class) {
$annotation = $this->annotationReader->getPropertyAnnotation($reflectionProperty, $class);
if ($annotation && 0 < count(array_intersect($annotation->groups, $groups))) {
if ($annotation && 0 < \count(array_intersect($annotation->groups, $groups))) {
return true;
}
}
Expand All @@ -238,7 +238,7 @@ private function isRequired(\ReflectionProperty $reflectionProperty, $groups): b
private function filterOperations(array $operations, string $operation): array
{
return array_filter($operations, function ($value, $key) use ($operation) {
return $operation === (is_int($key) ? $value : $key);
return $operation === (\is_int($key) ? $value : $key);
}, ARRAY_FILTER_USE_BOTH);
}
}
2 changes: 1 addition & 1 deletion src/SchemaGenerator/ObjectSchemaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function generate(\ReflectionClass $reflectionClass, array $context = [])
if (false === ($mapping['nullable'] ?? true)) {
$schema['required'][] = $property;
} else {
if (!is_array($schema['properties'][$property]['type'])) {
if (!\is_array($schema['properties'][$property]['type'])) {
$schema['properties'][$property]['type'] = [$schema['properties'][$property]['type']];
}
$schema['properties'][$property]['type'][] = 'null';
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaGenerator/TypeGenerator/ArrayTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ArrayTypeGenerator implements TypeGeneratorInterface
{
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], [Type::TARRAY, Type::SIMPLE_ARRAY, Type::JSON_ARRAY], true);
return \in_array($mapping['type'], [Type::TARRAY, Type::SIMPLE_ARRAY, Type::JSON_ARRAY], true);
}

public function generate(array $mapping, array $context = []): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(ContainerInterface $container = null)

public function supports(array $mapping, array $context = []): bool
{
return null !== $mapping['targetEntity'] && in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY], true);
return null !== $mapping['targetEntity'] && \in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY], true);
}

public function generate(array $mapping, array $context = []): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class DateTimeTypeGenerator implements TypeGeneratorInterface
{
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], ['datetime', 'date', 'time'], true);
return \in_array($mapping['type'], ['datetime', 'date', 'time'], true);
}

public function generate(array $mapping, array $context = []): array
Expand Down
4 changes: 2 additions & 2 deletions src/SchemaGenerator/TypeGenerator/DefaultTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public function supports(array $mapping, array $context = []): bool

public function generate(array $mapping, array $context = []): array
{
if (!in_array($mapping['type'], ['integer', 'number', 'boolean', 'object', 'array', 'string', 'null', 'any'], true)) {
if (!\in_array($mapping['type'], ['integer', 'number', 'boolean', 'object', 'array', 'string', 'null', 'any'], true)) {
$mapping['type'] = 'any';
}
$type = ['type' => $mapping['type']];
if ($mapping['nullable'] ?? false) {
if (!is_array($type['type'])) {
if (!\is_array($type['type'])) {
$type['type'] = [$type['type']];
}
$type['type'][] = 'null';
Expand Down
6 changes: 3 additions & 3 deletions src/SchemaGenerator/TypeGenerator/EntityTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ public function setAnnotationReader(Reader $reader)

public function supports(array $mapping, array $context = []): bool
{
return null !== $mapping['targetEntity'] && in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE], true);
return null !== $mapping['targetEntity'] && \in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE], true);
}

public function generate(array $mapping, array $context = []): array
{
$reflectionClass = new \ReflectionClass($mapping['targetEntity']);
if (0 < count($this->propertyInfo->getProperties($mapping['targetEntity'], $context))) {
if (0 < \count($this->propertyInfo->getProperties($mapping['targetEntity'], $context))) {
$type = $this->container->get('schemaGenerator')->generate($reflectionClass, $context);
} elseif ($this->reader->getClassAnnotation($reflectionClass, ApiResource::class)) {
$type = [
Expand All @@ -73,7 +73,7 @@ public function generate(array $mapping, array $context = []): array
throw new \LogicException('Entity '.$mapping['targetEntity'].' does not have any property to serialize with following groups: '.implode(', ', $context['serializer_groups']));
}
if ($mapping['nullable'] ?? true) {
if (!is_array($type['type'])) {
if (!\is_array($type['type'])) {
$type['type'] = [$type['type']];
}
$type['type'][] = 'null';
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaGenerator/TypeGenerator/IntegerTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class IntegerTypeGenerator implements TypeGeneratorInterface
{
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], ['integer', 'smallint', 'bigint'], true);
return \in_array($mapping['type'], ['integer', 'smallint', 'bigint'], true);
}

public function generate(array $mapping, array $context = []): array
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaGenerator/TypeGenerator/NumberTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class NumberTypeGenerator implements TypeGeneratorInterface
{
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], ['int', 'float', 'decimal'], true);
return \in_array($mapping['type'], ['int', 'float', 'decimal'], true);
}

public function generate(array $mapping, array $context = []): array
Expand Down
2 changes: 1 addition & 1 deletion src/SchemaGenerator/TypeGenerator/StringTypeGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class StringTypeGenerator implements TypeGeneratorInterface
{
public function supports(array $mapping, array $context = []): bool
{
return in_array($mapping['type'], ['string', 'text'], true);
return \in_array($mapping['type'], ['string', 'text'], true);
}

public function generate(array $mapping, array $context = []): array
Expand Down
2 changes: 1 addition & 1 deletion src/ServiceContainer/ApiConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function configure($service)
$value = $this->container->get('@' === substr($value, 0, 1) ? substr($value, 1) : $value);
}
}
call_user_func([$service, $methodName], $value);
\call_user_func([$service, $methodName], $value);
}
}
}
2 changes: 1 addition & 1 deletion src/Transformer/ArrayTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class ArrayTransformer implements TransformerInterface
{
public function supports(array $mapping, $value): bool
{
return in_array($mapping['type'], [Type::TARRAY, Type::JSON_ARRAY, Type::SIMPLE_ARRAY], true) && is_string($value);
return \in_array($mapping['type'], [Type::TARRAY, Type::JSON_ARRAY, Type::SIMPLE_ARRAY], true) && \is_string($value);
}

public function toObject(array $mapping, $value): array
Expand Down
6 changes: 3 additions & 3 deletions src/Transformer/CollectionTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function setRegistry(ManagerRegistry $registry)

public function supports(array $mapping, $value): bool
{
return null !== $mapping['targetEntity'] && in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY], true);
return null !== $mapping['targetEntity'] && \in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_MANY, ClassMetadataInfo::MANY_TO_MANY], true);
}

public function toObject(array $mapping, $value): Collection
Expand All @@ -47,7 +47,7 @@ public function toObject(array $mapping, $value): Collection
return $value;
}

if (is_array($value)) {
if (\is_array($value)) {
return new ArrayCollection($value);
}

Expand All @@ -69,7 +69,7 @@ public function toObject(array $mapping, $value): Collection

public function toScalar(array $mapping, $values): array
{
if (!$values instanceof Collection && !is_array($values)) {
if (!$values instanceof Collection && !\is_array($values)) {
$values = $this->toObject($mapping, $values);
}
if ($values instanceof Collection) {
Expand Down
2 changes: 1 addition & 1 deletion src/Transformer/DateTimeTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class DateTimeTransformer implements TransformerInterface
{
public function supports(array $mapping, $value): bool
{
return in_array($mapping['type'], [Type::DATETIME, Type::DATE, Type::TIME], true);
return \in_array($mapping['type'], [Type::DATETIME, Type::DATE, Type::TIME], true);
}

public function toObject(array $mapping, $value): \DateTime
Expand Down
8 changes: 4 additions & 4 deletions src/Transformer/EntityTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function setIriConverter(IriConverterInterface $iriConverter)

public function supports(array $mapping, $value): bool
{
return null !== $mapping['targetEntity'] && in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE], true);
return null !== $mapping['targetEntity'] && \in_array($mapping['type'], [ClassMetadataInfo::ONE_TO_ONE, ClassMetadataInfo::MANY_TO_ONE], true);
}

public function toObject(array $mapping, $value)
Expand Down Expand Up @@ -83,7 +83,7 @@ public function toObject(array $mapping, $value)
$type = 'integer';
break;
}
if (gettype($value) === $type) {
if (\gettype($value) === $type) {
$queryBuilder->orWhere("o.$fieldName = :query")->setParameter('query', $value);
}
}
Expand All @@ -93,10 +93,10 @@ public function toObject(array $mapping, $value)

public function toScalar(array $mapping, $value)
{
if (is_array($value)) {
if (\is_array($value)) {
return $value;
}
if (!is_object($value)) {
if (!\is_object($value)) {
$value = $this->toObject($mapping, $value);
if (null === $value) {
throw new EntityNotFoundException(sprintf('Unable to find an existing object of class %s with any value equal to %s.', $mapping['targetEntity'], $value));
Expand Down
2 changes: 1 addition & 1 deletion src/Transformer/IntegerTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class IntegerTransformer implements TransformerInterface
{
public function supports(array $mapping, $value): bool
{
return in_array($mapping['type'], ['int', Type::INTEGER, Type::SMALLINT, Type::BIGINT], true);
return \in_array($mapping['type'], ['int', Type::INTEGER, Type::SMALLINT, Type::BIGINT], true);
}

public function toObject(array $mapping, $value): int
Expand Down
2 changes: 1 addition & 1 deletion src/Transformer/StringTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ final class StringTransformer implements TransformerInterface
{
public function supports(array $mapping, $value): bool
{
return in_array($mapping['type'], [Type::STRING, Type::TEXT], true);
return \in_array($mapping['type'], [Type::STRING, Type::TEXT], true);
}

public function toObject(array $mapping, $value): string
Expand Down

0 comments on commit a0109b3

Please sign in to comment.