Skip to content

Commit

Permalink
Replace 'if' statement with ternary.
Browse files Browse the repository at this point in the history
  • Loading branch information
ash-jc-allen committed Apr 19, 2021
1 parent 2d3b63c commit 9c42ab1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
20 changes: 10 additions & 10 deletions src/Illuminate/Collections/Collection.php
Expand Up @@ -1066,21 +1066,21 @@ public function splitIn($numberOfGroups)
*/
public function sole($key = null, $operator = null, $value = null)
{
if (func_num_args() <= 1) {
$items = $this->when($key)->filter($key);
$filter = func_num_args() > 1
? $this->operatorForWhere(...func_get_args())
: $key;

if ($items->isEmpty()) {
throw new ItemNotFoundException;
}
$items = $this->when($filter)->filter($filter);

if ($items->count() > 1) {
throw new MultipleItemsFoundException;
}
if ($items->isEmpty()) {
throw new ItemNotFoundException;
}

return $items->first();
if ($items->count() > 1) {
throw new MultipleItemsFoundException;
}

return $this->sole($this->operatorForWhere(...func_get_args()));
return $items->first();
}

/**
Expand Down
20 changes: 10 additions & 10 deletions src/Illuminate/Collections/LazyCollection.php
Expand Up @@ -1024,16 +1024,16 @@ public function split($numberOfGroups)
*/
public function sole($key = null, $operator = null, $value = null)
{
if (func_num_args() <= 1) {
return $this
->when($key)
->filter($key)
->take(2)
->collect()
->sole();
}

return $this->sole($this->operatorForWhere(...func_get_args()));
$filter = func_num_args() > 1
? $this->operatorForWhere(...func_get_args())
: $key;

return $this
->when($filter)
->filter($filter)
->take(2)
->collect()
->sole();
}

/**
Expand Down

0 comments on commit 9c42ab1

Please sign in to comment.