Skip to content
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
20 changes: 9 additions & 11 deletions lib/Doctrine/ODM/MongoDB/Aggregation/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,10 @@ public function add($expression1, $expression2, ...$expressions): static
*/
public function addAnd($expression, ...$expressions): static
{
if (! isset($this->expr['$and'])) {
$this->expr['$and'] = [];
}

$this->expr['$and'] = array_merge($this->expr['$and'], array_map([$this, 'prepareArgument'], func_get_args()));
$this->expr['$and'] = array_merge(
$this->expr['$and'] ?? [],
array_map($this->prepareArgument(...), func_get_args()),
);

return $this;
}
Expand All @@ -141,11 +140,10 @@ public function addAnd($expression, ...$expressions): static
*/
public function addOr($expression, ...$expressions): static
{
if (! isset($this->expr['$or'])) {
$this->expr['$or'] = [];
}

$this->expr['$or'] = array_merge($this->expr['$or'], array_map([$this, 'prepareArgument'], func_get_args()));
$this->expr['$or'] = array_merge(
$this->expr['$or'] ?? [],
array_map($this->prepareArgument(...), func_get_args()),
);

return $this;
}
Expand Down Expand Up @@ -1116,7 +1114,7 @@ private function prepareArgument($expression)
}

if (is_array($expression)) {
return array_map([$this, 'prepareArgument'], $expression);
return array_map($this->prepareArgument(...), $expression);
}

if ($expression instanceof self) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ abstract protected function getStageName(): string;
private function convertExpression($expression)
{
if (is_array($expression)) {
return array_map([$this, 'convertExpression'], $expression);
return array_map($this->convertExpression(...), $expression);
}

if (is_string($expression) && substr($expression, 0, 1) === '$') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getReplaceExpression()
private function convertExpression($expression)
{
if (is_array($expression)) {
return array_map([$this, 'convertExpression'], $expression);
return array_map($this->convertExpression(...), $expression);
}

if (is_string($expression) && substr($expression, 0, 1) === '$') {
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Aggregation/Stage/GraphLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ private function fromReference(string $fieldName): static
private function convertExpression($expression)
{
if (is_array($expression)) {
return array_map([$this, 'convertExpression'], $expression);
return array_map($this->convertExpression(...), $expression);
}

if (is_string($expression) && substr($expression, 0, 1) === '$') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static function (SearchOperator $operator): object {

protected function getAddOperatorClosure(): Closure
{
return Closure::fromCallable([$this, 'addOperator']);
return $this->addOperator(...);
}

protected function getCompoundStage(): Compound
Expand Down
15 changes: 5 additions & 10 deletions lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -1839,8 +1839,7 @@ public function isCollectionValuedAssociation($fieldName): bool
*/
public function isSingleValuedReference(string $fieldName): bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::REFERENCE_ONE;
return ($this->fieldMappings[$fieldName]['association'] ?? null) === self::REFERENCE_ONE;
}

/**
Expand All @@ -1849,8 +1848,7 @@ public function isSingleValuedReference(string $fieldName): bool
*/
public function isCollectionValuedReference(string $fieldName): bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::REFERENCE_MANY;
return ($this->fieldMappings[$fieldName]['association'] ?? null) === self::REFERENCE_MANY;
}

/**
Expand All @@ -1859,8 +1857,7 @@ public function isCollectionValuedReference(string $fieldName): bool
*/
public function isSingleValuedEmbed(string $fieldName): bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::EMBED_ONE;
return ($this->fieldMappings[$fieldName]['association'] ?? null) === self::EMBED_ONE;
}

/**
Expand All @@ -1869,8 +1866,7 @@ public function isSingleValuedEmbed(string $fieldName): bool
*/
public function isCollectionValuedEmbed(string $fieldName): bool
{
return isset($this->fieldMappings[$fieldName]['association']) &&
$this->fieldMappings[$fieldName]['association'] === self::EMBED_MANY;
return ($this->fieldMappings[$fieldName]['association'] ?? null) === self::EMBED_MANY;
}

/**
Expand Down Expand Up @@ -2279,8 +2275,7 @@ public function getAssociationNames(): array
/** @param string $fieldName */
public function getTypeOfField($fieldName): ?string
{
return isset($this->fieldMappings[$fieldName]) ?
$this->fieldMappings[$fieldName]['type'] : null;
return $this->fieldMappings[$fieldName]['type'] ?? null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ public function getRealClass(string $class): string

public function resolveClassName(string $className): string
{
if (! isset($this->resolvedNames[$className])) {
$this->resolvedNames[$className] = $this->resolver->resolveClassName($className);
}

return $this->resolvedNames[$className];
return $this->resolvedNames[$className] ??= $this->resolver->resolveClassName($className);
}
}
21 changes: 6 additions & 15 deletions lib/Doctrine/ODM/MongoDB/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,8 @@ public function equals($value): self
*/
public function exclude($fieldName = null): self
{
if (! isset($this->query['select'])) {
$this->query['select'] = [];
}

$fieldNames = is_array($fieldName) ? $fieldName : func_get_args();
$this->query['select'] ??= [];
$fieldNames = is_array($fieldName) ? $fieldName : func_get_args();

foreach ($fieldNames as $fieldName) {
$this->query['select'][$fieldName] = 0;
Expand Down Expand Up @@ -1261,11 +1258,8 @@ public function returnNew(bool $bool = true): self
*/
public function select($fieldName = null): self
{
if (! isset($this->query['select'])) {
$this->query['select'] = [];
}

$fieldNames = is_array($fieldName) ? $fieldName : func_get_args();
$this->query['select'] ??= [];
$fieldNames = is_array($fieldName) ? $fieldName : func_get_args();

foreach ($fieldNames as $fieldName) {
$this->query['select'][$fieldName] = 1;
Expand Down Expand Up @@ -1464,11 +1458,8 @@ public function snapshot(bool $bool = true): self
*/
public function sort($fieldName, $order = 1): self
{
if (! isset($this->query['sort'])) {
$this->query['sort'] = [];
}

$fields = is_array($fieldName) ? $fieldName : [$fieldName => $order];
$this->query['sort'] ??= [];
$fields = is_array($fieldName) ? $fieldName : [$fieldName => $order];

foreach ($fields as $fieldName => $order) {
if (is_string($order)) {
Expand Down
18 changes: 3 additions & 15 deletions lib/Doctrine/ODM/MongoDB/Query/Expr.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,8 @@ public function __construct(DocumentManager $dm)
*/
public function addAnd($expression, ...$expressions): self
{
if (! isset($this->query['$and'])) {
$this->query['$and'] = [];
}

$this->query['$and'] = array_merge(
$this->query['$and'],
$this->query['$and'] ?? [],
func_get_args(),
);

Expand All @@ -107,12 +103,8 @@ public function addAnd($expression, ...$expressions): self
*/
public function addNor($expression, ...$expressions): self
{
if (! isset($this->query['$nor'])) {
$this->query['$nor'] = [];
}

$this->query['$nor'] = array_merge(
$this->query['$nor'],
$this->query['$nor'] ?? [],
func_get_args(),
);

Expand All @@ -130,12 +122,8 @@ public function addNor($expression, ...$expressions): self
*/
public function addOr($expression, ...$expressions): self
{
if (! isset($this->query['$or'])) {
$this->query['$or'] = [];
}

$this->query['$or'] = array_merge(
$this->query['$or'],
$this->query['$or'] ?? [],
func_get_args(),
);

Expand Down