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 |
||
25 | class SchemaService |
||
26 | { |
||
27 | /** |
||
28 | * @var EntityManagerInterface |
||
29 | */ |
||
30 | protected $entityManager; |
||
31 | /** |
||
32 | * @var PluginContext |
||
33 | */ |
||
34 | 1 | private $pluginContext; |
|
35 | |||
36 | 1 | /** |
|
37 | * SchemaService constructor. |
||
38 | * |
||
39 | * @param EntityManagerInterface $entityManager |
||
40 | * @param PluginContext $pluginContext |
||
41 | */ |
||
42 | public function __construct(EntityManagerInterface $entityManager, PluginContext $pluginContext) |
||
47 | |||
48 | /** |
||
49 | * Doctrine Metadata を生成してコールバック関数を実行する. |
||
50 | * |
||
51 | * コールバック関数は主に SchemaTool が利用されます. |
||
52 | * Metadata を出力する一時ディレクトリを指定しない場合は内部で生成し, コールバック関数実行後に削除されます. |
||
53 | * |
||
54 | * @param callable $callback Metadata を生成した後に実行されるコールバック関数 |
||
55 | * @param array $generatedFiles Proxy ファイルパスの配列 |
||
56 | * @param string $proxiesDirectory Proxy ファイルを格納したディレクトリ |
||
57 | * @param bool $saveMode UpdateSchema を即時実行する場合 true |
||
|
|||
58 | * @param string $outputDir Metadata の出力先ディレクトリ |
||
59 | */ |
||
60 | public function executeCallback(callable $callback, $generatedFiles, $proxiesDirectory, $outputDir = null) |
||
110 | |||
111 | /** |
||
112 | * Doctrine Metadata を生成して UpdateSchema を実行する. |
||
113 | * |
||
114 | * @param array $generatedFiles Proxy ファイルパスの配列 |
||
115 | * @param string $proxiesDirectory Proxy ファイルを格納したディレクトリ |
||
116 | * @param bool $saveMode UpdateSchema を即時実行する場合 true |
||
117 | */ |
||
118 | public function updateSchema($generatedFiles, $proxiesDirectory, $saveMode = false) |
||
124 | |||
125 | /** |
||
126 | * ネームスペースに含まれるEntityのテーブルを削除する |
||
127 | * |
||
128 | * @param $targetNamespace string 削除対象のネームスペース |
||
129 | */ |
||
130 | public function dropTable($targetNamespace) |
||
148 | } |
||
149 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.