Skip to content

Commit 88c52cf

Browse files
author
DKravtsov
committed
phpcpd 8.2.0 release. Added possibility to generate html report, extended report xml file, fixed some bugs, updated documentation.
1 parent a5e220a commit 88c52cf

32 files changed

+789
-131
lines changed

.gitignore

+1
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

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ChangeLog.md

+10
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

+1
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

+7
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

+1-1
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

+20-9
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-example.html

+169
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
<!DOCTYPE HTML SYSTEM "about:legacy-compat">
2+
<html>
3+
<head>
4+
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
5+
<meta charset="utf-8">
6+
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
7+
<script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"></script>
8+
<link href="https://cdn.datatables.net/v/bs5/jszip-2.5.0/dt-1.13.4/b-2.3.6/b-html5-2.3.6/b-print-2.3.6/datatables.min.css" rel="stylesheet">
9+
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"></script><script src="https://cdn.datatables.net/v/bs5/jszip-2.5.0/dt-1.13.4/b-2.3.6/b-html5-2.3.6/b-print-2.3.6/datatables.min.js"></script>
10+
<title>PHPCPD Report</title>
11+
<link rel="icon" href="https://systemsdk.github.io/images/favicon.ico" sizes="32x32">
12+
</head>
13+
<body style="padding-top: 3.5rem;">
14+
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-dark">
15+
<a class="navbar-brand" href="#"></a><button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation"><span class="navbar-toggler-icon"></span></button>
16+
<div class="collapse navbar-collapse" id="navbarNav">
17+
<ul class="navbar-nav">
18+
<li class="nav-item">
19+
<a class="nav-link active" href="#">Report</a>
20+
</li>
21+
<li class="nav-item" id="nav_enable_datatable">
22+
<a class="nav-link" href="?d=">Enable datatable</a>
23+
</li>
24+
<li class="nav-item" id="nav_disable_datatable">
25+
<a class="nav-link" href="?">Disable datatable</a>
26+
</li>
27+
<li class="nav-item">
28+
<a class="nav-link" target="_blank" rel="noopener noreferrer" href="https://packagist.org/packages/systemsdk/phpcpd">Package page</a>
29+
</li>
30+
</ul>
31+
</div>
32+
<img alt="Logo" src="https://systemsdk.github.io/images/logo-white-small.png" style="border-right: 20px solid;"></nav>
33+
<div class="container">
34+
<div class="row">
35+
<div class="col">
36+
<h4>PHPCPD <font color="#0000FF">8.2.0</font> - Summary of duplicated code</h4>
37+
<p>This page summarizes the code fragments that have been found at <font color="#0000FF">2025-04-29T17:39:52+00:00</font> to be replicated in the code.</p>
38+
<table class="table table-light table-bordered table-striped table-hover">
39+
<tr>
40+
<th># Duplications</th><th>Total lines</th><th>Total tokens</th><th>Approximate number of bytes</th>
41+
</tr>
42+
<tr>
43+
<td class="SummaryNumber">1</td><td class="SummaryNumber">59</td><td class="SummaryNumber">136</td><td class="SummaryNumber">544</td>
44+
</tr>
45+
</table>
46+
</div>
47+
</div>
48+
<div class="row">
49+
<div class="col">
50+
<h4>Details of duplicated code</h4>
51+
</div>
52+
<table style="width:100%" id="data_table" class="table table-light table-bordered table-striped table-hover">
53+
<thead>
54+
<tr>
55+
<th>lines</th><th>tokens</th><th>files</th><th>codefragment</th>
56+
</tr>
57+
</thead>
58+
<tbody>
59+
<tr>
60+
<td>59</td><td>136</td><td>
61+
<table class="table table-light table-bordered table-striped table-hover">
62+
<tr>
63+
<th>line</th><th>endline</th><th>path</th>
64+
</tr>
65+
<tr>
66+
<td>116</td><td>175</td><td>/var/www/html/tests/Fixture/Math.php</td>
67+
</tr>
68+
<tr>
69+
<td>217</td><td>276</td><td>/var/www/html/tests/Fixture/Math.php</td>
70+
</tr>
71+
</table>
72+
</td><td>
73+
<pre> public function div($v1, $v2)
74+
{
75+
$v3 = $v1 / ($v2 + $v1);
76+
if ($v3 &amp;gt; 14)
77+
{
78+
$v4 = 0;
79+
for ($i = 0; $i &amp;lt; $v3; $i++)
80+
{
81+
$v4 += ($v2 * $i);
82+
}
83+
}
84+
$v5 = ($v4 &amp;lt; $v3 ? ($v3 - $v4) : ($v4 - $v3));
85+
86+
$v6 = ($v1 * $v2 * $v3 * $v4 * $v5);
87+
88+
$d = array($v1, $v2, $v3, $v4, $v5, $v6);
89+
90+
$v7 = 1;
91+
for ($i = 0; $i &amp;lt; $v6; $i++)
92+
{
93+
shuffle( $d );
94+
$v7 = $v7 + $i * end($d);
95+
}
96+
97+
$v8 = $v7;
98+
foreach ( $d as $x )
99+
{
100+
$v8 *= $x;
101+
}
102+
103+
$v3 = $v1 / ($v2 + $v1);
104+
if ($v3 &amp;gt; 14)
105+
{
106+
$v4 = 0;
107+
for ($i = 0; $i &amp;lt; $v3; $i++)
108+
{
109+
$v4 += ($v2 * $i);
110+
}
111+
}
112+
$v5 = ($v4 &amp;lt; $v3 ? ($v3 - $v4) : ($v4 - $v3));
113+
114+
$v6 = ($v1 * $v2 * $v3 * $v4 * $v5);
115+
116+
$d = array($v1, $v2, $v3, $v4, $v5, $v6);
117+
118+
$v7 = 1;
119+
for ($i = 0; $i &amp;lt; $v6; $i++)
120+
{
121+
shuffle( $d );
122+
$v7 = $v7 + $i * end($d);
123+
}
124+
125+
$v8 = $v7;
126+
foreach ( $d as $x )
127+
{
128+
$v8 *= $x;
129+
}
130+
131+
return $v8;
132+
</pre>
133+
</td>
134+
</tr>
135+
</tbody>
136+
</table>
137+
</div>
138+
</div>
139+
<script>
140+
let params = (new URL(document.location)).searchParams;
141+
let showDatatable = false;
142+
143+
//------------ can be called with this parameter d
144+
if (params.get('d') !== null) { // got it via query param d
145+
showDatatable = true;
146+
}
147+
148+
if (showDatatable) {
149+
$("#nav_disable_datatable").show();
150+
$("#nav_enable_datatable").hide();
151+
$(document).ready( function () {
152+
$('#data_table').DataTable({
153+
dom: "<'row'<'col-sm-12 col-md-4'B><'col-sm-12 col-md-4'l><'col-sm-12 col-md-4'f>>" +
154+
"<'row'<'col-sm-12'tr>>" +
155+
"<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",
156+
buttons: [
157+
'copy', 'csv', 'excel', 'pdf', 'print'
158+
]
159+
}
160+
);
161+
} );
162+
} else {
163+
$("#nav_disable_datatable").hide();
164+
$("#nav_enable_datatable").show();
165+
}
166+
167+
</script>
168+
</body>
169+
</html>

0 commit comments

Comments
 (0)