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 |
||
| 9 | class SiteAccessVoterTest extends TestCase |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * @var \Netgen\Bundle\SiteAccessRoutesBundle\Matcher\Voter\SiteAccessVoter |
||
| 13 | */ |
||
| 14 | protected $voter; |
||
| 15 | |||
| 16 | public function setUp() |
||
| 17 | { |
||
| 18 | $this->voter = new SiteAccessVoter(); |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @param string $siteAccess |
||
| 23 | * @param array $groupConfig |
||
| 24 | * @param bool $vote |
||
| 25 | * |
||
| 26 | * @covers \Netgen\Bundle\SiteAccessRoutesBundle\Matcher\Voter\SiteAccessVoter::vote |
||
| 27 | * |
||
| 28 | * @dataProvider voteProvider |
||
| 29 | */ |
||
| 30 | public function testVote($siteAccess, array $groupConfig, $vote) |
||
| 31 | { |
||
| 32 | $this->assertEquals($vote, $this->voter->vote($siteAccess, $groupConfig)); |
||
| 33 | } |
||
| 34 | |||
| 35 | public function voteProvider() |
||
| 36 | { |
||
| 37 | return array( |
||
| 38 | array('cro', array('cro', 'eng'), true), |
||
| 39 | array('eng', array('cro', 'eng'), true), |
||
| 40 | array('admin', array('cro', 'eng'), VoterInterface::ABSTAIN), |
||
| 41 | array('extra', array('cro', 'eng'), VoterInterface::ABSTAIN), |
||
| 42 | ); |
||
| 43 | } |
||
| 44 | } |
||
| 45 |