นี่คือคำอธิบายบางส่วนสำหรับคำสั่ง 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สิ่งนี้จะดำเนินการไฟล์testuite / 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 / ทดสอบ / คงที่ / TestSuite / วีโอไอพี / ทดสอบ / PHP / _FILES / phpcpd / บัญชีดำสถานที่ตั้ง มันจะอ่านไฟล์และจะไม่สนใจโฟลเดอร์ทั้งหมดที่จะแยกออกจากกระบวนการตรวจจับการคัดลอกรหัสวาง
หลังจากเพิ่มไฟล์ / โฟลเดอร์ทั้งหมดในบัญชีดำรหัสมันจะทำงานด้านล่างรหัส
$result = $copyPasteDetector->run([BP]);
รหัสนี้จะดำเนินการrunการทำงานของdev / ทดสอบ / คงที่ / กรอบ / วีโอไอพี / TestFramework / CodingStandard / เครื่องมือ / 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คำสั่ง
ที่นี่ในคำสั่งตัวเองวีโอไอพีมี 
ไม่รวมTestไฟล์ทั้งหมด 
 ด้วยรหัส
--names-exclude "*Test.php" 
มันข้ามรหัสซ้ำทั้งหมดซึ่งน้อยกว่า 13 บรรทัดด้วยรหัส
--min-lines 13
เอาต์พุตสำหรับการดำเนินการคำสั่งนี้จะถูกเพิ่มไปยังไฟล์ที่กำหนดในtestCopyPasteฟังก์ชั่น ชื่อไฟล์สำหรับการตรวจคัดลอกวางเป็นphpcpd_report.xmlตั้งอยู่ที่dev ทดสอบ / คงที่ / รายงาน /สถานที่ตั้ง
หลังจากดำเนินการคำสั่งสำเร็จเอาต์พุตจะถูกเพิ่มในไฟล์รายงาน