|
| 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 | + |
| 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 > 14) |
| 47 | + { |
| 48 | + $v4 = 0; |
| 49 | + for ($i = 0; $i < $v3; $i++) |
| 50 | + { |
| 51 | + $v4 += ($v2 * $i); |
| 52 | + } |
| 53 | + } |
| 54 | + $v5 = ($v4 < $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 < $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 > 14) |
| 75 | + { |
| 76 | + $v4 = 0; |
| 77 | + for ($i = 0; $i < $v3; $i++) |
| 78 | + { |
| 79 | + $v4 += ($v2 * $i); |
| 80 | + } |
| 81 | + } |
| 82 | + $v5 = ($v4 < $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 < $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). |
0 commit comments