1 | <?php |
||
19 | abstract class Assert |
||
20 | { |
||
21 | /** @var string */ |
||
22 | protected static $lazyAssertionExceptionClass = LazyAssertionException::class; |
||
23 | |||
24 | /** @var string */ |
||
25 | protected static $assertionClass = Assertion::class; |
||
26 | |||
27 | /** |
||
28 | * Start validation on a value, returns {@link AssertionChain} |
||
29 | * |
||
30 | * The invocation of this method starts an assertion chain |
||
31 | * that is happening on the passed value. |
||
32 | * |
||
33 | * @example |
||
34 | * |
||
35 | * Assert::that($value)->notEmpty()->integer(); |
||
36 | * Assert::that($value)->nullOr()->string()->startsWith("Foo"); |
||
37 | * |
||
38 | * The assertion chain can be stateful, that means be careful when you reuse |
||
39 | * it. You should never pass around the chain. |
||
40 | * |
||
41 | * @param mixed $value |
||
42 | * @param string $defaultMessage |
||
|
|||
43 | * @param string $defaultPropertyPath |
||
44 | * |
||
45 | * @return \Assert\AssertionChain |
||
46 | */ |
||
47 | public static function that($value, $defaultMessage = null, $defaultPropertyPath = null) |
||
48 | { |
||
49 | return (new AssertionChain($value, $defaultMessage, $defaultPropertyPath)) |
||
50 | ->setAssertionClassName(static::$assertionClass) |
||
51 | ; |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Start validation on a set of values, returns {@link AssertionChain} |
||
56 | * |
||
57 | * @param mixed $values |
||
58 | * @param string $defaultMessage |
||
59 | * @param string $defaultPropertyPath |
||
60 | * |
||
61 | * @return \Assert\AssertionChain |
||
62 | */ |
||
63 | public static function thatAll($values, $defaultMessage = null, $defaultPropertyPath = null) |
||
67 | |||
68 | /** |
||
69 | * Start validation and allow NULL, returns {@link AssertionChain} |
||
70 | * |
||
71 | * @param mixed $value |
||
72 | * @param string $defaultMessage |
||
73 | * @param string $defaultPropertyPath |
||
74 | * |
||
75 | * @return \Assert\AssertionChain |
||
76 | */ |
||
77 | public static function thatNullOr($value, $defaultMessage = null, $defaultPropertyPath = null) |
||
81 | |||
82 | /** |
||
83 | * Create a lazy assertion object. |
||
84 | * |
||
85 | * @return \Assert\LazyAssertion |
||
86 | */ |
||
87 | public static function lazy() |
||
93 | } |
||
94 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.