File tree Expand file tree Collapse file tree 5 files changed +12
-36
lines changed
Expand file tree Collapse file tree 5 files changed +12
-36
lines changed Original file line number Diff line number Diff line change 1010use Hypervel \Queue \Contracts \Job as JobContract ;
1111use Hypervel \Queue \Exceptions \ManuallyFailedException ;
1212use Hypervel \Queue \Jobs \FakeJob ;
13- use InvalidArgumentException ;
1413use PHPUnit \Framework \Assert as PHPUnit ;
1514use RuntimeException ;
1615use Throwable ;
@@ -52,13 +51,8 @@ public function fail(string|Throwable|null $exception = null): void
5251 $ exception = new ManuallyFailedException ($ exception );
5352 }
5453
55- if ($ exception instanceof Throwable || is_null ($ exception )) {
56- if ($ this ->job ) {
57- $ this ->job ->fail ($ exception );
58- return ;
59- }
60- } else {
61- throw new InvalidArgumentException ('The fail method requires a string or an instance of Throwable. ' );
54+ if ($ this ->job ) {
55+ $ this ->job ->fail ($ exception );
6256 }
6357 }
6458
Original file line number Diff line number Diff line change 55namespace Hypervel \Validation \Rules ;
66
77use Closure ;
8- use InvalidArgumentException ;
98use Stringable ;
109
1110class ExcludeIf implements Stringable
@@ -17,18 +16,10 @@ class ExcludeIf implements Stringable
1716
1817 /**
1918 * Create a new exclude validation rule based on a condition.
20- *
21- * @param bool|Closure $condition
22- *
23- * @throws InvalidArgumentException
2419 */
25- public function __construct (mixed $ condition )
20+ public function __construct (bool | Closure $ condition )
2621 {
27- if ($ condition instanceof Closure || is_bool ($ condition )) {
28- $ this ->condition = $ condition ;
29- } else {
30- throw new InvalidArgumentException ('The provided condition must be a callable or boolean. ' );
31- }
22+ $ this ->condition = $ condition ;
3223 }
3324
3425 /**
Original file line number Diff line number Diff line change 55namespace Hypervel \Validation \Rules ;
66
77use Closure ;
8- use InvalidArgumentException ;
98use Stringable ;
109
1110class ProhibitedIf implements Stringable
@@ -17,18 +16,10 @@ class ProhibitedIf implements Stringable
1716
1817 /**
1918 * Create a new prohibited validation rule based on a condition.
20- *
21- * @param bool|Closure $condition
22- *
23- * @throws InvalidArgumentException
2419 */
25- public function __construct (mixed $ condition )
20+ public function __construct (bool | Closure $ condition )
2621 {
27- if ($ condition instanceof Closure || is_bool ($ condition )) {
28- $ this ->condition = $ condition ;
29- } else {
30- throw new InvalidArgumentException ('The provided condition must be a callable or boolean. ' );
31- }
22+ $ this ->condition = $ condition ;
3223 }
3324
3425 /**
Original file line number Diff line number Diff line change 99use Hypervel \Translation \Translator ;
1010use Hypervel \Validation \Rules \ExcludeIf ;
1111use Hypervel \Validation \Validator ;
12- use InvalidArgumentException ;
1312use PHPUnit \Framework \TestCase ;
1413use stdClass ;
14+ use TypeError ;
1515
1616/**
1717 * @internal
@@ -52,8 +52,8 @@ public function testItValidatesCallableAndBooleanAreAcceptableArguments()
5252 try {
5353 new ExcludeIf ($ condition );
5454 $ this ->fail ('The ExcludeIf constructor must not accept ' . gettype ($ condition ));
55- } catch (InvalidArgumentException $ exception ) {
56- $ this ->assertEquals ( ' The provided condition must be a callable or boolean. ' , $ exception -> getMessage ());
55+ } catch (TypeError ) {
56+ $ this ->assertTrue ( true ); // Invalid types correctly rejected by PHP type system
5757 }
5858 }
5959 }
Original file line number Diff line number Diff line change 99use Hypervel \Translation \Translator ;
1010use Hypervel \Validation \Rules \ProhibitedIf ;
1111use Hypervel \Validation \Validator ;
12- use InvalidArgumentException ;
1312use PHPUnit \Framework \TestCase ;
1413use stdClass ;
14+ use TypeError ;
1515
1616/**
1717 * @internal
@@ -52,8 +52,8 @@ public function testItValidatesCallableAndBooleanAreAcceptableArguments()
5252 try {
5353 new ProhibitedIf ($ condition );
5454 $ this ->fail ('The ProhibitedIf constructor must not accept ' . gettype ($ condition ));
55- } catch (InvalidArgumentException $ exception ) {
56- $ this ->assertEquals ( ' The provided condition must be a callable or boolean. ' , $ exception -> getMessage ());
55+ } catch (TypeError ) {
56+ $ this ->assertTrue ( true ); // Invalid types correctly rejected by PHP type system
5757 }
5858 }
5959 }
You can’t perform that action at this time.
0 commit comments