| Conditions | 1 | 
| Paths | 1 | 
| Total Lines | 226 | 
| Code Lines | 144 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 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  | 
            ||
| 147 | public function testFilterRules()  | 
            ||
| 148 | 	{ | 
            ||
| 149 | $filter = new DummyFilter();  | 
            ||
| 150 | |||
| 151 | $filter->setRuleFactory(new RuleFactory());  | 
            ||
| 152 | |||
| 153 | $rules = $filter->getRules();  | 
            ||
| 154 | |||
| 155 | $expected = [  | 
            ||
| 156 | 'filter' => FILTER_VALIDATE_BOOL,  | 
            ||
| 157 | 'flags' => FILTER_NULL_ON_FAILURE,  | 
            ||
| 158 | ];  | 
            ||
| 159 | |||
| 160 | $this->assertEquals(new Rule(FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE), $rules['test_valid_bool']);  | 
            ||
| 161 | $this->assertEquals($expected, $rules['test_valid_bool']->toArray());  | 
            ||
| 162 | |||
| 163 | $expected = [  | 
            ||
| 164 | 'filter' => FILTER_VALIDATE_DOMAIN,  | 
            ||
| 165 | 'flags' => 0,  | 
            ||
| 166 | ];  | 
            ||
| 167 | |||
| 168 | $this->assertEquals(new Rule(FILTER_VALIDATE_DOMAIN), $rules['test_valid_domain']);  | 
            ||
| 169 | $this->assertEquals($expected, $rules['test_valid_domain']->toArray());  | 
            ||
| 170 | |||
| 171 | $expected = [  | 
            ||
| 172 | 'filter' => FILTER_VALIDATE_EMAIL,  | 
            ||
| 173 | 'flags' => 0,  | 
            ||
| 174 | ];  | 
            ||
| 175 | |||
| 176 | $this->assertEquals(new Rule(FILTER_VALIDATE_EMAIL), $rules['test_valid_email']);  | 
            ||
| 177 | $this->assertEquals($expected, $rules['test_valid_email']->toArray());  | 
            ||
| 178 | |||
| 179 | $expected = [  | 
            ||
| 180 | 'filter' => FILTER_VALIDATE_FLOAT,  | 
            ||
| 181 | 'flags' => 0,  | 
            ||
| 182 | 'options' => [  | 
            ||
| 183 | 'min_range' => -100,  | 
            ||
| 184 | 'max_range' => 100,  | 
            ||
| 185 | 'decimal' => 2,  | 
            ||
| 186 | ]  | 
            ||
| 187 | ];  | 
            ||
| 188 | |||
| 189 | $this->assertEquals(  | 
            ||
| 190 | new Rule(FILTER_VALIDATE_FLOAT, 0, ['min_range' => -100, 'max_range' => 100, 'decimal' => 2]),  | 
            ||
| 191 | $rules['test_valid_float']  | 
            ||
| 192 | );  | 
            ||
| 193 | $this->assertEquals($expected, $rules['test_valid_float']->toArray());  | 
            ||
| 194 | |||
| 195 | $expected = [  | 
            ||
| 196 | 'filter' => FILTER_VALIDATE_INT,  | 
            ||
| 197 | 'flags' => 0,  | 
            ||
| 198 | 'options' => [  | 
            ||
| 199 | 'min_range' => -100,  | 
            ||
| 200 | 'max_range' => 100,  | 
            ||
| 201 | ]  | 
            ||
| 202 | ];  | 
            ||
| 203 | |||
| 204 | $this->assertEquals(  | 
            ||
| 205 | new Rule(FILTER_VALIDATE_INT, 0, ['min_range' => -100, 'max_range' => 100]),  | 
            ||
| 206 | $rules['test_valid_int']  | 
            ||
| 207 | );  | 
            ||
| 208 | $this->assertEquals($expected, $rules['test_valid_int']->toArray());  | 
            ||
| 209 | |||
| 210 | $expected = [  | 
            ||
| 211 | 'filter' => FILTER_VALIDATE_IP,  | 
            ||
| 212 | 'flags' => 0,  | 
            ||
| 213 | ];  | 
            ||
| 214 | |||
| 215 | $this->assertEquals(new Rule(FILTER_VALIDATE_IP), $rules['test_valid_ip_address']);  | 
            ||
| 216 | $this->assertEquals($expected, $rules['test_valid_ip_address']->toArray());  | 
            ||
| 217 | |||
| 218 | $expected = [  | 
            ||
| 219 | 'filter' => FILTER_VALIDATE_MAC,  | 
            ||
| 220 | 'flags' => 0,  | 
            ||
| 221 | ];  | 
            ||
| 222 | |||
| 223 | $this->assertEquals(new Rule(FILTER_VALIDATE_MAC), $rules['test_valid_mac_address']);  | 
            ||
| 224 | $this->assertEquals($expected, $rules['test_valid_mac_address']->toArray());  | 
            ||
| 225 | |||
| 226 | $expected = [  | 
            ||
| 227 | 'filter' => FILTER_VALIDATE_REGEXP,  | 
            ||
| 228 | 'flags' => 0,  | 
            ||
| 229 | 'options' => [  | 
            ||
| 230 | 'regexp' => '/^valid value$/i',  | 
            ||
| 231 | ]  | 
            ||
| 232 | ];  | 
            ||
| 233 | |||
| 234 | $this->assertEquals(  | 
            ||
| 235 | new Rule(FILTER_VALIDATE_REGEXP, 0, ['regexp' => '/^valid value$/i']),  | 
            ||
| 236 | $rules['test_valid_regexp']  | 
            ||
| 237 | );  | 
            ||
| 238 | $this->assertEquals($expected, $rules['test_valid_regexp']->toArray());  | 
            ||
| 239 | |||
| 240 | $expected = [  | 
            ||
| 241 | 'filter' => FILTER_SANITIZE_ADD_SLASHES,  | 
            ||
| 242 | 'flags' => 0,  | 
            ||
| 243 | ];  | 
            ||
| 244 | |||
| 245 | $this->assertEquals(  | 
            ||
| 246 | new Rule(FILTER_SANITIZE_ADD_SLASHES),  | 
            ||
| 247 | $rules['test_add_slashes']  | 
            ||
| 248 | );  | 
            ||
| 249 | $this->assertEquals($expected, $rules['test_add_slashes']->toArray());  | 
            ||
| 250 | |||
| 251 | $expected = [  | 
            ||
| 252 | 'filter' => FILTER_SANITIZE_EMAIL,  | 
            ||
| 253 | 'flags' => 0,  | 
            ||
| 254 | ];  | 
            ||
| 255 | |||
| 256 | $this->assertEquals(  | 
            ||
| 257 | new Rule(FILTER_SANITIZE_EMAIL),  | 
            ||
| 258 | $rules['test_clean_email']  | 
            ||
| 259 | );  | 
            ||
| 260 | $this->assertEquals($expected, $rules['test_clean_email']->toArray());  | 
            ||
| 261 | |||
| 262 | $expected = [  | 
            ||
| 263 | 'filter' => FILTER_SANITIZE_ENCODED,  | 
            ||
| 264 | 'flags' => 0,  | 
            ||
| 265 | ];  | 
            ||
| 266 | |||
| 267 | $this->assertEquals(  | 
            ||
| 268 | new Rule(FILTER_SANITIZE_ENCODED),  | 
            ||
| 269 | $rules['test_clean_encoded']  | 
            ||
| 270 | );  | 
            ||
| 271 | $this->assertEquals($expected, $rules['test_clean_encoded']->toArray());  | 
            ||
| 272 | |||
| 273 | $expected = [  | 
            ||
| 274 | 'filter' => FILTER_SANITIZE_NUMBER_FLOAT,  | 
            ||
| 275 | 'flags' => 0,  | 
            ||
| 276 | ];  | 
            ||
| 277 | |||
| 278 | $this->assertEquals(  | 
            ||
| 279 | new Rule(FILTER_SANITIZE_NUMBER_FLOAT),  | 
            ||
| 280 | $rules['test_clean_float']  | 
            ||
| 281 | );  | 
            ||
| 282 | $this->assertEquals($expected, $rules['test_clean_float']->toArray());  | 
            ||
| 283 | |||
| 284 | $expected = [  | 
            ||
| 285 | 'filter' => FILTER_SANITIZE_FULL_SPECIAL_CHARS,  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 286 | 'flags' => 0,  | 
            ||
| 287 | ];  | 
            ||
| 288 | |||
| 289 | $this->assertEquals(  | 
            ||
| 290 | new Rule(FILTER_SANITIZE_FULL_SPECIAL_CHARS),  | 
            ||
| 291 | $rules['test_clean_full_special_chars']  | 
            ||
| 292 | );  | 
            ||
| 293 | $this->assertEquals($expected, $rules['test_clean_full_special_chars']->toArray());  | 
            ||
| 294 | |||
| 295 | $expected = [  | 
            ||
| 296 | 'filter' => FILTER_SANITIZE_NUMBER_INT,  | 
            ||
| 297 | 'flags' => 0,  | 
            ||
| 298 | ];  | 
            ||
| 299 | |||
| 300 | $this->assertEquals(  | 
            ||
| 301 | new Rule(FILTER_SANITIZE_NUMBER_INT),  | 
            ||
| 302 | $rules['test_clean_int']  | 
            ||
| 303 | );  | 
            ||
| 304 | $this->assertEquals($expected, $rules['test_clean_int']->toArray());  | 
            ||
| 305 | |||
| 306 | $expected = [  | 
            ||
| 307 | 'filter' => FILTER_SANITIZE_SPECIAL_CHARS,  | 
            ||
| 308 | 'flags' => 0,  | 
            ||
| 309 | ];  | 
            ||
| 310 | |||
| 311 | $this->assertEquals(  | 
            ||
| 312 | new Rule(FILTER_SANITIZE_SPECIAL_CHARS),  | 
            ||
| 313 | $rules['test_clean_special_chars']  | 
            ||
| 314 | );  | 
            ||
| 315 | $this->assertEquals($expected, $rules['test_clean_special_chars']->toArray());  | 
            ||
| 316 | |||
| 317 | $expected = [  | 
            ||
| 318 | 'filter' => FILTER_SANITIZE_STRING,  | 
            ||
| 319 | 'flags' => 0,  | 
            ||
| 320 | ];  | 
            ||
| 321 | |||
| 322 | $this->assertEquals(  | 
            ||
| 323 | new Rule(FILTER_SANITIZE_STRING),  | 
            ||
| 324 | $rules['test_clean_string']  | 
            ||
| 325 | );  | 
            ||
| 326 | $this->assertEquals($expected, $rules['test_clean_string']->toArray());  | 
            ||
| 327 | |||
| 328 | $expected = [  | 
            ||
| 329 | 'filter' => FILTER_UNSAFE_RAW,  | 
            ||
| 330 | 'flags' => 0,  | 
            ||
| 331 | ];  | 
            ||
| 332 | |||
| 333 | $this->assertEquals(  | 
            ||
| 334 | new Rule(FILTER_UNSAFE_RAW),  | 
            ||
| 335 | $rules['test_clean_unsafe']  | 
            ||
| 336 | );  | 
            ||
| 337 | $this->assertEquals($expected, $rules['test_clean_unsafe']->toArray());  | 
            ||
| 338 | |||
| 339 | $expected = [  | 
            ||
| 340 | 'filter' => FILTER_SANITIZE_URL,  | 
            ||
| 341 | 'flags' => 0,  | 
            ||
| 342 | ];  | 
            ||
| 343 | |||
| 344 | $this->assertEquals(  | 
            ||
| 345 | new Rule(FILTER_SANITIZE_URL),  | 
            ||
| 346 | $rules['test_clean_url']  | 
            ||
| 347 | );  | 
            ||
| 348 | $this->assertEquals($expected, $rules['test_clean_url']->toArray());  | 
            ||
| 349 | |||
| 350 | $expected = [  | 
            ||
| 351 | 'filter' => FILTER_CALLBACK,  | 
            ||
| 352 | 'flags' => 0,  | 
            ||
| 353 | 			'options' => Closure::fromCallable('trim'), | 
            ||
| 354 | ];  | 
            ||
| 355 | |||
| 356 | $this->assertEquals(  | 
            ||
| 357 | 			(new Rule(FILTER_CALLBACK))->setCallback(Closure::fromCallable('trim')), | 
            ||
| 358 | $rules['test_callable']  | 
            ||
| 359 | );  | 
            ||
| 360 | $this->assertEquals($expected, $rules['test_callable']->toArray());  | 
            ||
| 361 | |||
| 362 | $expected = [  | 
            ||
| 363 | 'filter' => FILTER_CALLBACK,  | 
            ||
| 364 | 'flags' => 0,  | 
            ||
| 365 | 'options' => $filter->mult(2),  | 
            ||
| 366 | ];  | 
            ||
| 367 | |||
| 368 | $this->assertEquals(  | 
            ||
| 369 | (new Rule(FILTER_CALLBACK))->setCallback($filter->mult(2)),  | 
            ||
| 370 | $rules['test_closure']  | 
            ||
| 371 | );  | 
            ||
| 372 | $this->assertEquals($expected, $rules['test_closure']->toArray());  | 
            ||
| 373 | }  | 
            ||
| 375 |