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 |
||
21 | class EncryptionResourceWrapperTest extends \PHPUnit_Framework_TestCase |
||
22 | { |
||
23 | /** |
||
24 | * @var EncryptionWrapper |
||
25 | */ |
||
26 | private $wrapper; |
||
27 | |||
28 | /** |
||
29 | * @var \PHPUnit_Framework_MockObject_MockObject |
||
30 | */ |
||
31 | private $encryption; |
||
32 | |||
33 | protected function setUp() |
||
39 | |||
40 | protected function tearDown() |
||
45 | |||
46 | /* =========================================== |
||
47 | * |
||
48 | * EncryptionInterface::EncryptResourceWithKey |
||
49 | * |
||
50 | * =========================================== |
||
51 | */ |
||
52 | |||
53 | /** |
||
54 | * @throws CryptoException |
||
55 | */ |
||
56 | View Code Duplication | public function testEncryptResourceWithKeyEncryptsHandle() |
|
64 | |||
65 | /** |
||
66 | * @throws CryptoException |
||
67 | */ |
||
68 | View Code Duplication | public function testDecryptResourceWithKeyDecryptsEncryptedHandle() |
|
76 | |||
77 | /** |
||
78 | * @expectedException \Mes\Security\CryptoBundle\Exception\CryptoException |
||
79 | */ |
||
80 | View Code Duplication | public function testEncryptResourceWithKeyThrowsException() |
|
93 | |||
94 | /** |
||
95 | * @expectedException \Mes\Security\CryptoBundle\Exception\CryptoException |
||
96 | */ |
||
97 | View Code Duplication | public function testDecryptResourceWithKeyThrowsException() |
|
110 | |||
111 | /* ================================================ |
||
112 | * |
||
113 | * EncryptionInterface::EncryptResourceWithPassword |
||
114 | * |
||
115 | * ================================================ |
||
116 | */ |
||
117 | |||
118 | /** |
||
119 | * @throws CryptoException |
||
120 | */ |
||
121 | View Code Duplication | public function testEncryptResourceWithPasswordEncryptsHandle() |
|
128 | |||
129 | /** |
||
130 | * @throws CryptoException |
||
131 | */ |
||
132 | View Code Duplication | public function testDecryptResourceWithPasswordDecryptsEncryptedHandle() |
|
139 | |||
140 | /** |
||
141 | * @expectedException \Mes\Security\CryptoBundle\Exception\CryptoException |
||
142 | */ |
||
143 | View Code Duplication | public function testEncryptResourceWithPasswordThrowsException() |
|
155 | |||
156 | /** |
||
157 | * @expectedException \Mes\Security\CryptoBundle\Exception\CryptoException |
||
158 | */ |
||
159 | View Code Duplication | public function testDecryptResourceWithPasswordThrowsException() |
|
171 | } |
||
172 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.