Magento2 – How to Check Code Duplication in Magento 2 Extension

magento2marketplace

I have created a module in Magento 2 and now I am trying to submit it on Magento Marketplace.
My extension has passed from business review and Technical review but I am facing issues with QA review.

I recieved a mail from Magento marketplace stating that I had code duplication in my extension.
Below is the sample of the mail.

Code quality issues: CPD: This extension contains duplicated code.

When I went to my product on Marketplace account, and checked the technical report, I found below.

Code Duplicates Detected

This extension contains code that is directly copied from the Magento codebase. This is in direct violation of Sections 3.1 and 9.1b of the Magento Developer Agreement.

File: vendor/module/vendor-module-1.0.0.0/Block/Adminhtml/Module/Edit/Tab/Stores.php
Line: 58
File: magento/module-checkout-agreements/magento-module-checkout-agreements-100.0.6.0/Block/Adminhtml/Agreement/Edit/Form.php
Line: 122

File: magento/module-cms/magento-module-cms-100.0.7.0/Block/Adminhtml/Block/Edit/Form.php
Line: 100
File: vendor/module/vendor-module-1.0.0.0/Block/Adminhtml/Module/Renderer/Files.php
Line: 49

File: magento/framework/magento-framework-100.0.16.0/Data/Form/Element/Image.php
Line: 86
File: vendor/module/vendor-module-1.0.0.0/Model/ResourceModel/AbstractCollection.php
Line: 2
File: magento/module-cms/magento-module-cms-100.0.7.0/Model/ResourceModel/AbstractCollection.php
Line: 6

Is there any way I can check for code duplication on my setup to avoid this issue for my other extensions?

Best Answer

Magento 2 Setup folder

Step-1 for check with code extension

/dev/tests/static/testsuite/Magento/Test/Php/_files/phpcpd/blacklist
rename common.txt--

Step-2 run below command

php bin/magento dev:tests:run static

Step -3 see duplication code

dev/tests/static/report
phpcpd_report.xml

Now check phpcpd_report.xml

Related Topic