Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
15 | class SilverStripeCollectorTest extends SapphireTest |
||
16 | { |
||
17 | /** |
||
18 | * @var DebugBarSilverStripeCollector |
||
19 | */ |
||
20 | protected $collector; |
||
21 | |||
22 | protected $usesDatabase = true; |
||
23 | |||
24 | public function setUp() |
||
30 | |||
31 | public function testCollectorExists() |
||
35 | |||
36 | public function testCollect() |
||
53 | |||
54 | public function testShowRequirements() |
||
62 | |||
63 | public function testShowRequestParameters() |
||
85 | |||
86 | public function testGetSessionData() |
||
92 | |||
93 | public function testGetConfigData() |
||
101 | |||
102 | public function testGetWidgets() |
||
103 | { |
||
104 | $this->collector->collect(); |
||
105 | $result = $this->collector->getWidgets(); |
||
106 | // Stub out the dynamic data |
||
107 | $result['version']['tooltip'] = 'Stub'; |
||
108 | $result['locale']['tooltip'] = 'Stub'; |
||
109 | $result['user']['tooltip'] = 'Current member'; |
||
110 | |||
111 | $expected = array( |
||
112 | 'user' => array( |
||
113 | 'icon' => 'user', |
||
114 | 'tooltip' => 'Current member', |
||
115 | 'default' => '', |
||
116 | ), |
||
117 | 'version' => array( |
||
118 | 'icon' => 'desktop', |
||
119 | 'tooltip' => 'Stub', |
||
120 | 'default' => '', |
||
121 | ), |
||
122 | 'locale' => array( |
||
123 | 'icon' => 'globe', |
||
124 | 'tooltip' => 'Stub', |
||
125 | 'default' => '', |
||
126 | ), |
||
127 | 'session' => array( |
||
128 | 'icon' => 'archive', |
||
129 | 'widget' => 'PhpDebugBar.Widgets.VariableListWidget', |
||
130 | 'map' => 'silverstripe.session', |
||
131 | 'default' => '{}', |
||
132 | ), |
||
133 | 'cookies' => array( |
||
134 | 'icon' => 'asterisk', |
||
135 | 'widget' => 'PhpDebugBar.Widgets.VariableListWidget', |
||
136 | 'map' => 'silverstripe.cookies', |
||
137 | 'default' => '{}', |
||
138 | ), |
||
139 | 'parameters' => array( |
||
140 | 'icon' => 'arrow-right', |
||
141 | 'widget' => 'PhpDebugBar.Widgets.VariableListWidget', |
||
142 | 'map' => 'silverstripe.parameters', |
||
143 | 'default' => '{}', |
||
144 | ), |
||
145 | 'SiteConfig' => array( |
||
146 | 'icon' => 'gear', |
||
147 | 'widget' => 'PhpDebugBar.Widgets.VariableListWidget', |
||
148 | 'map' => 'silverstripe.config', |
||
149 | 'default' => '{}', |
||
150 | ), |
||
151 | 'requirements' => array( |
||
152 | 'icon' => 'file-o ', |
||
153 | 'widget' => 'PhpDebugBar.Widgets.ListWidget', |
||
154 | 'map' => 'silverstripe.requirements', |
||
155 | 'default' => '{}', |
||
156 | ), |
||
157 | 'templates' => array( |
||
158 | 'icon' => 'edit', |
||
159 | 'widget' => 'PhpDebugBar.Widgets.ListWidget', |
||
160 | 'map' => "silverstripe.templates.templates", |
||
161 | 'default' => '{}' |
||
162 | ), |
||
163 | 'templates:badge' => array( |
||
164 | 'map' => 'silverstripe.templates.count', |
||
165 | 'default' => 0 |
||
166 | ), |
||
167 | 'partialCache' => array( |
||
168 | 'icon' => 'asterisk', |
||
169 | 'widget' => 'PhpDebugBar.Widgets.ConfigWidget', |
||
170 | 'map' => "silverstripe.partialCache.calls", |
||
171 | 'default' => '{}' |
||
172 | ), |
||
173 | 'partialCache:badge' => array( |
||
174 | 'map' => 'silverstripe.partialCache.count', |
||
175 | 'default' => 0 |
||
176 | ) |
||
177 | ); |
||
178 | |||
179 | $this->assertSame($expected, $result); |
||
180 | } |
||
181 | |||
182 | View Code Duplication | public function testGetAssets() |
|
192 | } |
||
193 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.