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 |
||
6 | class NoneTest extends \PHPUnit_Framework_TestCase |
||
7 | { |
||
8 | /** |
||
9 | * none test |
||
10 | * |
||
11 | * @dataProvider generateDataForTest |
||
12 | * @param string $url |
||
13 | * @param string $bot |
||
14 | * @param array $options |
||
15 | */ |
||
16 | public function testNone($url, $bot, $options) |
||
17 | { |
||
18 | $parser = new XRobotsTagParser($url, $bot, $options); |
||
19 | $this->assertInstanceOf('vipnytt\XRobotsTagParser', $parser); |
||
20 | |||
21 | $this->assertTrue($parser->getRules(true)['none']); |
||
22 | $this->assertTrue($parser->getRules(false)['noindex']); |
||
23 | $this->assertTrue($parser->getRules(false)['nofollow']); |
||
24 | } |
||
25 | |||
26 | /** |
||
27 | * Generate test data |
||
28 | * @return array |
||
29 | */ |
||
30 | public function generateDataForTest() |
||
31 | { |
||
32 | return [ |
||
33 | [ |
||
34 | 'http://example.com/', |
||
35 | 'googlebot', |
||
36 | ['headers' => |
||
37 | [ |
||
38 | 'X-Robots-Tag: none' |
||
39 | ] |
||
40 | ] |
||
41 | ] |
||
42 | ]; |
||
43 | } |
||
44 | } |
||
45 |