Skip to content

Commit 9c42ab1

Browse files
committed
Replace 'if' statement with ternary.
1 parent 2d3b63c commit 9c42ab1

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

src/Illuminate/Collections/Collection.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,21 +1066,21 @@ public function splitIn($numberOfGroups)
10661066
*/
10671067
public function sole($key = null, $operator = null, $value = null)
10681068
{
1069-
if (func_num_args() <= 1) {
1070-
$items = $this->when($key)->filter($key);
1069+
$filter = func_num_args() > 1
1070+
? $this->operatorForWhere(...func_get_args())
1071+
: $key;
10711072

1072-
if ($items->isEmpty()) {
1073-
throw new ItemNotFoundException;
1074-
}
1073+
$items = $this->when($filter)->filter($filter);
10751074

1076-
if ($items->count() > 1) {
1077-
throw new MultipleItemsFoundException;
1078-
}
1075+
if ($items->isEmpty()) {
1076+
throw new ItemNotFoundException;
1077+
}
10791078

1080-
return $items->first();
1079+
if ($items->count() > 1) {
1080+
throw new MultipleItemsFoundException;
10811081
}
10821082

1083-
return $this->sole($this->operatorForWhere(...func_get_args()));
1083+
return $items->first();
10841084
}
10851085

10861086
/**

src/Illuminate/Collections/LazyCollection.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,16 +1024,16 @@ public function split($numberOfGroups)
10241024
*/
10251025
public function sole($key = null, $operator = null, $value = null)
10261026
{
1027-
if (func_num_args() <= 1) {
1028-
return $this
1029-
->when($key)
1030-
->filter($key)
1031-
->take(2)
1032-
->collect()
1033-
->sole();
1034-
}
1035-
1036-
return $this->sole($this->operatorForWhere(...func_get_args()));
1027+
$filter = func_num_args() > 1
1028+
? $this->operatorForWhere(...func_get_args())
1029+
: $key;
1030+
1031+
return $this
1032+
->when($filter)
1033+
->filter($filter)
1034+
->take(2)
1035+
->collect()
1036+
->sole();
10371037
}
10381038

10391039
/**

0 commit comments

Comments
 (0)