@@ -791,6 +791,40 @@ public function whenContainsAll(array $needles, $callback, $default = null)
791
791
return $ this ->when ($ this ->containsAll ($ needles ), $ callback , $ default );
792
792
}
793
793
794
+ /**
795
+ * Execute the given callback if the string is empty.
796
+ *
797
+ * @param callable $callback
798
+ * @return static
799
+ */
800
+ public function whenEmpty ($ callback )
801
+ {
802
+ if ($ this ->isEmpty ()) {
803
+ $ result = $ callback ($ this );
804
+
805
+ return is_null ($ result ) ? $ this : $ result ;
806
+ }
807
+
808
+ return $ this ;
809
+ }
810
+
811
+ /**
812
+ * Execute the given callback if the string is not empty.
813
+ *
814
+ * @param callable $callback
815
+ * @return static
816
+ */
817
+ public function whenNotEmpty ($ callback )
818
+ {
819
+ if ($ this ->isNotEmpty ()) {
820
+ $ result = $ callback ($ this );
821
+
822
+ return is_null ($ result ) ? $ this : $ result ;
823
+ }
824
+
825
+ return $ this ;
826
+ }
827
+
794
828
/**
795
829
* Execute the given callback if the string ends with a given substring.
796
830
*
@@ -854,19 +888,6 @@ public function whenIsUuid($callback, $default = null)
854
888
return $ this ->when ($ this ->isUuid (), $ callback , $ default );
855
889
}
856
890
857
- /**
858
- * Execute the given callback if the string matches the given pattern.
859
- *
860
- * @param string $pattern
861
- * @param callable $callback
862
- * @param callable|null $default
863
- * @return static
864
- */
865
- public function whenTest ($ pattern , $ callback , $ default = null )
866
- {
867
- return $ this ->when ($ this ->test ($ pattern ), $ callback , $ default );
868
- }
869
-
870
891
/**
871
892
* Execute the given callback if the string starts with a given substring.
872
893
*
@@ -881,37 +902,16 @@ public function whenStartsWith($needles, $callback, $default = null)
881
902
}
882
903
883
904
/**
884
- * Execute the given callback if the string is empty.
885
- *
886
- * @param callable $callback
887
- * @return static
888
- */
889
- public function whenEmpty ($ callback )
890
- {
891
- if ($ this ->isEmpty ()) {
892
- $ result = $ callback ($ this );
893
-
894
- return is_null ($ result ) ? $ this : $ result ;
895
- }
896
-
897
- return $ this ;
898
- }
899
-
900
- /**
901
- * Execute the given callback if the string is not empty.
905
+ * Execute the given callback if the string matches the given pattern.
902
906
*
907
+ * @param string $pattern
903
908
* @param callable $callback
909
+ * @param callable|null $default
904
910
* @return static
905
911
*/
906
- public function whenNotEmpty ( $ callback )
912
+ public function whenTest ( $ pattern , $ callback, $ default = null )
907
913
{
908
- if ($ this ->isNotEmpty ()) {
909
- $ result = $ callback ($ this );
910
-
911
- return is_null ($ result ) ? $ this : $ result ;
912
- }
913
-
914
- return $ this ;
914
+ return $ this ->when ($ this ->test ($ pattern ), $ callback , $ default );
915
915
}
916
916
917
917
/**
0 commit comments