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 |
||
| 22 | class SchemaService |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var EntityManagerInterface |
||
| 26 | */ |
||
| 27 | protected $entityManager; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * SchemaService constructor. |
||
| 31 | * |
||
| 32 | * @param EntityManagerInterface $entityManager |
||
| 33 | */ |
||
| 34 | 1 | public function __construct(EntityManagerInterface $entityManager) |
|
| 38 | |||
| 39 | /** |
||
| 40 | * Doctrine Metadata を生成してコールバック関数を実行する. |
||
| 41 | * |
||
| 42 | * コールバック関数は主に SchemaTool が利用されます. |
||
| 43 | * Metadata を出力する一時ディレクトリを指定しない場合は内部で生成し, コールバック関数実行後に削除されます. |
||
| 44 | * |
||
| 45 | * @param callable $callback Metadata を生成した後に実行されるコールバック関数 |
||
| 46 | * @param array $generatedFiles Proxy ファイルパスの配列 |
||
| 47 | * @param string $proxiesDirectory Proxy ファイルを格納したディレクトリ |
||
| 48 | * @param bool $saveMode UpdateSchema を即時実行する場合 true |
||
|
|
|||
| 49 | * @param string $outputDir Metadata の出力先ディレクトリ |
||
| 50 | */ |
||
| 51 | public function executeCallback(callable $callback, $generatedFiles, $proxiesDirectory, $outputDir = null) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * Doctrine Metadata を生成して UpdateSchema を実行する. |
||
| 95 | * |
||
| 96 | * @param array $generatedFiles Proxy ファイルパスの配列 |
||
| 97 | * @param string $proxiesDirectory Proxy ファイルを格納したディレクトリ |
||
| 98 | * @param bool $saveMode UpdateSchema を即時実行する場合 true |
||
| 99 | */ |
||
| 100 | public function updateSchema($generatedFiles, $proxiesDirectory, $saveMode = false) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * ネームスペースに含まれるEntityのテーブルを削除する |
||
| 109 | * |
||
| 110 | * @param $targetNamespace string 削除対象のネームスペース |
||
| 111 | */ |
||
| 112 | public function dropTable($targetNamespace) |
||
| 130 | } |
||
| 131 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.