Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit e22d0e5

Browse files
author
DKravtsov
committedApr 30, 2025·
phpcpd 8.2.0 release. Added possibility to generate html report, extended report xml file, fixed some bugs, updated documentation.
1 parent a5e220a commit e22d0e5

31 files changed

+620
-131
lines changed
 

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
reports/*
22
!reports/.gitkeep
3+
!reports/phpcpd/.gitkeep
34

45
/.env.local
56
/build/phar

‎.idea/htdocs.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎ChangeLog.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22

33
All notable changes in PHPCPD are documented in this file using the [Keep a CHANGELOG](http://keepachangelog.com/) principles.
44

5+
## [8.2.0] - 2025-05-01
6+
7+
### Added
8+
9+
* Added possibility to use [xalan](https://xalan.apache.org) cli tool for generating html report with datatable and possibility to export into csv, excel, pdf formats or print it.
10+
11+
### Updated
12+
13+
* Changed and extended xml report format.
14+
515
## [8.1.1] - 2025-04-13
616

717
### Added

‎Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ RUN apt-get update && apt-get upgrade -y && apt-get install -y \
3939
wget \
4040
gpg \
4141
debsecan \
42+
xalan \
4243
&& docker-php-ext-configure intl \
4344
&& docker-php-ext-install \
4445
sockets \

‎Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ info: ## Shows php, composer, phing, phive versions
9393
@make exec cmd="composer --version"
9494
@make exec cmd="php phing.phar -v"
9595
@make exec cmd="phive --version"
96+
@make exec cmd="xalan -v"
9697

9798
logs: ## Shows logs from the php container. Use ctrl+c in order to exit
9899
ifeq ($(INSIDE_DOCKER_CONTAINER), 0)
@@ -120,6 +121,12 @@ signed-phar: ## Create signed PHAR archive of PHPCPD and all its dependencies (r
120121
phpunit: ## Runs PhpUnit tests and create coverage report inside reports/coverage folder
121122
@make exec-bash cmd="./vendor/bin/phpunit -c phpunit.xml.dist --coverage-html reports/coverage --coverage-clover reports/clover.xml --log-junit reports/junit.xml"
122123

124+
phpcpd-run: ## Runs phpcpd
125+
@make exec-bash cmd="php phpcpd --fuzzy --log-pmd=reports/phpcpd/phpcpd-report-v1.xml tests/Fixture"
126+
127+
phpcpd-html-report: ## Generate html report (should be run after phpcpd-run)
128+
@make exec-bash cmd="xalan -in reports/phpcpd/phpcpd-report-v1.xml -xsl https://systemsdk.github.io/phpcpd/report/phpcpd-html-v1_0_0.xslt -out reports/phpcpd/phpcpd-report-v1.html"
129+
123130
report-code-coverage: ## Updates code coverage on coveralls.io. Note: COVERALLS_REPO_TOKEN should be set on CI side.
124131
@make exec-bash cmd="export COVERALLS_REPO_TOKEN=${COVERALLS_REPO_TOKEN} && php ./vendor/bin/php-coveralls -v --coverage_clover reports/clover.xml --json_path reports/coverals.json"
125132

‎build.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project name="phpcpd" default="setup">
33
<property name="basedir" value="." override="false"/>
4-
<property name="version" value="8.1.1" override="false"/>
4+
<property name="version" value="8.2.0" override="false"/>
55
<target name="setup" depends="clean,install-dependencies"/>
66

77
<target name="clean" description="Cleanup build artifacts">

‎composer.lock

Lines changed: 20 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎docs/images/report_example_01.png

261 KB
Loading

‎docs/report.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# PHP Copy/Paste Detector report
2+
This document describing how you can generate report.
3+
4+
## Requirements for html report generation
5+
* [Xalan](https://xalan.apache.org) tool
6+
* created folder (f.e. `reports/phpcpd`) with write access where you want to save your report
7+
8+
Note: You can find some already-made examples inside our solutions on our [GitHub page](https://github.com/systemsdk)
9+
10+
## Steps for html report generation
11+
You need to run the next commands for html report generation:
12+
13+
1. Run PHP Copy/Paste Detector
14+
```bash
15+
php ./vendor/bin/phpcpd --fuzzy --verbose --log-pmd=reports/phpcpd/phpcpd-report-v1.xml src
16+
```
17+
18+
Note: `src` is a folder where your php source code for analyzing
19+
20+
2. Run xalan tool for report generation
21+
```bash
22+
xalan -in reports/phpcpd/phpcpd-report-v1.xml -xsl https://systemsdk.github.io/phpcpd/report/phpcpd-html-v1_0_0.xslt -out reports/phpcpd/phpcpd-report-v1.html
23+
```
24+
25+
3. Now you can open the report using your web-browser
26+
27+
![Path mappings](images/report_example_01.png)
28+
29+
[Example](https://systemsdk.github.io/phpcpd/report/report-example.html)
30+
31+
Note: Please use menu items `Enable datatable`, `Disable datatabl` for enable/disable [DataTables](https://datatables.net/).
32+
33+
## Xml report format
34+
This format uses `xml` to output the duplications in a more structured format. The `xml` format can then further be processed using `xslt` transformations. See section xslt below for examples.
35+
36+
Report file example:
37+
```
38+
<?xml version="1.0" encoding="UTF-8"?>
39+
<pmd-cpd xmlns="https://systemsdk.github.io/phpcpd/report" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" phpcpdVersion="8.2.0" timestamp="2025-04-29T17:39:52+00:00" version="1.0.0" xsi:schemaLocation="https://systemsdk.github.io/phpcpd/report https://systemsdk.github.io/phpcpd/report/phpcpd-report-v1_0_0.xsd">
40+
<duplication lines="59" tokens="136">
41+
<file line="116" endline="175" path="/var/www/html/tests/Fixture/Math.php"/>
42+
<file line="217" endline="276" path="/var/www/html/tests/Fixture/Math.php"/>
43+
<codefragment><![CDATA[ public function div($v1, $v2)
44+
{
45+
$v3 = $v1 / ($v2 + $v1);
46+
if ($v3 &gt; 14)
47+
{
48+
$v4 = 0;
49+
for ($i = 0; $i &lt; $v3; $i++)
50+
{
51+
$v4 += ($v2 * $i);
52+
}
53+
}
54+
$v5 = ($v4 &lt; $v3 ? ($v3 - $v4) : ($v4 - $v3));
55+
56+
$v6 = ($v1 * $v2 * $v3 * $v4 * $v5);
57+
58+
$d = array($v1, $v2, $v3, $v4, $v5, $v6);
59+
60+
$v7 = 1;
61+
for ($i = 0; $i &lt; $v6; $i++)
62+
{
63+
shuffle( $d );
64+
$v7 = $v7 + $i * end($d);
65+
}
66+
67+
$v8 = $v7;
68+
foreach ( $d as $x )
69+
{
70+
$v8 *= $x;
71+
}
72+
73+
$v3 = $v1 / ($v2 + $v1);
74+
if ($v3 &gt; 14)
75+
{
76+
$v4 = 0;
77+
for ($i = 0; $i &lt; $v3; $i++)
78+
{
79+
$v4 += ($v2 * $i);
80+
}
81+
}
82+
$v5 = ($v4 &lt; $v3 ? ($v3 - $v4) : ($v4 - $v3));
83+
84+
$v6 = ($v1 * $v2 * $v3 * $v4 * $v5);
85+
86+
$d = array($v1, $v2, $v3, $v4, $v5, $v6);
87+
88+
$v7 = 1;
89+
for ($i = 0; $i &lt; $v6; $i++)
90+
{
91+
shuffle( $d );
92+
$v7 = $v7 + $i * end($d);
93+
}
94+
95+
$v8 = $v7;
96+
foreach ( $d as $x )
97+
{
98+
$v8 *= $x;
99+
}
100+
101+
return $v8;
102+
]]></codefragment>
103+
</duplication>
104+
</pmd-cpd>
105+
```
106+
107+
## Xslt
108+
This is not a direct report format. But you can use one of the following `xslt` stylesheets to convert the report into `html`. Or you can write your own stylesheet.
109+
110+
`https://systemsdk.github.io/phpcpd/report/phpcpd-html-v1_0_0.xslt`
111+
112+
This stylesheet is available and using for html report generation mentioned above.
113+
114+
It requires javascript enabled and uses [Bootstrap](https://getbootstrap.com/), [jQuery](https://jquery.com/), and [DataTables](https://datatables.net/).
115+
116+
## Schema versions
117+
PHP Copy/Past detector tool is building xml report that has schema `https://systemsdk.github.io/phpcpd/report/phpcpd-report-v1_0_0.xsd`.
118+
119+
You can find xsd versions history [here](schema.md).

‎docs/schema.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PHPCPD Report Schema
2+
This document describing PHPCPD report schema.
3+
4+
## PHPCPD Report Schema 1.0.0
5+
Namespace: `https://systemsdk.github.io/phpcpd/report`
6+
7+
Schema Location: `https://systemsdk.github.io/phpcpd/report/phpcpd-report-v1_0_0.xsd`
8+
9+
Current Version: 1.0.0 (since phpcpd 8.2.0)
10+
11+
Last Change: 2025-05-01

0 commit comments

Comments
 (0)
Please sign in to comment.