Skip to content

Commit

Permalink
Merge pull request #2014 from doctrine/chore/coding-standard
Browse files Browse the repository at this point in the history
Update to doctrine/cs v6
  • Loading branch information
alcaeus committed Jul 12, 2019
2 parents 85c5ae3 + 5ac9e08 commit c0f1d08
Show file tree
Hide file tree
Showing 85 changed files with 337 additions and 58 deletions.
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -36,7 +36,7 @@
"symfony/var-dumper": "^3.4|^4.1"
},
"require-dev": {
"doctrine/coding-standard": "^5.0",
"doctrine/coding-standard": "^6.0",
"jmikola/geojson": "^1.0",
"phpstan/phpstan": "^0.10.3",
"phpunit/phpunit": "^8.2"
Expand Down
13 changes: 9 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php
Expand Up @@ -323,7 +323,9 @@ public static function convertExpression($expression)
return array_map(static function ($expression) {
return static::convertExpression($expression);
}, $expression);
} elseif ($expression instanceof self) {
}

if ($expression instanceof self) {
return $expression->getExpression();
}

Expand Down Expand Up @@ -1545,7 +1547,6 @@ public function zip($inputs, ?bool $useLongestLength = null, $defaults = null) :
return $this->operator('$zip', $args);
}


/**
* @param mixed|self $expression
*
Expand All @@ -1555,9 +1556,13 @@ private function ensureArray($expression)
{
if (is_string($expression) && substr($expression, 0, 1) === '$') {
return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
} elseif (is_array($expression)) {
}

if (is_array($expression)) {
return array_map([$this, 'ensureArray'], $expression);
} elseif ($expression instanceof self) {
}

if ($expression instanceof self) {
return $expression->getExpression();
}

Expand Down
Expand Up @@ -85,7 +85,9 @@ private function convertExpression($expression)
{
if (is_array($expression)) {
return array_map([$this, 'convertExpression'], $expression);
} elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
}

if (is_string($expression) && substr($expression, 0, 1) === '$') {
return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Bucket.php
Expand Up @@ -31,6 +31,7 @@ class Bucket extends AbstractBucket
public function boundaries(...$boundaries) : self
{
$this->boundaries = $boundaries;

return $this;
}

Expand All @@ -44,6 +45,7 @@ public function boundaries(...$boundaries) : self
public function defaultBucket($default) : self
{
$this->default = $default;

return $this;
}

Expand All @@ -59,6 +61,7 @@ public function output() : Bucket\BucketOutput
}

assert($this->output instanceof Bucket\BucketOutput);

return $this->output;
}

Expand Down
Expand Up @@ -25,6 +25,7 @@ public function __construct(Builder $builder, Stage\BucketAuto $bucket)
public function groupBy($expression) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);

return $this->bucket->groupBy($expression);
}

Expand All @@ -34,6 +35,7 @@ public function groupBy($expression) : Stage\BucketAuto
public function buckets(int $buckets) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);

return $this->bucket->buckets($buckets);
}

Expand All @@ -45,6 +47,7 @@ public function buckets(int $buckets) : Stage\BucketAuto
public function granularity(string $granularity) : Stage\BucketAuto
{
assert($this->bucket instanceof Stage\BucketAuto);

return $this->bucket->granularity($granularity);
}
}
Expand Up @@ -30,6 +30,7 @@ public function __construct(Builder $builder, Stage\Bucket $bucket)
public function groupBy($expression)
{
assert($this->bucket instanceof Stage\Bucket);

return $this->bucket->groupBy($expression);
}

Expand All @@ -49,6 +50,7 @@ public function groupBy($expression)
public function boundaries(...$boundaries)
{
assert($this->bucket instanceof Stage\Bucket);

return $this->bucket->boundaries(...$boundaries);
}

Expand All @@ -64,6 +66,7 @@ public function boundaries(...$boundaries)
public function defaultBucket($default)
{
assert($this->bucket instanceof Stage\Bucket);

return $this->bucket->defaultBucket($default);
}
}
3 changes: 3 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/BucketAuto.php
Expand Up @@ -24,6 +24,7 @@ class BucketAuto extends AbstractBucket
public function buckets(int $buckets) : self
{
$this->buckets = $buckets;

return $this;
}

Expand All @@ -35,6 +36,7 @@ public function buckets(int $buckets) : self
public function granularity(string $granularity) : self
{
$this->granularity = $granularity;

return $this;
}

Expand All @@ -50,6 +52,7 @@ public function output() : Bucket\BucketAutoOutput
}

assert($this->output instanceof Bucket\BucketAutoOutput);

return $this->output;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Facet.php
Expand Up @@ -39,6 +39,7 @@ public function getExpression() : array
public function field(string $field) : self
{
$this->field = $field;

return $this;
}

Expand All @@ -62,6 +63,7 @@ public function pipeline($builder) : self
}

$this->pipelines[$this->field] = $builder;

return $this;
}
}
12 changes: 9 additions & 3 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php
Expand Up @@ -93,12 +93,14 @@ public function connectFromField(string $connectFromField) : self
// No targetClass mapping - simply use field name as is
if (! $this->targetClass) {
$this->connectFromField = $connectFromField;

return $this;
}

// connectFromField doesn't have to be a reference - in this case, just convert the field name
if (! $this->targetClass->hasReference($connectFromField)) {
$this->connectFromField = $this->convertTargetFieldName($connectFromField);

return $this;
}

Expand All @@ -109,6 +111,7 @@ public function connectFromField(string $connectFromField) : self
}

$this->connectFromField = $this->getReferencedFieldName($connectFromField, $referenceMapping);

return $this;
}

Expand All @@ -119,6 +122,7 @@ public function connectFromField(string $connectFromField) : self
public function connectToField(string $connectToField) : self
{
$this->connectToField = $this->convertTargetFieldName($connectToField);

return $this;
}

Expand Down Expand Up @@ -159,6 +163,7 @@ public function from(string $from) : self
$this->targetClass = $this->dm->getClassMetadata($from);
} catch (BaseMappingException $e) {
$this->from = $from;

return $this;
}

Expand All @@ -167,6 +172,7 @@ public function from(string $from) : self
}

$this->from = $this->targetClass->getCollection();

return $this;
}

Expand Down Expand Up @@ -274,7 +280,9 @@ private function convertExpression($expression)
{
if (is_array($expression)) {
return array_map([$this, 'convertExpression'], $expression);
} elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
}

if (is_string($expression) && substr($expression, 0, 1) === '$') {
return '$' . $this->getDocumentPersister($this->class)->prepareFieldName(substr($expression, 1));
}

Expand Down Expand Up @@ -317,8 +325,6 @@ private function getReferencedFieldName(string $fieldName, array $mapping) : str
case ClassMetadata::REFERENCE_STORE_AS_ID:
case ClassMetadata::REFERENCE_STORE_AS_REF:
return ClassMetadata::getReferenceFieldName($mapping['storeAs'], $mapping['name']);
break;

default:
throw MappingException::cannotLookupDbRefReference($this->class->name, $fieldName);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Lookup.php
Expand Up @@ -83,6 +83,7 @@ public function from(string $from) : self
$this->targetClass = $this->dm->getClassMetadata($from);
} catch (BaseMappingException $e) {
$this->from = $from;

return $this;
}

Expand All @@ -91,6 +92,7 @@ public function from(string $from) : self
}

$this->from = $this->targetClass->getCollection();

return $this;
}

Expand Down Expand Up @@ -120,6 +122,7 @@ public function getExpression() : array
public function localField(string $localField) : self
{
$this->localField = $this->prepareFieldName($localField, $this->class);

return $this;
}

Expand All @@ -134,6 +137,7 @@ public function localField(string $localField) : self
public function foreignField(string $foreignField) : self
{
$this->foreignField = $this->prepareFieldName($foreignField, $this->targetClass);

return $this;
}

Expand Down
2 changes: 2 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Stage/Out.php
Expand Up @@ -46,10 +46,12 @@ public function out(string $collection) : Stage\Out
$class = $this->dm->getClassMetadata($collection);
} catch (BaseMappingException $e) {
$this->collection = $collection;

return $this;
}

$this->fromDocument($class);

return $this;
}

Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/ReplaceRoot.php
Expand Up @@ -49,7 +49,9 @@ private function convertExpression($expression)
{
if (is_array($expression)) {
return array_map([$this, 'convertExpression'], $expression);
} elseif (is_string($expression) && substr($expression, 0, 1) === '$') {
}

if (is_string($expression) && substr($expression, 0, 1) === '$') {
return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1));
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Doctrine/ODM/MongoDB/Configuration.php
Expand Up @@ -339,6 +339,7 @@ public function getClassMetadataFactoryName() : string
if (! isset($this->attributes['classMetadataFactoryName'])) {
$this->attributes['classMetadataFactoryName'] = ClassMetadataFactory::class;
}

return $this->attributes['classMetadataFactoryName'];
}

Expand Down Expand Up @@ -435,6 +436,7 @@ public function getPersistentCollectionFactory() : PersistentCollectionFactory
if (! isset($this->attributes['persistentCollectionFactory'])) {
$this->attributes['persistentCollectionFactory'] = new DefaultPersistentCollectionFactory();
}

return $this->attributes['persistentCollectionFactory'];
}

Expand All @@ -459,6 +461,7 @@ public function getPersistentCollectionGenerator() : PersistentCollectionGenerat
$this->getPersistentCollectionNamespace()
);
}

return $this->attributes['persistentCollectionGenerator'];
}

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/DocumentManager.php
Expand Up @@ -510,6 +510,7 @@ public function merge($document)
throw new InvalidArgumentException(gettype($document));
}
$this->errorIfClosed();

return $this->unitOfWork->merge($document);
}

Expand Down Expand Up @@ -678,6 +679,7 @@ public function contains($document)
if (! is_object($document)) {
throw new InvalidArgumentException(gettype($document));
}

return $this->unitOfWork->isScheduledForInsert($document) ||
$this->unitOfWork->isInIdentityMap($document) &&
! $this->unitOfWork->isScheduledForDelete($document);
Expand Down Expand Up @@ -718,8 +720,6 @@ public function createReference(object $document, array $referenceMapping)
}

return $class->getDatabaseIdentifierValue($id);
break;

case ClassMetadata::REFERENCE_STORE_AS_REF:
$reference = ['id' => $class->getDatabaseIdentifierValue($id)];
break;
Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/MongoDB/Event/LifecycleEventArgs.php
Expand Up @@ -23,6 +23,7 @@ public function getDocumentManager() : DocumentManager
{
$dm = $this->getObjectManager();
assert($dm instanceof DocumentManager);

return $dm;
}
}
Expand Up @@ -17,6 +17,7 @@ public function getDocumentManager() : DocumentManager
{
$dm = $this->getObjectManager();
assert($dm instanceof DocumentManager);

return $dm;
}
}
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/MongoDB/Event/ManagerEventArgs.php
Expand Up @@ -17,6 +17,7 @@ public function getDocumentManager() : DocumentManager
{
$dm = $this->getObjectManager();
assert($dm instanceof DocumentManager);

return $dm;
}
}
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/MongoDB/Event/OnClearEventArgs.php
Expand Up @@ -17,6 +17,7 @@ public function getDocumentManager() : DocumentManager
{
$dm = $this->getObjectManager();
assert($dm instanceof DocumentManager);

return $dm;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php
Expand Up @@ -152,6 +152,7 @@ public function getHydratorFor(string $className) : HydratorInterface
}
}
$this->hydrators[$className] = new $fqn($this->dm, $this->unitOfWork, $class);

return $this->hydrators[$className];
}

Expand Down
1 change: 1 addition & 0 deletions lib/Doctrine/ODM/MongoDB/Id/UuidGenerator.php
Expand Up @@ -69,6 +69,7 @@ public function isValid(string $uuid) : bool
public function generate(DocumentManager $dm, object $document)
{
$uuid = $this->generateV4();

return $this->generateV5($uuid, $this->salt ?: php_uname('n'));
}

Expand Down

0 comments on commit c0f1d08

Please sign in to comment.