1. Go to this page and download the library: Download systemsdk/phpcpd library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
systemsdk / phpcpd example snippets
use Systemsdk\PhpCPD\Attributes\SuppressCpd;
// 1. Suppress an entire class
#[SuppressCpd]
class LegacyDataFixtures
{
// All methods and properties inside this class will be ignored
}
// 2. Suppress a specific method
class ReportGenerator
{
#[SuppressCpd]
public function generateBoilerplate(): void
{
// This specific method will be ignored, but the rest of the class is analyzed
}
}
// 3. Suppress a standalone function
#[SuppressCpd]
function globalHelperFunction() {
// ...
}
// ...
// Exact path segments or file names to exclude from analysis
->exclude([
'vendor', // Excludes any directory exactly named "vendor"
'tests/Fixtures', // Excludes specific nested directories
'src/Legacy/Generated.php' // Excludes a specific file
])
// ...
bash
$ ./vendor/bin/phpcpd --fuzzy --verbose src tests
Copy/Paste Detector 9.2.0
458/458 [==============================>] 100% Loading & Processing
Found 1 code clones with 17 duplicated lines in 1 files:
- /var/www/html/tests/Application/Identity/Transport/Controller/Api/V1/ApiKeyControllerTest.php:138-155 (17 lines) [inconsistent]
/var/www/html/tests/Application/Identity/Transport/Controller/Api/V1/ApiKeyControllerTest.php:163-180
public function testThatFindOneActionForRootUserReturnsSuccessResponse(): void
{
$client = $this->getTestClient('john-root', 'password-root');
$resource = static::getContainer()->get(ApiKeyResource::class);
$apiKeyEntity = $resource->findOneBy([
'description' => 'ApiKey Description: api',
]);
self::assertInstanceOf(ApiKey::class, $apiKeyEntity);
$client->request('GET', static::$baseUrl . '/' . $apiKeyEntity->getId());
$response = $client->getResponse();
$content = $response->getContent();
self::assertNotFalse($content);
self::assertSame(Response::HTTP_OK, $response->getStatusCode(), "Response:\n" . $response);
$responseData = JSON::decode($content, true);
$this->checkBasicFieldsInResponse($responseData);
0.05% duplicated lines out of 32210 total lines of code.
Average code clone size is 17 lines, the largest code clone has 17 lines
ℹ️ Note: 1 clone(s) (38 lines) were suppressed by #[SuppressCpd] attribute(s).
Time: 00:00.373, Memory: 10.00 MB
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.