Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Null Coalesce Operator #1692

Merged
merged 1 commit into from
Dec 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/DocumentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -674,7 +674,7 @@ public function createReference($document, array $referenceMapping)
);
}

$storeAs = isset($referenceMapping['storeAs']) ? $referenceMapping['storeAs'] : null;
$storeAs = $referenceMapping['storeAs'] ?? null;
switch ($storeAs) {
case ClassMetadataInfo::REFERENCE_STORE_AS_ID:
if ($class->inheritanceType === ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_COLLECTION) {
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -1110,9 +1110,9 @@ public function setCollection($name)
if ( ! isset($name['name'])) {
throw new \InvalidArgumentException('A name key is required when passing an array to setCollection()');
}
$this->collectionCapped = isset($name['capped']) ? $name['capped'] : false;
$this->collectionSize = isset($name['size']) ? $name['size'] : 0;
$this->collectionMax = isset($name['max']) ? $name['max'] : 0;
$this->collectionCapped = $name['capped'] ?? false;
$this->collectionSize = $name['size'] ?? 0;
$this->collectionMax = $name['max'] ?? 0;
$this->collection = $name['name'];
} else {
$this->collection = $name;
Expand Down Expand Up @@ -1270,7 +1270,7 @@ public function mapField(array $mapping)
if (isset($mapping['strategy'])) {
$this->generatorType = constant(ClassMetadata::class . '::GENERATOR_TYPE_' . strtoupper($mapping['strategy']));
}
$this->generatorOptions = isset($mapping['options']) ? $mapping['options'] : array();
$this->generatorOptions = $mapping['options'] ?? array();
switch ($this->generatorType) {
case self::GENERATOR_TYPE_AUTO:
$mapping['type'] = 'id';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)

if ($indexes) {
foreach ($indexes as $index) {
$name = isset($mapping['name']) ? $mapping['name'] : $mapping['fieldName'];
$name = $mapping['name'] ?? $mapping['fieldName'];
$keys = array($name => $index->order ?: 'asc');
$this->addIndex($class, $index, $keys);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ private function addFieldMapping(ClassMetadataInfo $class, $mapping)
return;
}

$keys = array($name => isset($mapping['order']) ? $mapping['order'] : 'asc');
$keys = array($name => $mapping['order'] ?? 'asc');
$options = array();

if (isset($mapping['background'])) {
Expand Down
22 changes: 11 additions & 11 deletions lib/Doctrine/ODM/MongoDB/Mapping/Driver/YamlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
if ( ! $element) {
return;
}
$element['type'] = isset($element['type']) ? $element['type'] : 'document';
$element['type'] = $element['type'] ?? 'document';

if (isset($element['db'])) {
$class->setDatabase($element['db']);
Expand All @@ -51,7 +51,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}
$class->setReadPreference(
$element['readPreference']['mode'],
isset($element['readPreference']['tagSets']) ? $element['readPreference']['tagSets'] : null
$element['readPreference']['tagSets'] ?? null
);
}
if (isset($element['writeConcern'])) {
Expand All @@ -63,7 +63,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}
} elseif ($element['type'] === 'mappedSuperclass') {
$class->setCustomRepositoryClass(
isset($element['repositoryClass']) ? $element['repositoryClass'] : null
$element['repositoryClass'] ?? null
);
$class->isMappedSuperclass = true;
} elseif ($element['type'] === 'embeddedDocument') {
Expand All @@ -73,7 +73,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
}
if (isset($element['indexes'])) {
foreach($element['indexes'] as $index) {
$class->addIndex($index['keys'], isset($index['options']) ? $index['options'] : array());
$class->addIndex($index['keys'], $index['options'] ?? array());
}
}
if (isset($element['shardKey'])) {
Expand Down Expand Up @@ -238,8 +238,8 @@ private function addMappingFromEmbed(ClassMetadataInfo $class, $fieldName, $embe
$mapping = array(
'type' => $type,
'embedded' => true,
'targetDocument' => isset($embed['targetDocument']) ? $embed['targetDocument'] : null,
'collectionClass' => isset($embed['collectionClass']) ? $embed['collectionClass'] : null,
'targetDocument' => $embed['targetDocument'] ?? null,
'collectionClass' => $embed['collectionClass'] ?? null,
'fieldName' => $fieldName,
'strategy' => isset($embed['strategy']) ? (string) $embed['strategy'] : $defaultStrategy,
);
Expand All @@ -262,21 +262,21 @@ private function addMappingFromReference(ClassMetadataInfo $class, $fieldName, $
{
$defaultStrategy = $type == 'one' ? ClassMetadataInfo::STORAGE_STRATEGY_SET : CollectionHelper::DEFAULT_STRATEGY;
$mapping = array(
'cascade' => isset($reference['cascade']) ? $reference['cascade'] : [],
'orphanRemoval' => isset($reference['orphanRemoval']) ? $reference['orphanRemoval'] : false,
'cascade' => $reference['cascade'] ?? [],
'orphanRemoval' => $reference['orphanRemoval'] ?? false,
'type' => $type,
'reference' => true,
'storeAs' => isset($reference['storeAs']) ? (string) $reference['storeAs'] : ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF,
'targetDocument' => isset($reference['targetDocument']) ? $reference['targetDocument'] : null,
'collectionClass' => isset($reference['collectionClass']) ? $reference['collectionClass'] : null,
'targetDocument' => $reference['targetDocument'] ?? null,
'collectionClass' => $reference['collectionClass'] ?? null,
'fieldName' => $fieldName,
'strategy' => isset($reference['strategy']) ? (string) $reference['strategy'] : $defaultStrategy,
'inversedBy' => isset($reference['inversedBy']) ? (string) $reference['inversedBy'] : null,
'mappedBy' => isset($reference['mappedBy']) ? (string) $reference['mappedBy'] : null,
'repositoryMethod' => isset($reference['repositoryMethod']) ? (string) $reference['repositoryMethod'] : null,
'limit' => isset($reference['limit']) ? (integer) $reference['limit'] : null,
'skip' => isset($reference['skip']) ? (integer) $reference['skip'] : null,
'prime' => isset($reference['prime']) ? $reference['prime'] : [],
'prime' => $reference['prime'] ?? [],
);
if (isset($reference['name'])) {
$mapping['name'] = $reference['name'];
Expand Down
8 changes: 4 additions & 4 deletions lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ private function loadReferenceManyCollectionOwningSide(PersistentCollectionInter
$criteria = $this->cm->merge(
array('_id' => array('$in' => array_values($ids))),
$this->dm->getFilterCollection()->getFilterCriteria($class),
isset($mapping['criteria']) ? $mapping['criteria'] : array()
$mapping['criteria'] ?? array()
);
$criteria = $this->uow->getDocumentPersister($className)->prepareQueryOrNewObj($criteria);

Expand Down Expand Up @@ -797,12 +797,12 @@ public function createReferenceManyInverseSideQuery(PersistentCollectionInterfac
$ownerClass = $this->dm->getClassMetadata(get_class($owner));
$targetClass = $this->dm->getClassMetadata($mapping['targetDocument']);
$mappedByMapping = isset($targetClass->fieldMappings[$mapping['mappedBy']]) ? $targetClass->fieldMappings[$mapping['mappedBy']] : array();
$mappedByFieldName = ClassMetadataInfo::getReferenceFieldName(isset($mappedByMapping['storeAs']) ? $mappedByMapping['storeAs'] : ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF, $mapping['mappedBy']);
$mappedByFieldName = ClassMetadataInfo::getReferenceFieldName($mappedByMapping['storeAs'] ?? ClassMetadataInfo::REFERENCE_STORE_AS_DB_REF, $mapping['mappedBy']);

$criteria = $this->cm->merge(
array($mappedByFieldName => $ownerClass->getIdentifierObject($owner)),
$this->dm->getFilterCollection()->getFilterCriteria($targetClass),
isset($mapping['criteria']) ? $mapping['criteria'] : array()
$mapping['criteria'] ?? array()
);
$criteria = $this->uow->getDocumentPersister($mapping['targetDocument'])->prepareQueryOrNewObj($criteria);
$qb = $this->dm->createQueryBuilder($mapping['targetDocument'])
Expand Down Expand Up @@ -1041,7 +1041,7 @@ public function prepareQueryOrNewObj(array $query, $isNewObj = false)
*/
private function prepareQueryElement($fieldName, $value = null, $class = null, $prepareValue = true, $inNewObj = false)
{
$class = isset($class) ? $class : $this->class;
$class = $class ?? $this->class;

// @todo Consider inlining calls to ClassMetadataInfo methods

Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ODM/MongoDB/Persisters/PersistenceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function prepareInsertData($document)
$insertData = array();
foreach ($class->fieldMappings as $mapping) {

$new = isset($changeset[$mapping['fieldName']][1]) ? $changeset[$mapping['fieldName']][1] : null;
$new = $changeset[$mapping['fieldName']][1] ?? null;

if ($new === null && $mapping['nullable']) {
$insertData[$mapping['name']] = null;
Expand Down Expand Up @@ -331,7 +331,7 @@ public function prepareEmbeddedDocumentValue(array $embeddedMapping, $embeddedDo
$value = null;

if ($rawValue !== null) {
switch (isset($mapping['association']) ? $mapping['association'] : null) {
switch ($mapping['association'] ?? null) {
// @Field, @String, @Date, etc.
case null:
$value = Type::getType($mapping['type'])->convertToDatabaseValue($rawValue);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Query/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -1380,7 +1380,7 @@ public function type($type)
'minkey' => 255,
];

$type = isset($map[$type]) ? $map[$type] : $type;
$type = $map[$type] ?? $type;
}

return $this->operator('$type', $type);
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ private function renameQueryOptions(array $options, array $rename)

return array_combine(
array_map(
function($key) use ($rename) { return isset($rename[$key]) ? $rename[$key] : $key; },
function($key) use ($rename) { return $rename[$key] ?? $key; },
array_keys($options)
),
array_values($options)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'Created <comment>%s%s</comment> for <info>%s</info>',
$option,
(isset($class) ? (self::INDEX === $option ? '(es)' : '') : (self::INDEX === $option ? 'es' : 's')),
(isset($class) ? $class : 'all classes')
($class ?? 'all classes')
));
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
'Dropped <comment>%s%s</comment> for <info>%s</info>',
$option,
(isset($class) ? (self::INDEX === $option ? '(es)' : '') : (self::INDEX === $option ? 'es' : 's')),
(isset($class) ? $class : 'all classes')
($class ?? 'all classes')
));
} catch (\Exception $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
Expand Down
12 changes: 6 additions & 6 deletions lib/Doctrine/ODM/MongoDB/Tools/DocumentGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -664,17 +664,17 @@ private function generateDocumentStubMethods(ClassMetadataInfo $metadata)
}
} elseif ($fieldMapping['type'] === ClassMetadataInfo::ONE) {
$nullable = $this->isAssociationNullable($fieldMapping) ? 'null' : null;
if ($code = $this->generateDocumentStubMethod($metadata, 'set', $fieldMapping['fieldName'], isset($fieldMapping['targetDocument']) ? $fieldMapping['targetDocument'] : null, $nullable)) {
if ($code = $this->generateDocumentStubMethod($metadata, 'set', $fieldMapping['fieldName'], $fieldMapping['targetDocument'] ?? null, $nullable)) {
$methods[] = $code;
}
if ($code = $this->generateDocumentStubMethod($metadata, 'get', $fieldMapping['fieldName'], isset($fieldMapping['targetDocument']) ? $fieldMapping['targetDocument'] : null)) {
if ($code = $this->generateDocumentStubMethod($metadata, 'get', $fieldMapping['fieldName'], $fieldMapping['targetDocument'] ?? null)) {
$methods[] = $code;
}
} elseif ($fieldMapping['type'] === ClassMetadataInfo::MANY) {
if ($code = $this->generateDocumentStubMethod($metadata, 'add', $fieldMapping['fieldName'], isset($fieldMapping['targetDocument']) ? $fieldMapping['targetDocument'] : null)) {
if ($code = $this->generateDocumentStubMethod($metadata, 'add', $fieldMapping['fieldName'], $fieldMapping['targetDocument'] ?? null)) {
$methods[] = $code;
}
if ($code = $this->generateDocumentStubMethod($metadata, 'remove', $fieldMapping['fieldName'], isset($fieldMapping['targetDocument']) ? $fieldMapping['targetDocument'] : null)) {
if ($code = $this->generateDocumentStubMethod($metadata, 'remove', $fieldMapping['fieldName'], $fieldMapping['targetDocument'] ?? null)) {
$methods[] = $code;
}
if ($code = $this->generateDocumentStubMethod($metadata, 'get', $fieldMapping['fieldName'], '\Doctrine\Common\Collections\Collection')) {
Expand Down Expand Up @@ -822,7 +822,7 @@ private function generateAssociationMappingPropertyDocBlock(array $fieldMapping)
{
$lines = array();
$lines[] = $this->spaces . '/**';
$lines[] = $this->spaces . ' * @var ' . (isset($fieldMapping['targetDocument']) ? $fieldMapping['targetDocument'] : 'object');
$lines[] = $this->spaces . ' * @var ' . ($fieldMapping['targetDocument'] ?? 'object');

if ($this->generateAnnotations) {
$lines[] = $this->spaces . ' *';
Expand Down Expand Up @@ -873,7 +873,7 @@ private function generateFieldMappingPropertyDocBlock(array $fieldMapping, Class
$lines = array();
$lines[] = $this->spaces . '/**';
if (isset($fieldMapping['id']) && $fieldMapping['id']) {
$fieldMapping['strategy'] = isset($fieldMapping['strategy']) ? $fieldMapping['strategy'] : ClassMetadataInfo::GENERATOR_TYPE_AUTO;
$fieldMapping['strategy'] = $fieldMapping['strategy'] ?? ClassMetadataInfo::GENERATOR_TYPE_AUTO;
if ($fieldMapping['strategy'] === ClassMetadataInfo::GENERATOR_TYPE_AUTO) {
$lines[] = $this->spaces . ' * @var MongoDB\BSON\ObjectId $' . $fieldMapping['fieldName'];
} elseif ($fieldMapping['strategy'] === ClassMetadataInfo::GENERATOR_TYPE_INCREMENT) {
Expand Down
11 changes: 5 additions & 6 deletions lib/Doctrine/ODM/MongoDB/UnitOfWork.php
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ private function computeOrRecomputeChangeSet(ClassMetadata $class, $document, $r
continue;
}

$orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null;
$orgValue = $originalData[$propName] ?? null;

// skip if value has not changed
if ($orgValue === $actualValue) {
Expand Down Expand Up @@ -1870,7 +1870,7 @@ private function doMerge($document, array &$visited, $prevManagedCopy = null, $a
continue;
} elseif ( ! $assoc2['isCascadeMerge']) {
if ($this->getDocumentState($other) === self::STATE_DETACHED) {
$targetDocument = isset($assoc2['targetDocument']) ? $assoc2['targetDocument'] : get_class($other);
$targetDocument = $assoc2['targetDocument'] ?? get_class($other);
/* @var $targetClass \Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo */
$targetClass = $this->dm->getClassMetadata($targetDocument);
$relatedId = $targetClass->getIdentifierObject($other);
Expand Down Expand Up @@ -2586,7 +2586,7 @@ public function getOwningDocument($document)
*/
public function getClassNameForAssociation(array $mapping, $data)
{
$discriminatorField = isset($mapping['discriminatorField']) ? $mapping['discriminatorField'] : null;
$discriminatorField = $mapping['discriminatorField'] ?? null;

$discriminatorValue = null;
if (isset($discriminatorField, $data[$discriminatorField])) {
Expand All @@ -2596,9 +2596,8 @@ public function getClassNameForAssociation(array $mapping, $data)
}

if ($discriminatorValue !== null) {
return isset($mapping['discriminatorMap'][$discriminatorValue])
? $mapping['discriminatorMap'][$discriminatorValue]
: $discriminatorValue;
return $mapping['discriminatorMap'][$discriminatorValue]
?? $discriminatorValue;
}

$class = $this->dm->getClassMetadata($mapping['targetDocument']);
Expand Down