Skip to content

Commit a534bc9

Browse files
author
DKravtsov
committed
extending xml report functionality.
1 parent a5e220a commit a534bc9

File tree

3 files changed

+223
-0
lines changed

3 files changed

+223
-0
lines changed

schema/cpd-report_1_0_0.xsd

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0"?>
2+
<xs:schema
3+
xmlns:xs="http://www.w3.org/2001/XMLSchema"
4+
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="https://github.com/systemsdk/phpcpd/schema"
5+
targetNamespace="https://github.com/systemsdk/phpcpd/schema"
6+
elementFormDefault="qualified">
7+
8+
<xsd:annotation>
9+
<xs:documentation><![CDATA[ PHP CPD Report Schema, version 1.0.0.]]></xs:documentation>
10+
</xsd:annotation>
11+
12+
<xs:element name="pmd-cpd">
13+
<xs:complexType>
14+
<xs:sequence>
15+
<xs:element name="file" type="file" minOccurs="0" maxOccurs="unbounded"/>
16+
<xs:element name="duplication" type="duplication" minOccurs="0" maxOccurs="unbounded"/>
17+
<xs:element name="error" type="error" minOccurs="0" maxOccurs="unbounded"/>
18+
</xs:sequence>
19+
<xs:attribute name="phpcpdVersion" type="xs:string" use="required"/>
20+
<xs:attribute name="timestamp" type="xs:string" use="required"/>
21+
<xs:attribute name="version" type="xs:string" use="required"/>
22+
</xs:complexType>
23+
</xs:element>
24+
25+
<xs:complexType name="file">
26+
<xs:attribute name="path" type="xs:string" use="required"/>
27+
<xs:attribute name="totalNumberOfTokens" type="xs:nonNegativeInteger" use="required"/>
28+
</xs:complexType>
29+
30+
<xs:complexType name="duplication">
31+
<xs:sequence>
32+
<xs:element name="file" type="fileLocation" minOccurs="2" maxOccurs="unbounded"/>
33+
<xs:element name="codefragment" type="codefragment" minOccurs="1" maxOccurs="1"/>
34+
</xs:sequence>
35+
<xs:attribute name="lines" type="xs:positiveInteger" use="required"/>
36+
<xs:attribute name="tokens" type="xs:positiveInteger" use="required"/>
37+
</xs:complexType>
38+
39+
<xs:complexType name="error">
40+
<xs:simpleContent>
41+
<xs:extension base="xs:string">
42+
<xs:attribute name="filename" type="xs:string" use="required"/>
43+
<xs:attribute name="msg" type="xs:string" use="required"/>
44+
</xs:extension>
45+
</xs:simpleContent>
46+
</xs:complexType>
47+
48+
<xs:complexType name="fileLocation">
49+
<xs:attribute name="line" type="xs:positiveInteger" use="required"/>
50+
<xs:attribute name="endline" type="xs:positiveInteger" use="required"/>
51+
<xs:attribute name="path" type="xs:string" use="required"/>
52+
</xs:complexType>
53+
54+
<xs:complexType name="codefragment">
55+
<xs:simpleContent>
56+
<xs:extension base="xs:string"/>
57+
</xs:simpleContent>
58+
</xs:complexType>
59+
</xs:schema>

schema/cpdhtml-v1.xslt

