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 GetRulesTest extends \PHPUnit_Framework_TestCase  | 
            ||
| 7 | { | 
            ||
| 8 | /**  | 
            ||
| 9 | * Get rules  | 
            ||
| 10 | *  | 
            ||
| 11 | * @dataProvider generateDataForTest  | 
            ||
| 12 | * @param string $url  | 
            ||
| 13 | * @param string $bot  | 
            ||
| 14 | * @param array $options  | 
            ||
| 15 | */  | 
            ||
| 16 | public function testGetRules($url, $bot, $options)  | 
            ||
| 17 |     { | 
            ||
| 18 | $parser = new XRobotsTagParser($url, $bot, $options);  | 
            ||
| 19 |         $this->assertInstanceOf('vipnytt\XRobotsTagParser', $parser); | 
            ||
| 20 | |||
| 21 | $this->assertTrue($parser->getRules(true)['noindex']);  | 
            ||
| 22 | $this->assertTrue($parser->getRules(true)['noarchive']);  | 
            ||
| 23 | $this->assertTrue($parser->getRules(true)['noodp']);  | 
            ||
| 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: googlebot: noindex, noarchive',  | 
            ||
| 39 | 'X-Robots-Tag: bingbot: noindex, noodp',  | 
            ||
| 40 | 'X-Robots-Tag: noindex, noodp'  | 
            ||
| 41 | ]  | 
            ||
| 42 | ]  | 
            ||
| 43 | ]  | 
            ||
| 44 | ];  | 
            ||
| 45 | }  | 
            ||
| 46 | }  | 
            ||
| 47 |