Skip to content

Commit 8ecc3d0

Browse files
authored
Merge pull request #407 from phpmetrics/issue-325-provide-miwoc
Provide configuration option "--maintainability-index-without-comments".
2 parents f2b11cc + b781420 commit 8ecc3d0

File tree

9 files changed

+259
-56
lines changed

9 files changed

+259
-56
lines changed

src/Hal/Application/Config/Validator.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,20 +56,20 @@ public function help()
5656
5757
Required:
5858
59-
<directories> List of directories to parse, separated by a comma (,)
59+
<directories> List of directories to parse, separated by a comma (,)
6060
6161
Optional:
6262
63-
--exclude=<directory> List of directories to exclude, separated by a comma (,)
64-
--extensions=<php,inc> List of extensions to parse, separated by a comma (,)
65-
--report-html=<directory> Folder where report HTML will be generated
66-
--report-csv=<file> File where report CSV will be generated
67-
--report-json=<file> File where report Json will be generated
68-
--report-violations=<file> File where XML violations report will be generated
69-
--git[=</path/to/git_binary>] Perform analyses based on Git History (default binary path: "git")
70-
--junit[=</path/to/junit.xml>] Evaluates metrics according to JUnit logs
71-
--quiet Quiet mode
72-
--version Display current version
63+
--exclude=<directory> List of directories to exclude, separated by a comma (,)
64+
--extensions=<php,inc> List of extensions to parse, separated by a comma (,)
65+
--report-html=<directory> Folder where report HTML will be generated
66+
--report-csv=<file> File where report CSV will be generated
67+
--report-json=<file> File where report Json will be generated
68+
--report-violations=<file> File where XML violations report will be generated
69+
--git[=</path/to/git_binary>] Perform analyses based on Git History (default binary path: "git")
70+
--junit[=</path/to/junit.xml>] Evaluates metrics according to JUnit logs
71+
--quiet Quiet mode
72+
--version Display current version
7373
7474
Examples:
7575
@@ -80,7 +80,7 @@ public function help()
8080
8181
phpmetrics --report-violations="./build/violations.xml" ./src,./lib
8282
83-
Analyze the "./src" and "./lib" directories, and generate the "./build/violations.xml" file. This file could
83+
Analyze the "./src" and "./lib" directories, and generate the "./build/violations.xml" file. This file could
8484
be read by any Continuous Integration Platform, and follows the "PMD Violation" standards.
8585
8686
EOT;

templates/html_report/_footer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
<script type="text/javascript" src="js/d3.hexbin.v0.js"></script>
176176
<script type="text/javascript" src="js/sort-table.min.js"></script>
177177
<script type="text/javascript" src="js/graph-maintainability.js"></script>
178+
<script type="text/javascript" src="js/graph-carousel.js"></script>
178179
<script type="text/javascript" src="js/graph-licenses.js"></script>
179180
<script type="text/javascript" src="js/FileSaver.min.js"></script>
180181

