Conditions | 1 |
Paths | 1 |
Total Lines | 132 |
Code Lines | 82 |
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 |
||
35 | public function testUpdateStatic() |
||
36 | { |
||
37 | // Test base state |
||
38 | $this->assertEquals( |
||
39 | ['test_1'], |
||
40 | Config::inst()->get(ConfigTest\First::class, 'first') |
||
41 | ); |
||
42 | $this->assertEquals( |
||
43 | [ |
||
44 | 'test_1', |
||
45 | 'test_2' |
||
46 | ], |
||
47 | Config::inst()->get(ConfigTest\Second::class, 'first') |
||
48 | ); |
||
49 | $this->assertEquals( |
||
50 | [ 'test_2' ], |
||
51 | Config::inst()->get(ConfigTest\Second::class, 'first', Config::UNINHERITED) |
||
52 | ); |
||
53 | $this->assertEquals( |
||
54 | [ |
||
55 | 'test_1', |
||
56 | 'test_2', |
||
57 | 'test_3' |
||
58 | ], |
||
59 | Config::inst()->get(ConfigTest\Third::class, 'first') |
||
60 | ); |
||
61 | $this->assertEquals( |
||
62 | [ 'test_3' ], |
||
63 | Config::inst()->get(ConfigTest\Third::class, 'first', true) |
||
64 | ); |
||
65 | |||
66 | // Modify first param |
||
67 | Config::modify()->merge(ConfigTest\First::class, 'first', array('test_1_2')); |
||
68 | Config::modify()->merge(ConfigTest\Third::class, 'first', array('test_3_2')); |
||
69 | Config::modify()->merge(ConfigTest\Fourth::class, 'first', array('test_4')); |
||
70 | |||
71 | // Check base class |
||
72 | $this->assertEquals( |
||
73 | ['test_1', 'test_1_2'], |
||
74 | Config::inst()->get(ConfigTest\First::class, 'first') |
||
75 | ); |
||
76 | $this->assertEquals( |
||
77 | ['test_1', 'test_1_2'], |
||
78 | Config::inst()->get(ConfigTest\First::class, 'first', Config::UNINHERITED) |
||
79 | ); |
||
80 | $this->assertEquals( |
||
81 | ['test_1'], |
||
82 | Config::inst()->get(ConfigTest\First::class, 'first', Config::NO_DELTAS) |
||
83 | ); |
||
84 | $this->assertEquals( |
||
85 | ['test_1'], |
||
86 | Config::inst()->get(ConfigTest\First::class, 'first', Config::NO_DELTAS | Config::UNINHERITED) |
||
87 | ); |
||
88 | |||
89 | // Modify second param |
||
90 | Config::modify()->merge(ConfigTest\Fourth::class, 'second', array('test_4')); |
||
91 | Config::modify()->merge(ConfigTest\Third::class, 'second', array('test_3_2')); |
||
92 | |||
93 | // Check fourth class |
||
94 | $this->assertEquals( |
||
95 | ['test_1', 'test_3', 'test_3_2', 'test_4'], |
||
96 | Config::inst()->get(ConfigTest\Fourth::class, 'second') |
||
97 | ); |
||
98 | $this->assertEquals( |
||
99 | ['test_4'], |
||
100 | Config::inst()->get(ConfigTest\Fourth::class, 'second', Config::UNINHERITED) |
||
101 | ); |
||
102 | $this->assertEquals( |
||
103 | ['test_1', 'test_3'], |
||
104 | Config::inst()->get(ConfigTest\Fourth::class, 'second', Config::NO_DELTAS) |
||
105 | ); |
||
106 | $this->assertEquals( |
||
107 | null, |
||
108 | Config::inst()->get(ConfigTest\Fourth::class, 'second', Config::NO_DELTAS | Config::UNINHERITED) |
||
109 | ); |
||
110 | |||
111 | // Check third class |
||
112 | $this->assertEquals( |
||
113 | ['test_1', 'test_3', 'test_3_2'], |
||
114 | Config::inst()->get(ConfigTest\Third::class, 'second') |
||
115 | ); |
||
116 | $this->assertEquals( |
||
117 | ['test_3', 'test_3_2'], |
||
118 | Config::inst()->get(ConfigTest\Third::class, 'second', Config::UNINHERITED) |
||
119 | ); |
||
120 | $this->assertEquals( |
||
121 | ['test_1', 'test_3'], |
||
122 | Config::inst()->get(ConfigTest\Third::class, 'second', Config::NO_DELTAS) |
||
123 | ); |
||
124 | $this->assertEquals( |
||
125 | ['test_3'], |
||
126 | Config::inst()->get(ConfigTest\Third::class, 'second', Config::NO_DELTAS | Config::UNINHERITED) |
||
127 | ); |
||
128 | |||
129 | // Test remove() |
||
130 | Config::modify()->remove(ConfigTest\Third::class, 'second'); |
||
131 | |||
132 | // Check third class ->get() |
||
133 | $this->assertEquals( |
||
134 | null, |
||
135 | Config::inst()->get(ConfigTest\Third::class, 'second') |
||
136 | ); |
||
137 | $this->assertEquals( |
||
138 | ['test_1', 'test_3'], |
||
139 | Config::inst()->get(ConfigTest\Third::class, 'second', Config::NO_DELTAS) |
||
140 | ); |
||
141 | $this->assertEquals( |
||
142 | null, |
||
143 | Config::inst()->get(ConfigTest\Third::class, 'second', Config::UNINHERITED) |
||
144 | ); |
||
145 | |||
146 | // Check ->exists() |
||
147 | $this->assertFalse( |
||
148 | Config::inst()->exists(ConfigTest\Third::class, 'second') |
||
149 | ); |
||
150 | $this->assertFalse( |
||
151 | Config::inst()->exists(ConfigTest\Third::class, 'second', Config::UNINHERITED) |
||
152 | ); |
||
153 | $this->assertTrue( |
||
154 | Config::inst()->exists(ConfigTest\Third::class, 'second', Config::NO_DELTAS) |
||
155 | ); |
||
156 | |||
157 | // Test merge() |
||
158 | Config::modify()->merge(ConfigTest\Third::class, 'second', ['test_3_2']); |
||
159 | $this->assertEquals( |
||
160 | ['test_3_2'], |
||
161 | Config::inst()->get(ConfigTest\Third::class, 'second') |
||
162 | ); |
||
163 | // No-deltas omits both above ->remove() as well as ->merge() |
||
164 | $this->assertEquals( |
||
165 | ['test_1', 'test_3'], |
||
166 | Config::inst()->get(ConfigTest\Third::class, 'second', Config::NO_DELTAS) |
||
167 | ); |
||
367 |