Skip to content

Commit

Permalink
Bump CS (#1249)
Browse files Browse the repository at this point in the history
* Upgrade Doctrine CS to v8.1
  • Loading branch information
simPod authored Sep 17, 2020
1 parent 0edb562 commit 8390baf
Show file tree
Hide file tree
Showing 73 changed files with 301 additions and 197 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"require-dev": {
"ext-pdo_sqlite": "*",
"doctrine/coding-standard": "^5.0",
"doctrine/coding-standard": "^8.1",
"doctrine/orm": "~2.1",
"doctrine/persistence": "^1.3.3|^2.0|^3.0",
"doctrine/phpcr-odm": "^1.3|^2.0",
Expand Down
22 changes: 7 additions & 15 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@
<exclude name="Squiz.Arrays.ArrayDeclaration.KeySpecified"/>
<exclude name="Squiz.Commenting.FunctionComment.SpacingAfterParamType"/>

<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousExceptionNaming.SuperfluousSuffix"/>
<exclude name="SlevomatCodingStandard.Classes.SuperfluousTraitNaming.SuperfluousSuffix"/>

<exclude name="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison.DisallowedYodaComparison"/>
<exclude name="SlevomatCodingStandard.ControlStructures.AssignmentInCondition.AssignmentInCondition"/>
<exclude name="SlevomatCodingStandard.ControlStructures.EarlyExit"/>

<exclude name="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/>

<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
</rule>

<rule ref="SlevomatCodingStandard.ControlStructures.RequireYodaComparison"/>
Expand Down Expand Up @@ -72,12 +73,6 @@
</properties>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing">
<properties>
<property name="spacesCountBeforeColon" value="0"/>
</properties>
</rule>

<rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
Expand All @@ -90,9 +85,6 @@
<exclude-pattern>tests/*</exclude-pattern>
</rule>

<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements">
<exclude-pattern>tests/*</exclude-pattern>
</rule>
Expand Down
6 changes: 4 additions & 2 deletions src/Accessor/DefaultAccessorStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ public function __construct(?ExpressionEvaluatorInterface $evaluator = null)
$this->evaluator = $evaluator;
}


/**
* {@inheritdoc}
*/
Expand Down Expand Up @@ -86,7 +85,7 @@ public function getValue(object $object, PropertyMetadata $metadata, Serializati

$accessor = $this->readAccessors[$metadata->class] ?? null;
if (null === $accessor) {
$accessor =\Closure::bind(static function ($o, $name) {
$accessor = \Closure::bind(static function ($o, $name) {
return $o->$name;
}, null, $metadata->class);
$this->readAccessors[$metadata->class] = $accessor;
Expand All @@ -106,6 +105,7 @@ public function setValue(object $object, $value, PropertyMetadata $metadata, Des

if (null !== $metadata->setter) {
$object->{$metadata->setter}($value);

return;
}

Expand All @@ -118,6 +118,7 @@ public function setValue(object $object, $value, PropertyMetadata $metadata, Des
}

$ref->setValue($object, $value);

return;
}

Expand All @@ -128,6 +129,7 @@ public function setValue(object $object, $value, PropertyMetadata $metadata, Des
}, null, $metadata->class);
$this->writeAccessors[$metadata->class] = $accessor;
}

$accessor($object, $metadata->name, $value);
}
}
1 change: 1 addition & 0 deletions src/Annotation/VirtualProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function __construct(array $data)
if (!property_exists(self::class, $key)) {
throw new InvalidArgumentException(sprintf('Unknown property "%s" on annotation "%s".', $key, self::class));
}

$this->{$key} = $value;
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/Construction/DoctrineObjectConstructor.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public function construct(DeserializationVisitorInterface $visitor, ClassMetadat
if (!isset($metadata->propertyMetadata[$name])) {
return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
}

$propertyMetadata = $metadata->propertyMetadata[$name];

// Avoid calling objectManager->find if some identification properties are excluded by some exclusion strategy
Expand All @@ -103,6 +104,7 @@ public function construct(DeserializationVisitorInterface $visitor, ClassMetadat
if (!array_key_exists($propertyMetadata->serializedName, $data)) {
return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);
}

$identifierList[$name] = $data[$propertyMetadata->serializedName];
}

Expand All @@ -119,10 +121,13 @@ public function construct(DeserializationVisitorInterface $visitor, ClassMetadat
switch ($this->fallbackStrategy) {
case self::ON_MISSING_NULL:
return null;

case self::ON_MISSING_EXCEPTION:
throw new ObjectConstructionException(sprintf('Entity %s can not be found', $metadata->name));

case self::ON_MISSING_FALLBACK:
return $this->fallbackConstructor->construct($visitor, $metadata, $data, $type, $context);

default:
throw new InvalidArgumentException('The provided fallback strategy for the object constructor is not valid');
}
Expand Down
2 changes: 2 additions & 0 deletions src/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,13 @@ public function addExclusionStrategy(ExclusionStrategyInterface $strategy): self

if (null === $this->exclusionStrategy) {
$this->exclusionStrategy = $strategy;

return $this;
}

if ($this->exclusionStrategy instanceof DisjunctExclusionStrategy) {
$this->exclusionStrategy->addStrategy($strategy);

return $this;
}

Expand Down
3 changes: 0 additions & 3 deletions src/ContextFactory/CallableDeserializationContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
final class CallableDeserializationContextFactory extends CallableContextFactory implements
DeserializationContextFactoryInterface
{
/**
* {@InheritDoc}
*/
public function createDeserializationContext(): DeserializationContext
{
return $this->createContext();
Expand Down
3 changes: 0 additions & 3 deletions src/ContextFactory/CallableSerializationContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
final class CallableSerializationContextFactory extends CallableContextFactory implements
SerializationContextFactoryInterface
{
/**
* {@InheritDoc}
*/
public function createSerializationContext(): SerializationContext
{
return $this->createContext();
Expand Down
3 changes: 0 additions & 3 deletions src/ContextFactory/DefaultDeserializationContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
final class DefaultDeserializationContextFactory implements DeserializationContextFactoryInterface
{
/**
* {@InheritDoc}
*/
public function createDeserializationContext(): DeserializationContext
{
return new DeserializationContext();
Expand Down
3 changes: 0 additions & 3 deletions src/ContextFactory/DefaultSerializationContextFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
*/
final class DefaultSerializationContextFactory implements SerializationContextFactoryInterface
{
/**
* {@InheritDoc}
*/
public function createSerializationContext(): SerializationContext
{
return new SerializationContext();
Expand Down
3 changes: 2 additions & 1 deletion src/EventDispatcher/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function dispatch(string $eventName, string $class, string $format, Event

$object = $event instanceof ObjectEvent ? $event->getObject() : null;
$realClass = is_object($object) ? get_class($object) : '';
$objectClass = $realClass !== $class ? ($realClass . $class) : $class;
$objectClass = $realClass !== $class ? $realClass . $class : $class;

if (!isset($this->classListeners[$eventName][$objectClass][$format])) {
$this->classListeners[$eventName][$objectClass][$format] = $this->initializeListeners($eventName, $class, $format);
Expand Down Expand Up @@ -119,6 +119,7 @@ protected function initializeListeners(string $eventName, string $loweredClass,
if (null !== $listener[1] && $loweredClass !== $listener[1]) {
continue;
}

if (null !== $listener[2] && $format !== $listener[2]) {
continue;
}
Expand Down
6 changes: 4 additions & 2 deletions src/EventDispatcher/Subscriber/DoctrineProxySubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function onPreSerialize(PreSerializeEvent $event): void
// so it must be loaded if its a real class.
$virtualType = !class_exists($type['name'], false);

if ($object instanceof PersistentCollection
if (
$object instanceof PersistentCollection
|| $object instanceof MongoDBPersistentCollection
|| $object instanceof PHPCRPersistentCollection
) {
Expand All @@ -53,7 +54,8 @@ public function onPreSerialize(PreSerializeEvent $event): void
return;
}

if (($this->skipVirtualTypeInit && $virtualType) ||
if (
($this->skipVirtualTypeInit && $virtualType) ||
(!$object instanceof Proxy && !$object instanceof LazyLoadingInterface)
) {
return;
Expand Down
6 changes: 0 additions & 6 deletions src/Exclusion/DepthExclusionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,11 @@
*/
final class DepthExclusionStrategy implements ExclusionStrategyInterface
{
/**
* {@inheritDoc}
*/
public function shouldSkipClass(ClassMetadata $metadata, Context $context): bool
{
return $this->isTooDeep($context);
}

/**
* {@inheritDoc}
*/
public function shouldSkipProperty(PropertyMetadata $property, Context $context): bool
{
return $this->isTooDeep($context);
Expand Down
4 changes: 2 additions & 2 deletions src/Exclusion/DisjunctExclusionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function addStrategy(ExclusionStrategyInterface $strategy): void
public function shouldSkipClass(ClassMetadata $metadata, Context $context): bool
{
foreach ($this->delegates as $delegate) {
/** @var $delegate ExclusionStrategyInterface */
\assert($delegate instanceof ExclusionStrategyInterface);
if ($delegate->shouldSkipClass($metadata, $context)) {
return true;
}
Expand All @@ -56,7 +56,7 @@ public function shouldSkipClass(ClassMetadata $metadata, Context $context): bool
public function shouldSkipProperty(PropertyMetadata $property, Context $context): bool
{
foreach ($this->delegates as $delegate) {
/** @var $delegate ExclusionStrategyInterface */
\assert($delegate instanceof ExclusionStrategyInterface);
if ($delegate->shouldSkipProperty($property, $context)) {
return true;
}
Expand Down
7 changes: 0 additions & 7 deletions src/Exclusion/ExpressionLanguageExclusionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ public function __construct(ExpressionEvaluatorInterface $expressionEvaluator)
$this->expressionEvaluator = $expressionEvaluator;
}


/**
* {@inheritDoc}
*/
public function shouldSkipClass(ClassMetadata $class, Context $navigatorContext): bool
{
if (null === $class->excludeIf) {
Expand All @@ -59,9 +55,6 @@ public function shouldSkipClass(ClassMetadata $class, Context $navigatorContext)
return $this->expressionEvaluator->evaluate($class->excludeIf, $variables);
}

/**
* {@inheritDoc}
*/
public function shouldSkipProperty(PropertyMetadata $property, Context $navigatorContext): bool
{
if (null === $property->excludeIf) {
Expand Down
10 changes: 4 additions & 6 deletions src/Exclusion/GroupsExclusionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,11 @@ public function __construct(array $groups)
}
}

/**
* {@inheritDoc}
*/
public function shouldSkipClass(ClassMetadata $metadata, Context $navigatorContext): bool
{
return false;
}

/**
* {@inheritDoc}
*/
public function shouldSkipProperty(PropertyMetadata $property, Context $navigatorContext): bool
{
if ($this->nestedGroups) {
Expand All @@ -75,6 +69,7 @@ public function shouldSkipProperty(PropertyMetadata $property, Context $navigato
return false;
}
}

return true;
}
}
Expand Down Expand Up @@ -103,13 +98,16 @@ public function getGroupsFor(Context $navigatorContext): array
if ($index > 0) {
$groups = [self::DEFAULT_GROUP];
}

break;
}

$groups = $groups[$path];
if (!array_filter($groups, 'is_string')) {
$groups += [self::DEFAULT_GROUP];
}
}

return $groups;
}
}
12 changes: 1 addition & 11 deletions src/Exclusion/VersionExclusionStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,17 @@ public function __construct(string $version)
$this->version = $version;
}

/**
* {@inheritDoc}
*/
public function shouldSkipClass(ClassMetadata $metadata, Context $navigatorContext): bool
{
return false;
}

/**
* {@inheritDoc}
*/
public function shouldSkipProperty(PropertyMetadata $property, Context $navigatorContext): bool
{
if ((null !== $version = $property->sinceVersion) && version_compare($this->version, $version, '<')) {
return true;
}

if ((null !== $version = $property->untilVersion) && version_compare($this->version, $version, '>')) {
return true;
}

return false;
return (null !== $version = $property->untilVersion) && version_compare($this->version, $version, '>');
}
}
4 changes: 3 additions & 1 deletion src/GraphNavigator/DeserializationGraphNavigator.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public function accept($data, ?array $type = null)
if (null === $type) {
throw new RuntimeException('The type must be given for all properties when deserializing.');
}

// Sometimes data can convey null but is not of a null type.
// Visitors can have the power to add this custom null evaluation
if ($this->visitor instanceof NullAwareVisitorInterface && true === $this->visitor->isNull($data)) {
Expand Down Expand Up @@ -167,8 +168,8 @@ public function accept($data, ?array $type = null)
}
}

/** @var ClassMetadata $metadata */
$metadata = $this->metadataFactory->getMetadataForClass($type['name']);
\assert($metadata instanceof ClassMetadata);

if ($metadata->usingExpression && !$this->expressionExclusionStrategy) {
throw new ExpressionLanguageRequiredException(sprintf('To use conditional exclude/expose in %s you must configure the expression language.', $metadata->name));
Expand Down Expand Up @@ -215,6 +216,7 @@ public function accept($data, ?array $type = null)
$this->accessor->setValue($object, $v, $propertyMetadata, $this->context);
} catch (NotAcceptableException $e) {
}

$this->context->popPropertyMetadata();
}

Expand Down
Loading

0 comments on commit 8390baf

Please sign in to comment.