+148
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:cpd="https://github.com/systemsdk/phpcpd/schema" exclude-result-prefixes="cpd">
3+
<xsl:output method="html" doctype-system="about:legacy-compat"/>
4+
<xsl:template match="/">
5+
<html>
6+
<head>
7+
<meta charset="utf-8"/>
8+
9+
<!-- Dependencies:
10+
https://getbootstrap.com/docs/5.3/getting-started/download/
11+
https://datatables.net/download/ (Styling Bootstrap5 + DataTables + Buttons + Column Visibility + HTML5 Export + JSZip + pdfmake + Print view
12+
https://releases.jquery.com/
13+
-->
14+
15+
<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"/>
16+
<script src="https://code.jquery.com/jquery-3.7.0.min.js" integrity="sha256-2Pmvv0kuTBOenSvLm6bvfBSSHrUJ+3A7x6P5Ebd07/g=" crossorigin="anonymous"/>
17+
<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"/>
18+
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js"/>
19+
<script src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js"/>
20+
<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"/>
21+
22+
</head>
23+
<body style="padding-top: 3.5rem;">
24+
<nav class="navbar navbar-expand-lg fixed-top navbar-dark bg-dark">
25+
<a class="navbar-brand" href="#">PHP Copy/Paste Detector</a>
26+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav"
27+
aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
28+
<span class="navbar-toggler-icon"></span>
29+
</button>
30+
<div class="collapse navbar-collapse" id="navbarNav">
31+
<ul class="navbar-nav">
32+
<li class="nav-item">
33+
<a class="nav-link active" href="#">Report</a>
34+
</li>
35+
<li class="nav-item" id="nav_enable_datatable">
36+
<a class="nav-link" href="?d=">Enable datatable</a>
37+
</li>
38+
<li class="nav-item" id="nav_disable_datatable">
39+
<a class="nav-link" href="?">Disable datatable</a>
40+
</li>
41+
<li class="nav-item">
42+
<a class="nav-link" target="_blank" rel="noopener noreferrer" href="https://packagist.org/packages/systemsdk/phpcpd">Package page</a>
43+
</li>
44+
</ul>
45+
</div>
46+
</nav>
47+
48+
<div class="container">
49+
<div class="row">
50+
<div class="col">
51+
<h4>Summary of duplicated code</h4>
52+
<p>This page summarizes the code fragments that have been found to be replicated in the code.</p>
53+
54+
<table class="table table-light table-bordered table-striped table-hover">
55+
<tr>
56+
<th># Duplications</th>
57+
<th>Total lines</th>
58+
<th>Total tokens</th>
59+
<th>Approximate number of bytes</th>
60+
</tr>
61+
<tr>
62+
<td class="SummaryNumber"><xsl:value-of select="count(//cpd:duplication)"/></td>
63+
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication/@lines)"/></td>
64+
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication/@tokens)"/></td>
65+
<td class="SummaryNumber"><xsl:value-of select="sum(//cpd:duplication/@tokens) * 4"/></td>
66+
</tr>
67+
</table>
68+
</div>
69+
</div>
70+
71+
<div class="row">
72+
<div class="col">
73+
<h4>Details of duplicated code</h4>
74+
</div>
75+
<table style="width:100%" id="data_table" class="table table-light table-bordered table-striped table-hover">
76+
<thead>
77+
<tr>
78+
<th>lines</th>
79+
<th>tokens</th>
80+
<th>files</th>
81+
<th>codefragment</th>
82+
</tr>
83+
</thead>
84+
<tbody>
85+
<xsl:apply-templates select="cpd:pmd-cpd/cpd:duplication" />
86+
</tbody>
87+
</table>
88+
</div>
89+
</div>
90+
91+
<script>
92+
let params = (new URL(document.location)).searchParams;
93+
let showDatatable = false;
94+
95+
//------------ can be called with this parameter d
96+
if (params.get('d') !== null) { // got it via query param d
97+
showDatatable = true;
98+
}
99+
100+
if (showDatatable) {
101+
$("#nav_disable_datatable").show();
102+
$("#nav_enable_datatable").hide();
103+
$(document).ready( function () {
104+
$('#data_table').DataTable({
105+
dom: "&lt;'row'&lt;'col-sm-12 col-md-4'B>&lt;'col-sm-12 col-md-4'l>&lt;'col-sm-12 col-md-4'f>>" +
106+
"&lt;'row'&lt;'col-sm-12'tr>>" +
107+
"&lt;'row'&lt;'col-sm-12 col-md-5'i>&lt;'col-sm-12 col-md-7'p>>",
108+
buttons: [
109+
'copy', 'csv', 'excel', 'pdf', 'print'
110+
]
111+
}
112+
);
113+
} );
114+
} else {
115+
$("#nav_disable_datatable").hide();
116+
$("#nav_enable_datatable").show();
117+
}
118+
119+
</script>
120+
121+
</body>
122+
</html>
123+
</xsl:template>
124+
125+
<!-- templates -->
126+
<xsl:template match="cpd:pmd-cpd/cpd:duplication">
127+
<xsl:for-each select=".">
128+
<tr>
129+
<td><xsl:value-of select="@lines"/></td>
130+
<td><xsl:value-of select="@tokens"/></td>
131+
<td>
132+
<table class="table table-light table-bordered table-striped table-hover">
133+
<tr><th>line</th><th>endline</th><th>path</th></tr>
134+
<xsl:for-each select="cpd:file">
135+
<tr>
136+
<td><xsl:value-of select="@line"/></td>
137+
<td><xsl:value-of select="@endline"/></td>
138+
<td><xsl:value-of select="@path"/></td>
139+
</tr>
140+
</xsl:for-each>
141+
</table>
142+
</td>
143+
<td><pre><xsl:value-of select="cpd:codefragment"/></pre></td>
144+
</tr>
145+
</xsl:for-each>
146+
</xsl:template>
147+
148+
</xsl:stylesheet>

schema/readme.md

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# PHP Copy/Paste Detector Report Schema
2+
PHP Copy/Paste Detector Report schema versions.
3+
4+
## PHP CPD Report Schema 1.0.0
5+
Namespace: `https://github.com/systemsdk/phpcpd/schema`
6+
7+
Schema Location: `https://github.com/systemsdk/phpcpd/schema/cpd-report_1_0_0.xsd`
8+
9+
Current Version: 1.0.0 (since phpcpd 8.2.0)
10+
11+
Last Change: 2025-04-27
12+
13+
Report file example:
14+
```
15+
16+
```

0 commit comments

Comments
 (0)