@@ -821,17 +821,7 @@ public function whenContainsAll(array $needles, $callback, $default = null)
821
821
*/
822
822
public function whenEndsWith ($ needles , $ callback , $ default = null )
823
823
{
824
- if ($ this ->endsWith ($ needles )) {
825
- $ result = $ callback ($ this );
826
-
827
- return $ result ?? $ this ;
828
- } elseif ($ default ) {
829
- $ result = $ default ($ this );
830
-
831
- return $ result ?? $ this ;
832
- }
833
-
834
- return $ this ;
824
+ return $ this ->when ($ this ->endsWith ($ needles ), $ callback , $ default );
835
825
}
836
826
837
827
/**
@@ -844,17 +834,7 @@ public function whenEndsWith($needles, $callback, $default = null)
844
834
*/
845
835
public function whenExactly ($ value , $ callback , $ default = null )
846
836
{
847
- if ($ this ->exactly ($ value )) {
848
- $ result = $ callback ($ this );
849
-
850
- return $ result ?? $ this ;
851
- } elseif ($ default ) {
852
- $ result = $ default ($ this );
853
-
854
- return $ result ?? $ this ;
855
- }
856
-
857
- return $ this ;
837
+ return $ this ->when ($ this ->exactly ($ value ), $ callback , $ default );
858
838
}
859
839
860
840
/**
@@ -867,17 +847,7 @@ public function whenExactly($value, $callback, $default = null)
867
847
*/
868
848
public function whenIs ($ pattern , $ callback , $ default = null )
869
849
{
870
- if ($ this ->is ($ pattern )) {
871
- $ result = $ callback ($ this );
872
-
873
- return $ result ?? $ this ;
874
- } elseif ($ default ) {
875
- $ result = $ default ($ this );
876
-
877
- return $ result ?? $ this ;
878
- }
879
-
880
- return $ this ;
850
+ return $ this ->when ($ this ->is ($ pattern ), $ callback , $ default );
881
851
}
882
852
883
853
/**
@@ -889,17 +859,7 @@ public function whenIs($pattern, $callback, $default = null)
889
859
*/
890
860
public function whenIsAscii ($ callback , $ default = null )
891
861
{
892
- if ($ this ->isAscii ()) {
893
- $ result = $ callback ($ this );
894
-
895
- return $ result ?? $ this ;
896
- } elseif ($ default ) {
897
- $ result = $ default ($ this );
898
-
899
- return $ result ?? $ this ;
900
- }
901
-
902
- return $ this ;
862
+ return $ this ->when ($ this ->isAscii (), $ callback , $ default );
903
863
}
904
864
905
865
/**
@@ -911,17 +871,7 @@ public function whenIsAscii($callback, $default = null)
911
871
*/
912
872
public function whenIsUuid ($ callback , $ default = null )
913
873
{
914
- if ($ this ->isUuid ()) {
915
- $ result = $ callback ($ this );
916
-
917
- return $ result ?? $ this ;
918
- } elseif ($ default ) {
919
- $ result = $ default ($ this );
920
-
921
- return $ result ?? $ this ;
922
- }
923
-
924
- return $ this ;
874
+ return $ this ->when ($ this ->isUuid (), $ callback , $ default );
925
875
}
926
876
927
877
/**
@@ -934,17 +884,7 @@ public function whenIsUuid($callback, $default = null)
934
884
*/
935
885
public function whenTest ($ pattern , $ callback , $ default = null )
936
886
{
937
- if ($ this ->test ($ pattern )) {
938
- $ result = $ callback ($ this );
939
-
940
- return $ result ?? $ this ;
941
- } elseif ($ default ) {
942
- $ result = $ default ($ this );
943
-
944
- return $ result ?? $ this ;
945
- }
946
-
947
- return $ this ;
887
+ return $ this ->when ($ this ->test ($ pattern ), $ callback , $ default );
948
888
}
949
889
950
890
/**
@@ -957,17 +897,7 @@ public function whenTest($pattern, $callback, $default = null)
957
897
*/
958
898
public function whenStartsWith ($ needles , $ callback , $ default = null )
959
899
{
960
- if ($ this ->startsWith ($ needles )) {
961
- $ result = $ callback ($ this );
962
-
963
- return $ result ?? $ this ;
964
- } elseif ($ default ) {
965
- $ result = $ default ($ this );
966
-
967
- return $ result ?? $ this ;
968
- }
969
-
970
- return $ this ;
900
+ return $ this ->when ($ this ->startsWith ($ needles ), $ callback , $ default );
971
901
}
972
902
973
903
/**
0 commit comments