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 |
||
| 15 | class SetupTest extends OrmTestCase |
||
| 16 | { |
||
| 17 | private $originalAutoloaderCount; |
||
| 18 | private $originalIncludePath; |
||
| 19 | |||
| 20 | public function setUp() |
||
| 21 | { |
||
| 22 | $this->originalAutoloaderCount = count(spl_autoload_functions()); |
||
| 23 | $this->originalIncludePath = get_include_path(); |
||
| 24 | } |
||
| 25 | |||
| 26 | public function tearDown() |
||
| 27 | { |
||
| 28 | if ( ! $this->originalIncludePath) { |
||
| 29 | return; |
||
| 30 | } |
||
| 31 | |||
| 32 | set_include_path($this->originalIncludePath); |
||
| 33 | |||
| 34 | foreach (spl_autoload_functions() as $i => $loader) { |
||
| 35 | if ($i > $this->originalAutoloaderCount + 1) { |
||
| 36 | spl_autoload_unregister($loader); |
||
| 37 | } |
||
| 38 | } |
||
| 39 | } |
||
| 40 | |||
| 41 | public function testDirectoryAutoload() |
||
| 42 | { |
||
| 43 | Setup::registerAutoloadDirectory(__DIR__ . "/../../../../../vendor/doctrine/common/lib"); |
||
| 44 | |||
| 45 | self::assertEquals($this->originalAutoloaderCount + 2, count(spl_autoload_functions())); |
||
| 46 | } |
||
| 47 | |||
| 48 | public function testAnnotationConfiguration() |
||
| 57 | |||
| 58 | public function testXMLConfiguration() |
||
| 65 | |||
| 66 | /** |
||
| 67 | * @group DDC-1350 |
||
| 68 | */ |
||
| 69 | public function testConfigureProxyDir() |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @group DDC-1350 |
||
| 78 | */ |
||
| 79 | View Code Duplication | public function testConfigureCache() |
|
| 88 | |||
| 89 | /** |
||
| 90 | * @group DDC-3190 |
||
| 91 | */ |
||
| 92 | View Code Duplication | public function testConfigureCacheCustomInstance() |
|
| 101 | |||
| 102 | private function makeTemporaryDirectory() : string |
||
| 111 | } |
||
| 112 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: