1 | <?php |
||
26 | class Registry |
||
27 | { |
||
28 | /** |
||
29 | * @var array<string,callable> Associative array of definition name to function callback |
||
30 | */ |
||
31 | private $definitions = []; |
||
32 | |||
33 | /** |
||
34 | * @var array<string,callable> Associative array of definition name to function callback |
||
35 | */ |
||
36 | private static $defaultDefinitions = [ |
||
37 | 'required' => ['Caridea\Validate\Rule\Blank', 'required'], |
||
38 | 'not_empty' => ['Caridea\Validate\Rule\Blank', 'notEmpty'], |
||
39 | 'not_empty_list' => ['Caridea\Validate\Rule\Blank', 'notEmptyList'], |
||
40 | 'one_of' => ['Caridea\Validate\Rule\Compare', 'oneOf'], |
||
41 | 'min_length' => ['Caridea\Validate\Rule\Length', 'min'], |
||
42 | 'max_length' => ['Caridea\Validate\Rule\Length', 'max'], |
||
43 | 'length_equal' => ['Caridea\Validate\Rule\Length', 'equal'], |
||
44 | 'length_between' => ['Caridea\Validate\Rule\Length', 'between'], |
||
45 | 'like' => ['Caridea\Validate\Rule\Match', 'like'], |
||
46 | 'integer' => ['Caridea\Validate\Rule\Compare', 'integer'], |
||
47 | 'positive_integer' => ['Caridea\Validate\Rule\Compare', 'positiveInteger'], |
||
48 | 'decimal' => ['Caridea\Validate\Rule\Compare', 'decimal'], |
||
49 | 'positive_decimal' => ['Caridea\Validate\Rule\Compare', 'positiveDecimal'], |
||
50 | 'min_number' => ['Caridea\Validate\Rule\Compare', 'min'], |
||
51 | 'max_number' => ['Caridea\Validate\Rule\Compare', 'max'], |
||
52 | 'number_between' => ['Caridea\Validate\Rule\Compare', 'between'], |
||
53 | 'email' => ['Caridea\Validate\Rule\Match', 'email'], |
||
54 | 'iso_date' => ['Caridea\Validate\Rule\Match', 'isoDate'], |
||
55 | 'url' => ['Caridea\Validate\Rule\Match', 'url'], |
||
56 | 'timezone' => ['Caridea\Validate\Rule\Timezone', 'timezone'], |
||
57 | 'equal_to_field' => ['Caridea\Validate\Rule\Compare', 'equalToField'], |
||
58 | 'nested_object' => ['Caridea\Validate\Rule\Nested', 'nestedObject'], |
||
59 | 'list_of' => ['Caridea\Validate\Rule\Nested', 'listOf'], |
||
60 | 'list_of_objects' => ['Caridea\Validate\Rule\Nested', 'listOfObjects'], |
||
61 | 'list_of_different_objects' => ['Caridea\Validate\Rule\Nested', 'listOfDifferentObjects'], |
||
62 | ]; |
||
63 | |||
64 | /** |
||
65 | * Creates a new Validation rule registry. |
||
66 | */ |
||
67 | 4 | public function __construct() |
|
71 | |||
72 | /** |
||
73 | * Registers rule definitions. |
||
74 | * |
||
75 | * ```php |
||
76 | * $registry = new \Caridea\Validate\Registry(); |
||
77 | * $registry->register([ |
||
78 | * 'adult' => ['My\Validate\AgeRule', 'adult'], |
||
79 | * 'credit_card' => function(){return new CreditCardRule();}, |
||
80 | * 'something' => 'my_function_that_can_be_called' |
||
81 | * ]); |
||
82 | * ``` |
||
83 | * |
||
84 | * @param array<string,callable> $definitions Associative array of definition name to function callback |
||
85 | * @return $this provides a fluent interface |
||
86 | */ |
||
87 | 2 | public function register(array $definitions): self |
|
97 | |||
98 | /** |
||
99 | * Constructs a validation rule. |
||
100 | * |
||
101 | * @param string $name A string name |
||
102 | * @param mixed $arg Optional constructor argument, or an array of arguments |
||
103 | * @return \Caridea\Validate\Rule The instantiated rule |
||
104 | * @throws \InvalidArgumentException if the rule name is not registered |
||
105 | * @throws \UnexpectedValueException if the factory returns a non-Rule |
||
106 | */ |
||
107 | 3 | public function factory(string $name, $arg = null): Rule |
|
120 | |||
121 | /** |
||
122 | * Creates a new Builder using this Repository. |
||
123 | * |
||
124 | * @return \Caridea\Validate\Builder The builder |
||
125 | */ |
||
126 | 1 | public function builder(): Builder |
|
130 | } |
||
131 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..