1
0
mirror of synced 2025-03-06 12:56:10 +03:00

Merge pull request #6691 from keradus/php_syntax

Use newer PHP syntax
This commit is contained in:
Marco Pivetta 2017-09-11 08:50:05 +02:00 committed by GitHub
commit 80f7824b3d
16 changed files with 47 additions and 57 deletions

View File

@ -942,7 +942,7 @@ class ClassMetadataInfo implements ClassMetadata
} }
$fieldRefl = $reflService->getAccessibleProperty( $fieldRefl = $reflService->getAccessibleProperty(
isset($embeddedClass['declared']) ? $embeddedClass['declared'] : $this->name, $embeddedClass['declared'] ?? $this->name,
$property $property
); );
@ -1617,9 +1617,7 @@ class ClassMetadataInfo implements ClassMetadata
} }
$mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName'];
$mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName']) $mapping['joinColumnFieldNames'][$joinColumn['name']] = $joinColumn['fieldName'] ?? $joinColumn['name'];
? $joinColumn['fieldName']
: $joinColumn['name'];
} }
if ($uniqueConstraintColumns) { if ($uniqueConstraintColumns) {
@ -3288,8 +3286,8 @@ class ClassMetadataInfo implements ClassMetadata
$this->embeddedClasses[$mapping['fieldName']] = [ $this->embeddedClasses[$mapping['fieldName']] = [
'class' => $this->fullyQualifiedClassName($mapping['class']), 'class' => $this->fullyQualifiedClassName($mapping['class']),
'columnPrefix' => $mapping['columnPrefix'], 'columnPrefix' => $mapping['columnPrefix'],
'declaredField' => isset($mapping['declaredField']) ? $mapping['declaredField'] : null, 'declaredField' => $mapping['declaredField'] ?? null,
'originalField' => isset($mapping['originalField']) ? $mapping['originalField'] : null, 'originalField' => $mapping['originalField'] ?? null,
]; ];
} }
@ -3302,15 +3300,11 @@ class ClassMetadataInfo implements ClassMetadata
public function inlineEmbeddable($property, ClassMetadataInfo $embeddable) public function inlineEmbeddable($property, ClassMetadataInfo $embeddable)
{ {
foreach ($embeddable->fieldMappings as $fieldMapping) { foreach ($embeddable->fieldMappings as $fieldMapping) {
$fieldMapping['originalClass'] = isset($fieldMapping['originalClass']) $fieldMapping['originalClass'] = $fieldMapping['originalClass'] ?? $embeddable->name;
? $fieldMapping['originalClass']
: $embeddable->name;
$fieldMapping['declaredField'] = isset($fieldMapping['declaredField']) $fieldMapping['declaredField'] = isset($fieldMapping['declaredField'])
? $property . '.' . $fieldMapping['declaredField'] ? $property . '.' . $fieldMapping['declaredField']
: $property; : $property;
$fieldMapping['originalField'] = isset($fieldMapping['originalField']) $fieldMapping['originalField'] = $fieldMapping['originalField'] ?? $fieldMapping['fieldName'];
? $fieldMapping['originalField']
: $fieldMapping['fieldName'];
$fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName']; $fieldMapping['fieldName'] = $property . "." . $fieldMapping['fieldName'];
if (! empty($this->embeddedClasses[$property]['columnPrefix'])) { if (! empty($this->embeddedClasses[$property]['columnPrefix'])) {

View File

@ -64,7 +64,7 @@ class YamlDriver extends FileDriver
} }
} else if ($element['type'] == 'mappedSuperclass') { } else if ($element['type'] == 'mappedSuperclass') {
$metadata->setCustomRepositoryClass( $metadata->setCustomRepositoryClass(
isset($element['repositoryClass']) ? $element['repositoryClass'] : null $element['repositoryClass'] ?? null
); );
$metadata->isMappedSuperclass = true; $metadata->isMappedSuperclass = true;
} else if ($element['type'] == 'embeddable') { } else if ($element['type'] == 'embeddable') {
@ -115,9 +115,9 @@ class YamlDriver extends FileDriver
$metadata->addNamedNativeQuery( $metadata->addNamedNativeQuery(
[ [
'name' => $mappingElement['name'], 'name' => $mappingElement['name'],
'query' => isset($mappingElement['query']) ? $mappingElement['query'] : null, 'query' => $mappingElement['query'] ?? null,
'resultClass' => isset($mappingElement['resultClass']) ? $mappingElement['resultClass'] : null, 'resultClass' => $mappingElement['resultClass'] ?? null,
'resultSetMapping' => isset($mappingElement['resultSetMapping']) ? $mappingElement['resultSetMapping'] : null, 'resultSetMapping' => $mappingElement['resultSetMapping'] ?? null,
] ]
); );
} }
@ -136,15 +136,15 @@ class YamlDriver extends FileDriver
foreach ($resultSetMapping['entityResult'] as $entityResultElement) { foreach ($resultSetMapping['entityResult'] as $entityResultElement) {
$entityResult = [ $entityResult = [
'fields' => [], 'fields' => [],
'entityClass' => isset($entityResultElement['entityClass']) ? $entityResultElement['entityClass'] : null, 'entityClass' => $entityResultElement['entityClass'] ?? null,
'discriminatorColumn' => isset($entityResultElement['discriminatorColumn']) ? $entityResultElement['discriminatorColumn'] : null, 'discriminatorColumn' => $entityResultElement['discriminatorColumn'] ?? null,
]; ];
if (isset($entityResultElement['fieldResult'])) { if (isset($entityResultElement['fieldResult'])) {
foreach ($entityResultElement['fieldResult'] as $fieldResultElement) { foreach ($entityResultElement['fieldResult'] as $fieldResultElement) {
$entityResult['fields'][] = [ $entityResult['fields'][] = [
'name' => isset($fieldResultElement['name']) ? $fieldResultElement['name'] : null, 'name' => $fieldResultElement['name'] ?? null,
'column' => isset($fieldResultElement['column']) ? $fieldResultElement['column'] : null, 'column' => $fieldResultElement['column'] ?? null,
]; ];
} }
} }
@ -157,7 +157,7 @@ class YamlDriver extends FileDriver
if (isset($resultSetMapping['columnResult'])) { if (isset($resultSetMapping['columnResult'])) {
foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) { foreach ($resultSetMapping['columnResult'] as $columnResultAnnot) {
$columns[] = [ $columns[] = [
'name' => isset($columnResultAnnot['name']) ? $columnResultAnnot['name'] : null, 'name' => $columnResultAnnot['name'] ?? null,
]; ];
} }
} }
@ -343,7 +343,7 @@ class YamlDriver extends FileDriver
$mapping = [ $mapping = [
'fieldName' => $name, 'fieldName' => $name,
'class' => $embeddedMapping['class'], 'class' => $embeddedMapping['class'],
'columnPrefix' => isset($embeddedMapping['columnPrefix']) ? $embeddedMapping['columnPrefix'] : null, 'columnPrefix' => $embeddedMapping['columnPrefix'] ?? null,
]; ];
$metadata->mapEmbedded($mapping); $metadata->mapEmbedded($mapping);
} }

View File

@ -1795,7 +1795,7 @@ class BasicEntityPersister implements EntityPersister
$parameters = []; $parameters = [];
$owningAssoc = $this->class->associationMappings[$assoc['mappedBy']]; $owningAssoc = $this->class->associationMappings[$assoc['mappedBy']];
$sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']);
$tableAlias = $this->getSQLTableAlias(isset($owningAssoc['inherited']) ? $owningAssoc['inherited'] : $this->class->name); $tableAlias = $this->getSQLTableAlias($owningAssoc['inherited'] ?? $this->class->name);
foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) { foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) {
if ($sourceClass->containsForeignIdentifier) { if ($sourceClass->containsForeignIdentifier) {

View File

@ -196,9 +196,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
foreach ($subTableStmts as $tableName => $stmt) { foreach ($subTableStmts as $tableName => $stmt) {
/** @var \Doctrine\DBAL\Statement $stmt */ /** @var \Doctrine\DBAL\Statement $stmt */
$paramIndex = 1; $paramIndex = 1;
$data = isset($insertData[$tableName]) $data = $insertData[$tableName] ?? [];
? $insertData[$tableName]
: [];
foreach ((array) $id as $idName => $idVal) { foreach ((array) $id as $idName => $idVal) {
$type = isset($this->columnTypes[$idName]) ? $this->columnTypes[$idName] : Type::STRING; $type = isset($this->columnTypes[$idName]) ? $this->columnTypes[$idName] : Type::STRING;

View File

@ -183,7 +183,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
if (isset($this->_sqlParameters[$key])) { if (isset($this->_sqlParameters[$key])) {
foreach ($this->_sqlParameters[$key] as $parameterKey => $parameterName) { foreach ($this->_sqlParameters[$key] as $parameterKey => $parameterName) {
$paramValues[] = $params[$parameterKey]; $paramValues[] = $params[$parameterKey];
$paramTypes[] = isset($types[$parameterKey]) ? $types[$parameterKey] : ParameterTypeInferer::inferType($params[$parameterKey]); $paramTypes[] = $types[$parameterKey] ?? ParameterTypeInferer::inferType($params[$parameterKey]);
} }
} }

View File

@ -206,8 +206,7 @@ class ResultSetMappingBuilder extends ResultSetMapping
return $columnName . $this->sqlCounter++; return $columnName . $this->sqlCounter++;
case self::COLUMN_RENAMING_CUSTOM: case self::COLUMN_RENAMING_CUSTOM:
return isset($customRenameColumns[$columnName]) return $customRenameColumns[$columnName] ?? $columnName;
? $customRenameColumns[$columnName] : $columnName;
case self::COLUMN_RENAMING_NONE: case self::COLUMN_RENAMING_NONE:
return $columnName; return $columnName;
@ -441,8 +440,7 @@ class ResultSetMappingBuilder extends ResultSetMapping
$sql = ""; $sql = "";
foreach ($this->columnOwnerMap as $columnName => $dqlAlias) { foreach ($this->columnOwnerMap as $columnName => $dqlAlias) {
$tableAlias = isset($tableAliases[$dqlAlias]) $tableAlias = $tableAliases[$dqlAlias] ?? $dqlAlias;
? $tableAliases[$dqlAlias] : $dqlAlias;
if ($sql) { if ($sql) {
$sql .= ", "; $sql .= ", ";

View File

@ -1441,12 +1441,12 @@ class QueryBuilder
$queryPart = $this->getDQLPart($queryPartName); $queryPart = $this->getDQLPart($queryPartName);
if (empty($queryPart)) { if (empty($queryPart)) {
return (isset($options['empty']) ? $options['empty'] : ''); return ($options['empty'] ?? '');
} }
return (isset($options['pre']) ? $options['pre'] : '') return ($options['pre'] ?? '')
. (is_array($queryPart) ? implode($options['separator'], $queryPart) : $queryPart) . (is_array($queryPart) ? implode($options['separator'], $queryPart) : $queryPart)
. (isset($options['post']) ? $options['post'] : ''); . ($options['post'] ?? '');
} }
/** /**

View File

@ -214,7 +214,7 @@ class ConvertDoctrine1Schema
$fieldMapping['id'] = true; $fieldMapping['id'] = true;
} }
$fieldMapping['fieldName'] = isset($column['alias']) ? $column['alias'] : $name; $fieldMapping['fieldName'] = $column['alias'] ?? $name;
$fieldMapping['columnName'] = $column['name']; $fieldMapping['columnName'] = $column['name'];
$fieldMapping['type'] = $column['type']; $fieldMapping['type'] = $column['type'];
@ -313,13 +313,13 @@ class ConvertDoctrine1Schema
$foreignType = 'many'; $foreignType = 'many';
$joinColumns = []; $joinColumns = [];
} else { } else {
$type = isset($relation['type']) ? $relation['type'] : 'one'; $type = $relation['type'] ?? 'one';
$foreignType = isset($relation['foreignType']) ? $relation['foreignType'] : 'many'; $foreignType = $relation['foreignType'] ?? 'many';
$joinColumns = [ $joinColumns = [
[ [
'name' => $relation['local'], 'name' => $relation['local'],
'referencedColumnName' => $relation['foreign'], 'referencedColumnName' => $relation['foreign'],
'onDelete' => isset($relation['onDelete']) ? $relation['onDelete'] : null, 'onDelete' => $relation['onDelete'] ?? null,
] ]
]; ];
} }

View File

@ -193,7 +193,7 @@ class YamlExporter extends AbstractExporter
'mappedBy' => $associationMapping['mappedBy'], 'mappedBy' => $associationMapping['mappedBy'],
'inversedBy' => $associationMapping['inversedBy'], 'inversedBy' => $associationMapping['inversedBy'],
'orphanRemoval' => $associationMapping['orphanRemoval'], 'orphanRemoval' => $associationMapping['orphanRemoval'],
'orderBy' => isset($associationMapping['orderBy']) ? $associationMapping['orderBy'] : null 'orderBy' => $associationMapping['orderBy'] ?? null
]; ];
$associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray); $associationMappingArray = array_merge($associationMappingArray, $oneToManyMappingArray);
@ -202,8 +202,8 @@ class YamlExporter extends AbstractExporter
$manyToManyMappingArray = [ $manyToManyMappingArray = [
'mappedBy' => $associationMapping['mappedBy'], 'mappedBy' => $associationMapping['mappedBy'],
'inversedBy' => $associationMapping['inversedBy'], 'inversedBy' => $associationMapping['inversedBy'],
'joinTable' => isset($associationMapping['joinTable']) ? $associationMapping['joinTable'] : null, 'joinTable' => $associationMapping['joinTable'] ?? null,
'orderBy' => isset($associationMapping['orderBy']) ? $associationMapping['orderBy'] : null 'orderBy' => $associationMapping['orderBy'] ?? null
]; ];
$associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray); $associationMappingArray = array_merge($associationMappingArray, $manyToManyMappingArray);

View File

@ -283,13 +283,13 @@ class SchemaTool
$indexData['flags'] = []; $indexData['flags'] = [];
} }
$table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array) $indexData['flags'], isset($indexData['options']) ? $indexData['options'] : []); $table->addIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, (array) $indexData['flags'], $indexData['options'] ?? []);
} }
} }
if (isset($class->table['uniqueConstraints'])) { if (isset($class->table['uniqueConstraints'])) {
foreach ($class->table['uniqueConstraints'] as $indexName => $indexData) { foreach ($class->table['uniqueConstraints'] as $indexName => $indexData) {
$uniqIndex = new Index($indexName, $indexData['columns'], true, false, [], isset($indexData['options']) ? $indexData['options'] : []); $uniqIndex = new Index($indexName, $indexData['columns'], true, false, [], $indexData['options'] ?? []);
foreach ($table->getIndexes() as $tableIndexName => $tableIndex) { foreach ($table->getIndexes() as $tableIndexName => $tableIndex) {
if ($tableIndex->isFullfilledBy($uniqIndex)) { if ($tableIndex->isFullfilledBy($uniqIndex)) {
@ -298,7 +298,7 @@ class SchemaTool
} }
} }
$table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, isset($indexData['options']) ? $indexData['options'] : []); $table->addUniqueIndex($indexData['columns'], is_numeric($indexName) ? null : $indexName, $indexData['options'] ?? []);
} }
} }
@ -365,7 +365,7 @@ class SchemaTool
} }
$options = [ $options = [
'length' => isset($discrColumn['length']) ? $discrColumn['length'] : null, 'length' => $discrColumn['length'] ?? null,
'notnull' => true 'notnull' => true
]; ];
@ -417,7 +417,7 @@ class SchemaTool
$columnType = $mapping['type']; $columnType = $mapping['type'];
$options = []; $options = [];
$options['length'] = isset($mapping['length']) ? $mapping['length'] : null; $options['length'] = $mapping['length'] ?? null;
$options['notnull'] = isset($mapping['nullable']) ? ! $mapping['nullable'] : true; $options['notnull'] = isset($mapping['nullable']) ? ! $mapping['nullable'] : true;
if ($class->isInheritanceTypeSingleTable() && $class->parentClasses) { if ($class->isInheritanceTypeSingleTable() && $class->parentClasses) {
$options['notnull'] = false; $options['notnull'] = false;
@ -474,7 +474,7 @@ class SchemaTool
$table->addColumn($columnName, $columnType, $options); $table->addColumn($columnName, $columnType, $options);
} }
$isUnique = isset($mapping['unique']) ? $mapping['unique'] : false; $isUnique = $mapping['unique'] ?? false;
if ($isUnique) { if ($isUnique) {
$table->addUniqueIndex([$columnName]); $table->addUniqueIndex([$columnName]);
} }

View File

@ -1001,7 +1001,7 @@ class UnitOfWork implements PropertyChangedListener
$changeSet = []; $changeSet = [];
foreach ($actualData as $propName => $actualValue) { foreach ($actualData as $propName => $actualValue) {
$orgValue = isset($originalData[$propName]) ? $originalData[$propName] : null; $orgValue = $originalData[$propName] ?? null;
if ($orgValue !== $actualValue) { if ($orgValue !== $actualValue) {
$changeSet[$propName] = [$orgValue, $actualValue]; $changeSet[$propName] = [$orgValue, $actualValue];
@ -2681,7 +2681,7 @@ class UnitOfWork implements PropertyChangedListener
// TODO: Is this even computed right in all cases of composite keys? // TODO: Is this even computed right in all cases of composite keys?
foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) { foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) {
$joinColumnValue = isset($data[$srcColumn]) ? $data[$srcColumn] : null; $joinColumnValue = $data[$srcColumn] ?? null;
if ($joinColumnValue !== null) { if ($joinColumnValue !== null) {
if ($targetClass->containsForeignIdentifier) { if ($targetClass->containsForeignIdentifier) {

View File

@ -277,7 +277,7 @@ class EntityManagerTest extends OrmTestCase
*/ */
public function testClearManagerWithProxyClassName() public function testClearManagerWithProxyClassName()
{ {
$proxy = $this->_em->getReference(Country::class, ['id' => rand(457, 100000)]); $proxy = $this->_em->getReference(Country::class, ['id' => random_int(457, 100000)]);
$entity = new Country(456, 'United Kingdom'); $entity = new Country(456, 'United Kingdom');

View File

@ -27,8 +27,8 @@ class GearmanLockTest extends OrmFunctionalTestCase
$this->gearman = new \GearmanClient(); $this->gearman = new \GearmanClient();
$this->gearman->addServer( $this->gearman->addServer(
isset($_SERVER['GEARMAN_HOST']) ? $_SERVER['GEARMAN_HOST'] : null, $_SERVER['GEARMAN_HOST'] ?? null,
isset($_SERVER['GEARMAN_PORT']) ? $_SERVER['GEARMAN_PORT'] : 4730 $_SERVER['GEARMAN_PORT'] ?? 4730
); );
$this->gearman->setCompleteCallback([$this, "gearmanTaskCompleted"]); $this->gearman->setCompleteCallback([$this, "gearmanTaskCompleted"]);

View File

@ -17,8 +17,8 @@ class LockAgentWorker
$worker = new \GearmanWorker(); $worker = new \GearmanWorker();
$worker->addServer( $worker->addServer(
isset($_SERVER['GEARMAN_HOST']) ? $_SERVER['GEARMAN_HOST'] : null, $_SERVER['GEARMAN_HOST'] ?? null,
isset($_SERVER['GEARMAN_PORT']) ? $_SERVER['GEARMAN_PORT'] : 4730 $_SERVER['GEARMAN_PORT'] ?? 4730
); );
$worker->addFunction("findWithLock", [$lockAgent, "findWithLock"]); $worker->addFunction("findWithLock", [$lockAgent, "findWithLock"]);
$worker->addFunction("dqlWithLock", [$lockAgent, "dqlWithLock"]); $worker->addFunction("dqlWithLock", [$lockAgent, "dqlWithLock"]);

View File

@ -55,7 +55,7 @@ class DDC1454File
public function __construct() public function __construct()
{ {
$this->fileId = rand(); $this->fileId = random_int(0, getrandmax());
} }
/** /**

View File

@ -599,7 +599,7 @@ class UnitOfWorkTest extends OrmTestCase
$mergedEntity = new EntityWithRandomlyGeneratedField(); $mergedEntity = new EntityWithRandomlyGeneratedField();
$mergedEntity->id = $persistedEntity->id; $mergedEntity->id = $persistedEntity->id;
$mergedEntity->generatedField = mt_rand( $mergedEntity->generatedField = random_int(
$persistedEntity->generatedField + 1, $persistedEntity->generatedField + 1,
$persistedEntity->generatedField + 1000 $persistedEntity->generatedField + 1000
); );
@ -915,7 +915,7 @@ class EntityWithRandomlyGeneratedField
public function __construct() public function __construct()
{ {
$this->id = uniqid('id', true); $this->id = uniqid('id', true);
$this->generatedField = mt_rand(0, 100000); $this->generatedField = random_int(0, 100000);
} }
} }