コードの重複をチェックするために使用されるMagento 2コマンドの説明を次に示します。
コードの複製/コピーペーストを確認するコマンドは以下のとおりです。
php bin/magento dev:tests:run static
このコマンドは最初にdev/tests/staticフォルダーに移動します。ここでは、このテストスイートの宣言ファイルphpunit.xml.distを確認できます。
<testsuites>
    <testsuite name="Less Static Code Analysis">
        <file>testsuite/Magento/Test/Less/LiveCodeTest.php</file>
    </testsuite>
    <testsuite name="Javascript Static Code Analysis">
        <file>testsuite/Magento/Test/Js/LiveCodeTest.php</file>
    </testsuite>
    <testsuite name="PHP Coding Standard Verification">
        <file>testsuite/Magento/Test/Php/LiveCodeTest.php</file>
    </testsuite>
    <testsuite name="Code Integrity Tests">
        <directory>testsuite/Magento/Test/Integrity</directory>
    </testsuite>
    <testsuite name="Xss Unsafe Output Test">
        <file>testsuite/Magento/Test/Php/XssPhtmlTemplateTest.php</file>
    </testsuite>
</testsuites>
このファイルには、さまざまなコードテストで実行するファイルを定義する上記のコードがあります。 
絞り込むにPHP Coding Standard Verification testsuiteは、ファイルtestsuite / Magento / Test / Php / LiveCodeTest.phpが実行されます
このファイルを開くと、さまざまな種類のコードの問題を確認するためのさまざまな関数が見つかります。実行される関数はtestCopyPaste
public function testCopyPaste()
{
    $reportFile = self::$reportDir . '/phpcpd_report.xml';
    $copyPasteDetector = new CopyPasteDetector($reportFile);
    if (!$copyPasteDetector->canRun()) {
        $this->markTestSkipped('PHP Copy/Paste Detector is not available.');
    }
    $blackList = [];
    foreach (glob(__DIR__ . '/_files/phpcpd/blacklist/*.txt') as $list) {
        $blackList = array_merge($blackList, file($list, FILE_IGNORE_NEW_LINES));
    }
    $copyPasteDetector->setBlackList($blackList);
    $result = $copyPasteDetector->run([BP]);
    $output = "";
    if (file_exists($reportFile)) {
        $output = file_get_contents($reportFile);
    }
    $this->assertTrue(
        $result,
        "PHP Copy/Paste Detector has found error(s):" . PHP_EOL . $output
    );
}
ここでは、このコードチェックのファイル/フォルダーをブラックリストに登録するためのコードがあります。
foreach (glob(__DIR__ . '/_files/phpcpd/blacklist/*.txt') as $list) {
    $blackList = array_merge($blackList, file($list, FILE_IGNORE_NEW_LINES));
}
このforeach関数は.txt、dev / tests / static / testsuite / Magento / Test / Php / _files / phpcpd / blacklistの場所に追加されたファイルをチェックします。ファイルを読み取り、コピーペーストコード検出プロセスから除外するすべてのフォルダーを無視します。
すべてのブラックリストファイル/フォルダーをコードに追加すると、コードの下で実行されます。
$result = $copyPasteDetector->run([BP]);
このコードはrun、dev / tests / static / framework / Magento / TestFramework / CodingStandard / Tool / CopyPasteDetector.phpファイルの機能を実行します。
public function run(array $whiteList)
{
    $blackListStr = ' ';
    foreach ($this->blacklist as $file) {
        $file = escapeshellarg(trim($file));
        if (!$file) {
            continue;
        }
        $blackListStr .= '--exclude ' . $file . ' ';
    }
    $vendorDir = require BP . '/app/etc/vendor_path.php';
    $command = 'php ' . BP . '/' . $vendorDir . '/bin/phpcpd' . ' --log-pmd ' . escapeshellarg(
            $this->reportFile
        ) . ' --names-exclude "*Test.php" --min-lines 13' . $blackListStr . ' ' . implode(' ', $whiteList);
    exec($command, $output, $exitCode);
    return !(bool)$exitCode;
}
ここで、コードはリストblacklisted内のすべてのフォルダー/ファイルを追加します--exclude。
その後、vendor/bin/phpcpdコマンドを実行します。
ここではコマンド自体にMagentoが持っています 
Testコードによってすべてのファイルを除外しました 
--names-exclude "*Test.php" 
また、コードごとに13行未満であるすべてのコードの重複をスキップしました
--min-lines 13
このコマンド実行の出力は、testCopyPastefunctionで定義されたファイルに追加されます。コピー/ペースト検出のファイル名は、dev / tests / static / reportにあるphpcpd_report.xmlです。
コマンドが正常に実行されると、レポートファイルに出力が追加されます。