Skip to content

Add duplicated-code command for token-based copy-paste detection - #137

Merged
TomasVotruba merged 2 commits into
mainfrom
tv-copy-paste-command
Sep 17, 2026
Merged

TomasVotruba merged 2 commits into
mainfrom
tv-copy-paste-command

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Adds a duplicated-code command - a small token-based copy-paste detector, a clone of phpcpd.

It tokenizes PHP with token_get_all(), strips whitespace and comments, then finds exact duplicate token spans with a Rabin-Karp rolling hash.

Extracted from the utils/duplicates script in rector-src so it can be reused across the rector packages CI.

vendor/bin/swiss-knife duplicated-code src rules --min-tokens 150 --min-lines 5

Options:

  • --min-lines minimum lines of a reported clone (default 5)
  • --min-tokens minimum tokens of a reported clone (default 70)
  • --fuzzy ignore variable names when matching
  • --skip-file file paths or masks to skip

Exit code is 1 when clones are found, 0 otherwise.

@TomasVotruba
TomasVotruba merged commit 423d94c into main Sep 17, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the tv-copy-paste-command branch September 17, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant