Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 34 |
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 |
||
4 | public function testConfigFile() |
||
5 | { |
||
6 | // Empty config files list at the beginning |
||
7 | $object = new \Suricate\Suricate(); |
||
8 | $reflectionClass = new ReflectionClass($object); |
||
9 | $property = $reflectionClass->getProperty('configFile'); |
||
10 | $property->setAccessible(true); |
||
11 | $configFiles = $property->getValue($object); |
||
12 | |||
13 | $this->assertEquals([], $configFiles); |
||
14 | |||
15 | // single config file |
||
16 | $object = new \Suricate\Suricate( |
||
17 | [], |
||
18 | './tests/stubs/my-single-config.ini' |
||
19 | ); |
||
20 | $reflectionClass = new ReflectionClass($object); |
||
21 | $property = $reflectionClass->getProperty('configFile'); |
||
22 | $property->setAccessible(true); |
||
23 | $configFiles = $property->getValue($object); |
||
24 | |||
25 | $this->assertEquals( |
||
26 | ['./tests/stubs/my-single-config.ini'], |
||
27 | $configFiles |
||
28 | ); |
||
29 | |||
30 | // multiple config file |
||
31 | $object = new \Suricate\Suricate( |
||
32 | [], |
||
33 | [ |
||
34 | './tests/stubs/my-single-config.ini', |
||
35 | './tests/stubs/another-config.ini' |
||
36 | ] |
||
37 | ); |
||
38 | $reflectionClass = new ReflectionClass($object); |
||
39 | $property = $reflectionClass->getProperty('configFile'); |
||
40 | $property->setAccessible(true); |
||
41 | $configFiles = $property->getValue($object); |
||
42 | |||
43 | $this->assertEquals( |
||
44 | [ |
||
45 | './tests/stubs/my-single-config.ini', |
||
46 | './tests/stubs/another-config.ini' |
||
47 | ], |
||
48 | $configFiles |
||
49 | ); |
||
50 | |||
51 | // non existent file |
||
52 | $object = new \Suricate\Suricate( |
||
53 | [], |
||
54 | [ |
||
55 | './tests/stubs/my-single-config-unknown.ini', |
||
56 | './tests/stubs/another-config.ini' |
||
57 | ] |
||
58 | ); |
||
59 | $reflectionClass = new ReflectionClass($object); |
||
60 | $property = $reflectionClass->getProperty('configFile'); |
||
61 | $property->setAccessible(true); |
||
62 | $configFiles = $property->getValue($object); |
||
63 | |||
64 | $this->assertEquals(['./tests/stubs/another-config.ini'], $configFiles); |
||
65 | } |
||
103 |