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 #770

Merged
merged 1 commit into from Dec 11, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions lib/Doctrine/ODM/PHPCR/Configuration.php
Expand Up @@ -325,9 +325,8 @@ public function setDefaultRepositoryClassName($className)
*/
public function getDefaultRepositoryClassName()
{
return isset($this->attributes['defaultRepositoryClassName'])
? $this->attributes['defaultRepositoryClassName']
: 'Doctrine\ODM\PHPCR\DocumentRepository';
return $this->attributes['defaultRepositoryClassName']
?? 'Doctrine\ODM\PHPCR\DocumentRepository';
}

/**
Expand All @@ -349,9 +348,8 @@ public function setRepositoryFactory(RepositoryFactory $repositoryFactory)
*/
public function getRepositoryFactory()
{
return isset($this->attributes['repositoryFactory'])
? $this->attributes['repositoryFactory']
: new DefaultRepositoryFactory();
return $this->attributes['repositoryFactory']
?? new DefaultRepositoryFactory();
}

/**
Expand All @@ -373,9 +371,8 @@ public function setUuidGenerator(\Closure $generator)
*/
public function getUuidGenerator()
{
return (isset($this->attributes['uuidGenerator']))
? $this->attributes['uuidGenerator']
: function () {
return $this->attributes['uuidGenerator']
?? function () {
return UUIDHelper::generateUUID();
}
;
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ODM/PHPCR/Mapping/ClassMetadata.php
Expand Up @@ -634,7 +634,7 @@ public function hasLifecycleCallbacks($lifecycleEvent)
*/
public function getLifecycleCallbacks($event)
{
return isset($this->lifecycleCallbacks[$event]) ? $this->lifecycleCallbacks[$event] : array();
return $this->lifecycleCallbacks[$event] ?? array();
}

/**
Expand Down Expand Up @@ -1463,7 +1463,7 @@ public function isAssociationInverseSide($assocName)
*/
public function isInheritedField($fieldName)
{
return isset($this->inheritedFields[$fieldName]) ? $this->inheritedFields[$fieldName] : false;
return $this->inheritedFields[$fieldName] ?? false;
}

/**
Expand Down Expand Up @@ -1537,7 +1537,7 @@ public function mapField(array $mapping, ClassMetadata $inherited = null)
}

if (!isset($mapping['nullable'])) {
$mapping['nullable'] = isset($parentMapping['nullable']) ? $parentMapping['nullable'] : false;
$mapping['nullable'] = $parentMapping['nullable'] ?? false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/PHPCR/Mapping/Driver/XmlDriver.php
Expand Up @@ -288,7 +288,7 @@ private function addReferenceMapping(ClassMetadata $class, $reference, $type)
$attributes = (array) $reference->attributes();
$mapping = $attributes["@attributes"];
$mapping['strategy'] = isset($mapping['strategy']) ? strtolower($mapping['strategy']) : null;
$mapping['targetDocument'] = isset($mapping['target-document']) ? $mapping['target-document'] : null;
$mapping['targetDocument'] = $mapping['target-document'] ?? null;
unset($mapping['target-document']);

if ($type === 'many') {
Expand Down
6 changes: 3 additions & 3 deletions lib/Doctrine/ODM/PHPCR/Mapping/Driver/YamlDriver.php
Expand Up @@ -63,7 +63,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['repositoryClass'])) {
$class->setCustomRepositoryClassName($element['repositoryClass']);
Expand Down Expand Up @@ -218,7 +218,7 @@ public function loadMetadataForClass($className, ClassMetadata $class)
foreach ($element['mixedReferrers'] as $name => $attributes) {
$mapping = array(
'fieldName' => $name,
'referenceType' => isset($attributes['referenceType']) ? $attributes['referenceType'] : null,
'referenceType' => $attributes['referenceType'] ?? null,
);
$class->mapMixedReferrers($mapping);
}
Expand Down Expand Up @@ -272,7 +272,7 @@ private function addMappingFromReference(ClassMetadata $class, $fieldName, $refe
$mapping = array_merge(array('fieldName' => $fieldName), $reference);

$mapping['cascade'] = (isset($reference['cascade'])) ? $this->getCascadeMode($reference['cascade']) : 0;
$mapping['name'] = (isset($reference['name'])) ? $reference['name'] : null;
$mapping['name'] = $reference['name'] ?? null;

if (! isset($mapping['targetDocument'])) {
$mapping['targetDocument'] = null;
Expand Down
28 changes: 14 additions & 14 deletions lib/Doctrine/ODM/PHPCR/UnitOfWork.php
Expand Up @@ -362,9 +362,9 @@ public function getOrCreateDocument($className, NodeInterface $node, array &$hin
*/
public function getOrCreateDocuments($className, $nodes, array &$hints = array())
{
$refresh = isset($hints['refresh']) ? $hints['refresh'] : false;
$locale = isset($hints['locale']) ? $hints['locale'] : null;
$fallback = isset($hints['fallback']) ? $hints['fallback'] : isset($locale);
$refresh = $hints['refresh'] ?? false;
$locale = $hints['locale'] ?? null;
$fallback = $hints['fallback'] ?? isset($locale);
$documents = array();
$overrideLocalValuesOids = array();
$strategies = array();
Expand Down Expand Up @@ -443,7 +443,7 @@ public function getOrCreateDocuments($className, $nodes, array &$hints = array()

foreach ($nodes as $node) {
$id = $node->getPath();
$document = $this->getDocumentById($id) ?: (isset($documents[$id]) ? $documents[$id] : null);
$document = $this->getDocumentById($id) ?: ($documents[$id] ?? null);

if (! $document) {
continue;
Expand Down Expand Up @@ -523,7 +523,7 @@ public function getOrCreateDocuments($className, $nodes, array &$hints = array()
}
}

$targetDocument = isset($mapping['targetDocument']) ? $mapping['targetDocument'] : null;
$targetDocument = $mapping['targetDocument'] ?? null;
$coll = new ReferenceManyCollection(
$this->dm,
$document,
Expand Down Expand Up @@ -609,7 +609,7 @@ public function getOrCreateDocuments($className, $nodes, array &$hints = array()

$this->nonMappedData[$overrideLocalValuesOids[$id]] = $nonMappedData;
foreach ($class->reflFields as $fieldName => $reflFields) {
$value = isset($documentState[$fieldName]) ? $documentState[$fieldName] : null;
$value = $documentState[$fieldName] ?? null;
$reflFields->setValue($document, $value);
$this->originalData[$overrideLocalValuesOids[$id]][$fieldName] = $value;
}
Expand Down Expand Up @@ -1273,7 +1273,7 @@ private function computeAssociationChanges($document, $class, $oid, $isNew, $cha
// convert to a PersistentCollection
switch ($assocType) {
case 'reference':
$targetDocument = isset($mapping['targetDocument']) ? $mapping['targetDocument'] : null;
$targetDocument = $mapping['targetDocument'] ?? null;
$changeSet[$fieldName] = ReferenceManyCollection::createFromCollection(
$this->dm,
$document,
Expand Down Expand Up @@ -1361,8 +1361,8 @@ private function computeChildrenChanges($document, $class, $oid, $isNew, $change
);
}

$filter = isset($mapping['filter']) ? $mapping['filter'] : null;
$fetchDepth = isset($mapping['fetchDepth']) ? $mapping['fetchDepth'] : null;
$filter = $mapping['filter'] ?? null;
$fetchDepth = $mapping['fetchDepth'] ?? null;

// convert to a PersistentCollection
$changeSet[$fieldName] = ChildrenCollection::createFromCollection(
Expand Down Expand Up @@ -1947,7 +1947,7 @@ private function doMerge($document, array &$visited, $prevManagedCopy = null, $a
$document,
$mapping['property'],
array(),
isset($mapping['targetDocument']) ? $mapping['targetDocument'] : null,
$mapping['targetDocument'] ?? null,
$locale,
$this->getReferenceManyCollectionTypeFromMetadata($mapping)
);
Expand Down Expand Up @@ -2372,7 +2372,7 @@ private function executeInserts($documents)

$this->setMixins($class, $node, $document);

$fields = isset($this->documentChangesets[$oid]['fields']) ? $this->documentChangesets[$oid]['fields'] : array();
$fields = $this->documentChangesets[$oid]['fields'] ?? array();
foreach ($fields as $fieldName => $fieldValue) {
// Ignore translatable fields (they will be persisted by the translation strategy)
if (in_array($fieldName, $class->translatableFields)) {
Expand All @@ -2399,7 +2399,7 @@ private function executeInserts($documents)

//populate $associationChangesets to force executeUpdates($associationUpdates)
//to only update association fields
$data = isset($associationChangesets[$oid]['fields']) ? $associationChangesets[$oid]['fields'] : array();
$data = $associationChangesets[$oid]['fields'] ?? array();
$data[$fieldName] = array(null, $fieldValue);
$associationChangesets[$oid] = array('fields' => $data);
}
Expand Down Expand Up @@ -2492,7 +2492,7 @@ private function executeUpdates($documents, $dispatchEvents = true)
}
}

$fields = isset($this->documentChangesets[$oid]['fields']) ? $this->documentChangesets[$oid]['fields'] : array();
$fields = $this->documentChangesets[$oid]['fields'] ?? array();
foreach ($fields as $fieldName => $data) {
$fieldValue = $data[1];

Expand Down Expand Up @@ -3926,7 +3926,7 @@ public function createAssoc(array $properties, array $mapping)
}

$keys = (array) $properties[$mapping['assoc']];
$nulls = isset($properties[$mapping['assocNulls']]) ? ((array) $properties[$mapping['assocNulls']]) : array();
$nulls = (array) ($properties[$mapping['assocNulls']] ?? array());

// make sure we start with first value
reset($values);
Expand Down
13 changes: 5 additions & 8 deletions tests/Doctrine/Tests/ODM/PHPCR/PHPCRFunctionalTestCase.php
Expand Up @@ -26,8 +26,8 @@ public function createDocumentManager(array $paths = null)

$metaDriver = new AnnotationDriver($reader, $paths);

$factoryclass = isset($GLOBALS['DOCTRINE_PHPCR_FACTORY'])
? $GLOBALS['DOCTRINE_PHPCR_FACTORY'] : '\Jackalope\RepositoryFactoryJackrabbit';
$factoryclass = $GLOBALS['DOCTRINE_PHPCR_FACTORY']
?? '\Jackalope\RepositoryFactoryJackrabbit';

if ($factoryclass === '\Jackalope\RepositoryFactoryDoctrineDBAL') {
$params = array();
Expand All @@ -50,13 +50,10 @@ public function createDocumentManager(array $paths = null)
$repository = $factory->getRepository($parameters);
$this->assertNotNull($repository, 'There is an issue with your parameters: '.var_export(array_keys($parameters), true));

$workspace = isset($GLOBALS['DOCTRINE_PHPCR_WORKSPACE'])
? $GLOBALS['DOCTRINE_PHPCR_WORKSPACE'] : 'tests';
$workspace = $GLOBALS['DOCTRINE_PHPCR_WORKSPACE'] ?? 'tests';

$user = isset($GLOBALS['DOCTRINE_PHPCR_USER'])
? $GLOBALS['DOCTRINE_PHPCR_USER'] : '';
$pass = isset($GLOBALS['DOCTRINE_PHPCR_PASS'])
? $GLOBALS['DOCTRINE_PHPCR_PASS'] : '';
$user = $GLOBALS['DOCTRINE_PHPCR_USER'] ?? '';
$pass = $GLOBALS['DOCTRINE_PHPCR_PASS'] ?? '';

$credentials = new \PHPCR\SimpleCredentials($user, $pass);
$session = $repository->login($credentials, $workspace);
Expand Down
Expand Up @@ -10,7 +10,7 @@ public function setup()
{
$this->dm = $this->createDocumentManager();
$this->node = $this->resetFunctionalNode($this->dm);
$this->count = isset($GLOBALS['DOCTRINE_PHPCR_PERFORMANCE_COUNT']) ? $GLOBALS['DOCTRINE_PHPCR_PERFORMANCE_COUNT'] : 100;
$this->count = $GLOBALS['DOCTRINE_PHPCR_PERFORMANCE_COUNT'] ?? 100;
}

public function testInsertDocuments()
Expand Down