templates/html_report/_header.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
<link rel="stylesheet" href="css/roboto.css">
1010
<link rel="stylesheet" href="css/normalize.css">
1111
<link rel="stylesheet" href="css/material-icons.css">
12+
<link rel="stylesheet" href="css/graph-carousel.css">
1213
</head>
1314
<body>
1415

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
body {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
6+
.bloc-graph {
7+
text-align: center;
8+
max-width: 1140px;
9+
margin: auto;
10+
}
11+
12+
.bloc-graph-carousel {
13+
background-size: cover;
14+
background-repeat: no-repeat;
15+
background-position: center;
16+
overflow: hidden;
17+
height: 400px;
18+
position: relative;
19+
display: flex;
20+
}
21+
.bloc-graph-carousel p {
22+
font-size: 1em;
23+
}
24+
25+
.icon-container span.dot {
26+
cursor: pointer;
27+
height: 16px;
28+
width: 16px;
29+
background-color: #eee;
30+
border-radius: 50%;
31+
display: inline-block;
32+
}
33+
34+
.icon-container span.dot.active {
35+
background-color: #bbb;
36+
}
37+
38+
.bloc-graph-items {
39+
position: relative;
40+
flex: 1;
41+
overflow: hidden;
42+
color: #000;
43+
}
44+
45+
.bloc-graph-item {
46+
width: 100%;
47+
height: 100%;
48+
transition: transform 1s;
49+
position: absolute;
50+
display: flex;
51+
flex-direction: column;
52+
justify-content: center;
53+
}
54+
.bloc-graph-item.first {
55+
left: 0;
56+
}
57+
.bloc-graph-item.second {
58+
left: 100%;
59+
}

templates/html_report/css/style.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ a {
275275
color: #333;
276276
display: inline-block;
277277
padding: 1px 5px;
278+
margin: 4px auto;
279+
font-size: 0.8em;
278280
}
279281

280282
.badge-score {

templates/html_report/index.php

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<?php require __DIR__ . '/_header.php'; ?>
1+
<?php
2+
require __DIR__ . '/_header.php'; ?>
23
<div class="row">
34
<div class="column">
45
<div class="bloc bloc-number">
@@ -59,18 +60,30 @@
5960
<div class="column column-help-inner">
6061
<div class="row">
6162
<div class="column with-help">
62-
<div class="bloc">
63-
<div class="label">Maintainability / complexity</div>
64-
<div id="svg-maintainability" class="svg-container"></div>
63+
<div class="bloc bloc-graph">
64+
<div class="bloc-graph-carousel">
65+
<div class="bloc-graph-items">
66+
<div class="bloc-graph-item first">
67+
<div class="label">Maintainability / complexity</div>
68+
<div id="svg-maintainability" class="svg-container"></div>
69+
</div>
70+
<div class="bloc-graph-item second">
71+
<div class="label">Maintainability without comments / complexity</div>
72+
<div id="svg-maintainability-without-comments" class="svg-container"></div>
73+
</div>
74+
</div>
75+
</div>
76+
<div class="icon-container">
77+
<span class="dot dot-first active" title="Maintainability / complexity"></span>
78+
<span class="dot dot-second" title="Maintainability without comments / complexity"></span>
79+
</div>
6580
</div>
6681
</div>
6782
<div class="column help">
6883
<div class="help-inner">
6984
<p>Each file is symbolized by a circle. Size of the circle represents the Cyclomatic
7085
complexity.
71-
Color
72-
of the circle represents the Maintainability Index.</p>
73-
86+
Color of the circle represents the Maintainability Index.</p>
7487
<p>Large red circles will be probably hard to maintain.</p>
7588
</div>
7689
</div>
@@ -95,14 +108,21 @@
95108
<tbody id="contentClassRank" class="clusterize-content">
96109
<?php
97110
$classesS = $classes;
98-
usort($classesS, function ($a, $b) {
111+
usort($classesS, static function ($a, $b) {
99112
return strcmp($b['pageRank'], $a['pageRank']);
100113
});
101114
//$classesS = array_slice($classesS, 0, 10);
102115
foreach ($classesS as $class) { ?>
103116
<tr>
104-
<td><?php echo $class['name']; ?> <span class="badge"
105-
title="Maintainability Index"><?php echo isset($class['mi']) ? $class['mi'] : ''; ?></span>
117+
<td><?php echo $class['name']; ?>
118+
<?php
119+
$badgeTitleMIWOC = 'Maintainability Index (w/o comments)';
120+
$mIwoC = isset($class['mIwoC']) ? $class['mIwoC'] : '';
121+
$badgeTitleMI = 'Maintainability Index';
122+
$mi = isset($class['mi']) ? $class['mi'] : '';
123+
?>
124+
<span class="badge" title="<?php echo $badgeTitleMI;?>"><?php echo $mi;?></span>
125+
<span class="badge" title="<?php echo $badgeTitleMIWOC;?>"><?php echo $mIwoC;?></span>
106126
</td>
107127
<td><?php echo $class['pageRank']; ?></td>
108128
</tr>
@@ -180,7 +200,8 @@
180200
<script type="text/javascript">
181201
document.onreadystatechange = function () {
182202
if (document.readyState === 'complete') {
183-
chartMaintainability();
203+
chartMaintainability(true);
204+
chartMaintainability(false);
184205

185206
new Clusterize({
186207
scrollId: 'clusterizeClassRank',
@@ -195,7 +216,7 @@
195216
// prepare json for packages pie
196217
<?php
197218
$json = [];
198-
$packages = isset($project['composer'], $project['composer']['packages']) ? $project['composer']['packages'] : [];
219+
$packages = isset($project['composer']['packages']) ? $project['composer']['packages'] : [];
199220
foreach ($packages as $package) {
200221
foreach ($package->license as $license) {
201222
if (!isset($json[$license])) {
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
(function () {
2+
'use strict';
3+
var slides = document.querySelectorAll('.bloc-graph-item'),
4+
dots = document.querySelectorAll('.dot'),
5+
carouselCount = 0,
6+
scrollInterval,
7+
interval = 5000;
8+
9+
dots[0].addEventListener('click', function (e) {
10+
e = e || window.event;
11+
e.preventDefault();
12+
carouselCount -= 100;
13+
slider(e);
14+
if (e.type !== 'autoClick') {
15+
clearInterval(scrollInterval);
16+
scrollInterval = setInterval(autoScroll, interval);
17+
}
18+
});
19+
dots[1].addEventListener('click', sliderEvent);
20+
dots[1].addEventListener('autoClick', sliderEvent);
21+
22+
function sliderEvent(e)
23+
{
24+
e = e || window.event;
25+
e.preventDefault();
26+
carouselCount += 100;
27+
slider(e);
28+
if (e.type !== "autoClick") {
29+
clearInterval(scrollInterval);
30+
scrollInterval = setInterval(autoScroll, interval);
31+
}
32+
}
33+
34+
function slider(e)
35+
{
36+
switch (carouselCount) {
37+
case -100:
38+
carouselCount = 0;
39+
break;
40+
case 200:
41+
carouselCount = 0;
42+
break;
43+
default:
44+
break;
45+
}
46+
for (var i = 0; i < slides.length; i += 1) {
47+
slides[i].setAttribute('style', 'transform:translateX(-' + carouselCount + '%)');
48+
}
49+
activeDot();
50+
}
51+
52+
function activeDot()
53+
{
54+
for (var i = 0; i < dots.length; i++) {
55+
dots[i].classList.remove('active')
56+
}
57+
switch (carouselCount) {
58+
case 0:
59+
dots[0].classList.add('active');
60+
break;
61+
case 100:
62+
dots[1].classList.add('active');
63+
break;
64+
default:
65+
break;
66+
}
67+
}
68+
69+
// create new Event to dispatch click for auto scroll
70+
var autoClick = new Event('autoClick');
71+
function autoScroll()
72+
{
73+
dots[1].dispatchEvent(autoClick);
74+
}
75+
76+
// set timing of dispatch click events
77+
scrollInterval = setInterval(autoScroll, interval);
78+
})();
Lines changed: 43 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
function chartMaintainability() {
1+
function chartMaintainability(withoutComment)
2+
{
3+
var chartId = withoutComment ? 'svg-maintainability-without-comments' : 'svg-maintainability';
24

3-
var diameter = document.getElementById('svg-maintainability').offsetWidth;
5+
var diameter = document.getElementById(chartId).offsetWidth;
46

57
var json = {
68
name: 'chart',
79
children: classes
810
};
911

10-
var svg = d3.select('#svg-maintainability').append('svg')
12+
var svg = d3.select('#' + chartId).append('svg')
1113
.attr('width', diameter)
1214
.attr('height', diameter);
1315

14-
1516
var bubble = d3.layout.pack()
1617
.size([diameter, diameter])
1718
.padding(3)
@@ -37,31 +38,49 @@ function chartMaintainability() {
3738
return d.r;
3839
})
3940
.style("fill", function (d) {
40-
if (d.mi > 85) {
41-
return '#8BC34A';
42-
} else if (d.mi > 69) {
43-
return '#FFC107';
41+
if (true === withoutComment) {
42+
if (d.mIwoC > 65) {
43+
return '#8BC34A';
44+
} else if (d.mIwoC > 53) {
45+
return '#FFC107';
46+
} else {
47+
return '#F44336';
48+
}
4449
} else {
45-
return '#F44336';
50+
if (d.mi > 85) {
51+
return '#8BC34A';
52+
} else if (d.mi > 69) {
53+
return '#FFC107';
54+
} else {
55+
return '#F44336';
56+
}
4657
}
4758
})
48-
.attr("transform", function (d) {
49-
return "translate(" + d.x + "," + d.y + ")";
50-
})
5159
.on('mouseover', function (d) {
52-
var text = '<strong>' + d.name + '</strong>'
53-
+ "<br />Cyclomatic Complexity : " + d.ccn
54-
+ "<br />Maintainability Index: " + d.mi;
60+
var text = '';
61+
if (true === withoutComment) {
62+
text = '<strong>' + d.name + '</strong>'
63+
+ "<br />Cyclomatic Complexity : " + d.ccn
64+
+ "<br />Maintainability Index (w/o comments): " + d.mIwoC;
65+
} else {
66+
text = '<strong>' + d.name + '</strong>'
67+
+ "<br />Cyclomatic Complexity : " + d.ccn
68+
+ "<br />Maintainability Index: " + d.mi;
69+
}
5570
d3.select('.tooltip').html(text);
56-
d3.select(".tooltip").style("opacity", 1);
71+
d3.select(".tooltip")
72+
.style("opacity", 1)
73+
.style("z-index", 1);
5774
})
5875
.on('mousemove', function () {
5976
d3.select(".tooltip")
6077
.style("left", (d3.event.pageX + 5) + "px")
6178
.style("top", (d3.event.pageY + 5) + "px");
6279
})
6380
.on('mouseout', function () {
64-
d3.select(".tooltip").style("opacity", 0);
81+
d3.select(".tooltip")
82+
.style("opacity", 0)
83+
.style("z-index", -1);
6584
});
6685

6786
d3.select("body")
@@ -70,12 +89,15 @@ function chartMaintainability() {
7089
.style("opacity", 0);
7190

7291
// button for saving image
73-
var button = d3.select('#svg-maintainability').append('button');
92+
var button = d3.select('#' + chartId).append('button');
7493
button
7594
.classed('btn-save-image', true)
7695
.text('download')
7796
.on('click', function () {
78-
var svg = d3.select('#svg-maintainability svg')[0][0];
79-
saveSvgAsImage(svg, 'PhpMetrics maintainability / complexity', 1900, 1900);
97+
var svg = d3.select('#' + chartId + ' svg')[0][0];
98+
var nameImage = (withoutComment)
99+
? 'PhpMetrics maintainability without comments / complexity'
100+
: 'PhpMetrics maintainability / complexity';
101+
saveSvgAsImage(svg, nameImage, 1900, 1900);
80102
});
81-
}
103+
}

0 commit comments

Comments
 (0)