File tree Expand file tree Collapse file tree 2 files changed +20
-20
lines changed
src/Illuminate/Collections Expand file tree Collapse file tree 2 files changed +20
-20
lines changed Original file line number Diff line number Diff line change @@ -1066,21 +1066,21 @@ public function splitIn($numberOfGroups)
1066
1066
*/
1067
1067
public function sole ($ key = null , $ operator = null , $ value = null )
1068
1068
{
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 ;
1071
1072
1072
- if ($ items ->isEmpty ()) {
1073
- throw new ItemNotFoundException ;
1074
- }
1073
+ $ items = $ this ->when ($ filter )->filter ($ filter );
1075
1074
1076
- if ($ items ->count () > 1 ) {
1077
- throw new MultipleItemsFoundException ;
1078
- }
1075
+ if ($ items ->isEmpty () ) {
1076
+ throw new ItemNotFoundException ;
1077
+ }
1079
1078
1080
- return $ items ->first ();
1079
+ if ($ items ->count () > 1 ) {
1080
+ throw new MultipleItemsFoundException ;
1081
1081
}
1082
1082
1083
- return $ this -> sole ( $ this -> operatorForWhere (... func_get_args ()) );
1083
+ return $ items -> first ( );
1084
1084
}
1085
1085
1086
1086
/**
Original file line number Diff line number Diff line change @@ -1024,16 +1024,16 @@ public function split($numberOfGroups)
1024
1024
*/
1025
1025
public function sole ($ key = null , $ operator = null , $ value = null )
1026
1026
{
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 ();
1037
1037
}
1038
1038
1039
1039
/**
You can’t perform that action at this time.
0 commit comments