Conditions | 1 |
Paths | 1 |
Total Lines | 178 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
37 | public function provideValidFilterData() : array |
||
38 | { |
||
39 | return [ |
||
40 | 'not required field not present' => [ |
||
41 | 'spec' => ['fieldOne' => ['required' => false]], |
||
42 | 'input' => [], |
||
43 | 'options' => [], |
||
44 | 'result' => [true, [], null, []], |
||
45 | ], |
||
46 | 'Required With A Default Without Input' => [ |
||
47 | 'spec' => ['fieldOne' => ['required' => true, 'default' => 'theDefault']], |
||
48 | 'input' => [], |
||
49 | 'options' => [], |
||
50 | 'result' => [true, ['fieldOne' => 'theDefault'], null, []], |
||
51 | ], |
||
52 | 'Required With A Null Default Without Input' => [ |
||
53 | 'spec' => ['fieldOne' => ['required' => true, 'default' => null]], |
||
54 | 'input' => [], |
||
55 | 'options' => [], |
||
56 | 'result' => [true, ['fieldOne' => null], null, []], |
||
57 | ], |
||
58 | 'Required With A Default With Input' => [ |
||
59 | 'spec' => ['fieldOne' => ['required' => true, 'default' => 'theDefault']], |
||
60 | 'input' => ['fieldOne' => 'notTheDefault'], |
||
61 | 'options' => [], |
||
62 | 'result' => [true, ['fieldOne' => 'notTheDefault'], null, []], |
||
63 | ], |
||
64 | 'Not Required With A Default Without Input' => [ |
||
65 | 'spec' => ['fieldOne' => ['default' => 'theDefault']], |
||
66 | 'input' => [], |
||
67 | 'options' => [], |
||
68 | 'result' => [true, ['fieldOne' => 'theDefault'], null, []], |
||
69 | ], |
||
70 | 'Not Required With A Default With Input' => [ |
||
71 | 'spec' => ['fieldOne' => ['default' => 'theDefault']], |
||
72 | 'input' => ['fieldOne' => 'notTheDefault'], |
||
73 | 'options' => [], |
||
74 | 'result' => [true, ['fieldOne' => 'notTheDefault'], null, []], |
||
75 | ], |
||
76 | 'Required Fail' => [ |
||
77 | 'spec' => ['fieldOne' => ['required' => true]], |
||
78 | 'input' => [], |
||
79 | 'options' => [], |
||
80 | 'result' => [false, null, "Field 'fieldOne' was required and not present", []], |
||
81 | ], |
||
82 | 'Required Default Pass' => [ |
||
83 | 'spec' => ['fieldOne' => []], |
||
84 | 'input' => [], |
||
85 | 'options' => [], |
||
86 | 'result' => [true, [], null, []], |
||
87 | ], |
||
88 | 'requiredDefaultFail' => [ |
||
89 | 'spec' => ['fieldOne' => []], |
||
90 | 'input' => [], |
||
91 | 'options' => ['defaultRequired' => true], |
||
92 | 'result' => [false, null, "Field 'fieldOne' was required and not present", []], |
||
93 | ], |
||
94 | 'filterPass' => [ |
||
95 | 'spec' => ['fieldOne' => [['floatval']]], |
||
96 | 'input' => ['fieldOne' => '3.14'], |
||
97 | 'options' => [], |
||
98 | 'result' => [true, ['fieldOne' => 3.14], null, []], |
||
99 | ], |
||
100 | 'filterDefaultShortNamePass' => [ |
||
101 | 'spec' => ['fieldOne' => [['float']]], |
||
102 | 'input' => ['fieldOne' => '3.14'], |
||
103 | 'options' => [], |
||
104 | 'result' => [true, ['fieldOne' => 3.14], null, []], |
||
105 | ], |
||
106 | 'filterFail' => [ |
||
107 | 'spec' => ['fieldOne' => [['\TraderInteractive\FiltererTest::failingFilter']]], |
||
108 | 'input' => ['fieldOne' => 'valueOne'], |
||
109 | 'options' => [], |
||
110 | 'result' => [ |
||
111 | false, |
||
112 | null, |
||
113 | "Field 'fieldOne' with value 'valueOne' failed filtering, message 'i failed'", |
||
114 | [], |
||
115 | ], |
||
116 | ], |
||
117 | 'chainPass' => [ |
||
118 | 'spec' => ['fieldOne' => [['trim', 'a'], ['floatval']]], |
||
119 | 'input' => ['fieldOne' => 'a3.14'], |
||
120 | 'options' => [], |
||
121 | 'result' => [true, ['fieldOne' => 3.14], null, []], |
||
122 | ], |
||
123 | 'chainFail' => [ |
||
124 | 'spec' => ['fieldOne' => [['trim'], ['\TraderInteractive\FiltererTest::failingFilter']]], |
||
125 | 'input' => ['fieldOne' => 'the value'], |
||
126 | 'options' => [], |
||
127 | 'result' => [ |
||
128 | false, |
||
129 | null, |
||
130 | "Field 'fieldOne' with value 'the value' failed filtering, message 'i failed'", |
||
131 | [], |
||
132 | ], |
||
133 | ], |
||
134 | 'multiInputPass' => [ |
||
135 | 'spec' => ['fieldOne' => [['trim']], 'fieldTwo' => [['strtoupper']]], |
||
136 | 'input' => ['fieldOne' => ' value', 'fieldTwo' => 'bob'], |
||
137 | 'options' => [], |
||
138 | 'result' => [true, ['fieldOne' => 'value', 'fieldTwo' => 'BOB'], null, []], |
||
139 | ], |
||
140 | 'multiInputFail' => [ |
||
141 | 'spec' => [ |
||
142 | 'fieldOne' => [['\TraderInteractive\FiltererTest::failingFilter']], |
||
143 | 'fieldTwo' => [['\TraderInteractive\FiltererTest::failingFilter']], |
||
144 | ], |
||
145 | 'input' => ['fieldOne' => 'value one', 'fieldTwo' => 'value two'], |
||
146 | 'options' => [], |
||
147 | 'result' => [ |
||
148 | false, |
||
149 | null, |
||
150 | "Field 'fieldOne' with value 'value one' failed filtering, message 'i failed'\n" |
||
151 | . "Field 'fieldTwo' with value 'value two' failed filtering, message 'i failed'", |
||
152 | [], |
||
153 | ], |
||
154 | ], |
||
155 | 'emptyFilter' => [ |
||
156 | 'spec' => ['fieldOne' => [[]]], |
||
157 | 'input' => ['fieldOne' => 0], |
||
158 | 'options' => [], |
||
159 | 'result' => [true, ['fieldOne' => 0], null, []], |
||
160 | ], |
||
161 | 'unknownsAllowed' => [ |
||
162 | 'spec' => [], |
||
163 | 'input'=> ['fieldTwo' => 0], |
||
164 | 'options' => ['allowUnknowns' => true], |
||
165 | 'result' => [true, [], null, ['fieldTwo' => 0]], |
||
166 | ], |
||
167 | 'unknownsNotAllowed' => [ |
||
168 | 'spec' => [], |
||
169 | 'input' => ['fieldTwo' => 0], |
||
170 | 'options' => [], |
||
171 | 'result' => [false, null, "Field 'fieldTwo' with value '0' is unknown", ['fieldTwo' => 0]], |
||
172 | ], |
||
173 | 'objectFilter' => [ |
||
174 | 'spec' => ['fieldOne' => [[[$this, 'passingFilter']]]], |
||
175 | 'input' => ['fieldOne' => 'foo'], |
||
176 | 'options' => [], |
||
177 | 'result' => [true, ['fieldOne' => 'fooboo'], null, []], |
||
178 | ], |
||
179 | 'filterWithCustomError' => [ |
||
180 | 'spec' => [ |
||
181 | 'fieldOne' => [ |
||
182 | 'error' => 'My custom error message', |
||
183 | ['\TraderInteractive\FiltererTest::failingFilter'], |
||
184 | ], |
||
185 | ], |
||
186 | 'input' => ['fieldOne' => 'valueOne'], |
||
187 | 'options' => [], |
||
188 | 'result' => [false, null, 'My custom error message', []], |
||
189 | ], |
||
190 | 'filterWithCustomErrorContainingValuePlaceholder' => [ |
||
191 | 'spec' => [ |
||
192 | 'fieldOne' => [ |
||
193 | 'error' => "The value '{value}' is invalid.", |
||
194 | ['uint'], |
||
195 | ], |
||
196 | ], |
||
197 | 'input' => ['fieldOne' => 'abc'], |
||
198 | 'options' => [], |
||
199 | 'result' => [false, null, "The value 'abc' is invalid.", []], |
||
200 | ], |
||
201 | 'arrayizeAliasIsCalledProperly' => [ |
||
202 | 'spec' => ['field' => [['arrayize']]], |
||
203 | 'input' => ['field' => 'a string value'], |
||
204 | 'options' => [], |
||
205 | 'result' => [true, ['field' => ['a string value']], null, []], |
||
206 | ], |
||
207 | 'concatAliasIsCalledProperly' => [ |
||
208 | 'spec' => ['field' => [['concat', '%', '%']]], |
||
209 | 'input' => ['field' => 'value'], |
||
210 | 'options' => [], |
||
211 | 'result' => [true, ['field' => '%value%'], null, []], |
||
212 | ], |
||
213 | ]; |
||
214 | } |
||
215 | |||
574 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: