PHPackages                             shipmonk/copy-paste-detector - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. shipmonk/copy-paste-detector

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

shipmonk/copy-paste-detector
============================

Finds duplicated PHP code structures using AST-based analysis, inspired by CloneDR to detect Type-2 (parameterized) code clones.

51.1k↑118.8%[1 PRs](https://github.com/shipmonk-rnd/copy-paste-detector/pulls)PHPCI passing

Since May 12Pushed 1mo agoCompare

[ Source](https://github.com/shipmonk-rnd/copy-paste-detector)[ Packagist](https://packagist.org/packages/shipmonk/copy-paste-detector)[ RSS](/packages/shipmonk-copy-paste-detector/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependenciesVersions (9)Used By (0)

PHP Copy-Paste Detector
=======================

[](#php-copy-paste-detector)

An AST-based structural code clone detector for PHP, inspired by the CloneDR methodology. This tool efficiently detects Type-2 (parameterized) code clones using AST analysis and hash-based exact matching.

Installation
------------

[](#installation)

```
composer require --dev shipmonk/copy-paste-detector
```

Basic Usage
-----------

[](#basic-usage)

```
vendor/bin/copy-paste-detector src/
```

CLI Options
-----------

[](#cli-options)

- `--config=config.php` or `-c config.php`

    - Path to configuration file
    - Defaults to `copy-paste-detector.php` in current directory
    - Configuration file must return a `CopyPasteDetector\Config\Config` instance
- `--min-node-count=100` or `-m 100`

    - Minimum number of AST nodes for a subtree to be considered
    - Defaults to 50
- `--cache-dir=cache/`

    - Directory for caching parsed structures
    - Defaults to system temp directory
- `--patch=changes.patch`

    - Path to a git diff/patch file (extension must be `.patch` or `.diff`)
    - Only reports clone groups with at least one instance fully inside the patch's added lines.
    - Requires `sebastian/diff` to be installed.
- `--ansi` / `--no-ansi`

    - Force enable or disable ANSI color output
    - By default, colors are auto-detected based on the terminal

Check if MR copied code from elsewhere
--------------------------------------

[](#check-if-mr-copied-code-from-elsewhere)

```
git diff master...HEAD > changes.patch
vendor/bin/copy-paste-detector --patch=changes.patch src/ tests/
```

- A clone group is reported if at least one instance lies fully inside the patch's added lines. The other instances may be either elsewhere in the codebase or also inside the patch.

Configuration File
------------------

[](#configuration-file)

Create a `copy-paste-detector.php` file in your project root to configure detection settings:

```
