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 |
||
| 26 | class SecurityConfigTest extends TestCase {
|
||
| 27 | /** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */ |
||
| 28 | private $config; |
||
| 29 | /** @var SecurityConfig */ |
||
| 30 | private $securityConfig; |
||
| 31 | public function setUp() {
|
||
| 36 | |||
| 37 | /** |
||
| 38 | * @param array $mockedMethods |
||
| 39 | * @return SecurityConfig | \PHPUnit_Framework_MockObject_MockObject |
||
| 40 | */ |
||
| 41 | private function getMockInstance($mockedMethods = []) {
|
||
| 47 | |||
| 48 | public function testGetAllSecurityConfigs() {
|
||
| 69 | /** |
||
| 70 | * @dataProvider numericConfTestData |
||
| 71 | * @param string $appConfigValue |
||
| 72 | * @param int $expected |
||
| 73 | */ |
||
| 74 | View Code Duplication | public function testGetBruteForceProtectionFailTolerance($appConfigValue, $expected) {
|
|
| 82 | /** |
||
| 83 | * @dataProvider numericConfTestData |
||
| 84 | * @param string $appConfigValue |
||
| 85 | * @param int $expected |
||
| 86 | */ |
||
| 87 | View Code Duplication | public function testGetBruteForceProtectionTimeThreshold($appConfigValue, $expected) {
|
|
| 95 | /** |
||
| 96 | * @dataProvider numericConfTestData |
||
| 97 | * @param string $appConfigValue |
||
| 98 | * @param int $expected |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function testGetBruteForceProtectionBanPeriod($appConfigValue, $expected) {
|
|
| 108 | /** |
||
| 109 | * @dataProvider minPassTestData |
||
| 110 | * @param string $appConfigValue |
||
| 111 | * @param int $expected |
||
| 112 | */ |
||
| 113 | View Code Duplication | public function testGetMinPasswordLength($appConfigValue, $expected) {
|
|
| 121 | /** |
||
| 122 | * @dataProvider configTestData |
||
| 123 | * @param string $appConfigValue |
||
| 124 | * @param bool $expected |
||
| 125 | */ |
||
| 126 | View Code Duplication | public function testGetIsUpperLowerCaseEnforced($appConfigValue, $expected) {
|
|
| 134 | /** |
||
| 135 | * @dataProvider configTestData |
||
| 136 | * @param string $appConfigValue |
||
| 137 | * @param bool $expected |
||
| 138 | */ |
||
| 139 | View Code Duplication | public function testGetIsNumericCharactersEnforced($appConfigValue, $expected) {
|
|
| 147 | /** |
||
| 148 | * @dataProvider configTestData |
||
| 149 | * @param string $appConfigValue |
||
| 150 | * @param bool $expected |
||
| 151 | */ |
||
| 152 | View Code Duplication | public function testGetIsSpecialCharactersEnforced($appConfigValue, $expected) {
|
|
| 160 | /** |
||
| 161 | * @dataProvider numericConfTestData |
||
| 162 | * @param string $expected |
||
| 163 | * @param int $setValue |
||
| 164 | */ |
||
| 165 | public function testSetBruteForceProtectionFailTolerance($expected, $setValue) {
|
||
| 170 | /** |
||
| 171 | * @dataProvider numericConfTestData |
||
| 172 | * @param string $expected |
||
| 173 | * @param int $setValue |
||
| 174 | */ |
||
| 175 | public function testSetBruteForceProtectionTimeThreshold($expected, $setValue) {
|
||
| 180 | /** |
||
| 181 | * @dataProvider numericConfTestData |
||
| 182 | * @param string $expected |
||
| 183 | * @param int $setValue |
||
| 184 | */ |
||
| 185 | public function testSetBruteForceProtectionBanPeriod($expected, $setValue) {
|
||
| 190 | /** |
||
| 191 | * @dataProvider minPassTestData |
||
| 192 | * @param string $expected |
||
| 193 | * @param int $setValue |
||
| 194 | */ |
||
| 195 | public function testSetMinPasswordLength($expected, $setValue) {
|
||
| 200 | /** |
||
| 201 | * @dataProvider configTestData |
||
| 202 | * @param string $expected |
||
| 203 | * @param bool $setValue |
||
| 204 | */ |
||
| 205 | public function testSetIsUpperLowerCaseEnforced($expected, $setValue) {
|
||
| 210 | /** |
||
| 211 | * @dataProvider configTestData |
||
| 212 | * @param string $expected |
||
| 213 | * @param bool $setValue |
||
| 214 | */ |
||
| 215 | public function testSetIsNumericCharactersEnforced($expected, $setValue) {
|
||
| 220 | /** |
||
| 221 | * @dataProvider configTestData |
||
| 222 | * @param string $expected |
||
| 223 | * @param bool $setValue |
||
| 224 | */ |
||
| 225 | public function testSetIsSpecialCharactersEnforced($expected, $setValue) {
|
||
| 250 | |||
| 251 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.