Skip to content

Commit c98e507

Browse files
committed
First commit with PhpAssumptions and PHP Magic Number Detector
0 parents  commit c98e507

13 files changed

+957
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### Composer template
3+
composer.phar
4+
/vendor/
5+
6+
# Commit your application's lock file https://getcomposer.org/doc/01-basic-usage.md#commit-your-composer-lock-file-to-version-control
7+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
8+
composer.lock
9+
10+
/build/

.phpqa.yml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
tool:
2+
phpa: MacFJA\PHPQAExtensions\Tools\Analyzer\PhpAssumptions
3+
phpmnd: MacFJA\PHPQAExtensions\Tools\Analyzer\PhpMagicNumber
4+
report:
5+
phpa: app/report/phpassumptions.xsl
6+
phpmnd: app/report/phpmagicnumber.xsl

LICENSE.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2018 [MacFJA](https://github.com/MacFJA)
4+
5+
> Permission is hereby granted, free of charge, to any person obtaining a copy
6+
> of this software and associated documentation files (the "Software"), to deal
7+
> in the Software without restriction, including without limitation the rights
8+
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
> copies of the Software, and to permit persons to whom the Software is
10+
> furnished to do so, subject to the following conditions:
11+
>
12+
> The above copyright notice and this permission notice shall be included in
13+
> all copies or substantial portions of the Software.
14+
>
15+
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
> THE SOFTWARE.

README.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# PHPQA Extensions
2+
3+
Add more tools to [PHPQA](https://github.com/EdgedesignCZ/phpqa)
4+
5+
## Usage
6+
7+
### Get the list of available tools
8+
9+
```
10+
$ php vendor/bin/phpqa-extensions.php --tools
11+
12+
List of available tools
13+
=======================
14+
15+
--------------------------- -------- --------------------------- -----------
16+
Name CLI Composer Installed
17+
--------------------------- -------- --------------------------- -----------
18+
PhpAssumptions phpa rskuipers/php-assumptions No
19+
PHP Magic Number Detector phpmnd povils/phpmnd No
20+
--------------------------- -------- --------------------------- -----------
21+
```
22+
23+
### Install a tool on a project
24+
25+
```
26+
$ php vendor/bin/phpqa-extensions.php --add phpmnd
27+
```
28+
or
29+
```
30+
$ php vendor/bin/phpqa-extensions.php --add "PHP Magic Number Detector"
31+
```
32+
or
33+
```
34+
$ php vendor/bin/phpqa-extensions.php --add povils/phpmnd
35+
```
36+
37+
Several tools can be add in one times:
38+
```
39+
$ php vendor/bin/phpqa-extensions.php --add phpmnd --add phpa
40+
```
41+
42+
## Options
43+
44+
| Option name | Default | Tool | Description |
45+
|-------------|---------|------|-------------|
46+
| phpmnd.ignore-numbers | _null_ | PHP Magic Number Detector | List (comma separate) of number to ignore (typically 0,1,2) |
47+
| phpmnd.ignore-funcs | _null_ | PHP Magic Number Detector | List (comma separate) of function to ignore |
48+
| phpmnd.ignore-strings | _null_ | PHP Magic Number Detector | List (comma separate) of strings value to ignore |
49+
| phpmnd.strings | `false` | PHP Magic Number Detector | Activate the strings literal analysis |
50+
51+
## How to contribute
52+
53+
If you found a nice tool that you want to added, open a issue on GitHub.
54+
55+
You can also create Pull Request of a new tool.

app/report/phpassumptions.xsl

+164
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
3+
4+
<xsl:output method="html" encoding="UTF-8"/>
5+
<xsl:key name="file-category" match="//files/file" use="@name" />
6+
<xsl:param name="root-directory"/>
7+
8+
<xsl:template match="/">
9+
<html>
10+
<head>
11+
<title>PhpAssumptions report</title>
12+
<link rel="stylesheet"><xsl:attribute name="href"><xsl:value-of select="$bootstrap.min.css" /></xsl:attribute></link>
13+
<style>
14+
.file {
15+
background: #f9f9f9
16+
}
17+
.fixed-navbar {
18+
list-style-type: none;
19+
position: fixed;
20+
top: 0;
21+
right: 1em;
22+
}
23+
</style>
24+
<script>
25+
var onDocumentReady = [
26+
function () {
27+
$('[data-file]').each(function () {
28+
var pathWithoutRoot = $(this).text().replace('<xsl:value-of select="$root-directory"></xsl:value-of>', '');
29+
$(this).text(pathWithoutRoot);
30+
});
31+
}
32+
];
33+
</script>
34+
</head>
35+
<body>
36+
37+
<div class="container-fluid">
38+
39+
<h1>PhpAssumptions report</h1>
40+
41+
<nav>
42+
<ul class="nav nav-pills" role="tablist">
43+
<li role="presentation" class="active">
44+
<a href="#overview" aria-controls="overview" role="tab" data-toggle="tab">Overview</a>
45+
</li>
46+
<li role="presentation">
47+
<a href="#errors" aria-controls="errors" role="tab" data-toggle="tab">Errors</a>
48+
</li>
49+
</ul>
50+
</nav>
51+
52+
<div class="tab-content">
53+
54+
<div role="tabpanel" class="tab-pane active" id="overview">
55+
<table class="table table-striped">
56+
<thead>
57+
<tr>
58+
<th>File</th>
59+
<th>Errors</th>
60+
</tr>
61+
</thead>
62+
<!-- http://stackoverflow.com/a/9589085/4587679 -->
63+
<xsl:for-each select="//files/file[generate-id() = generate-id(key('file-category', ./@name)[1])]">
64+
<xsl:variable name="group" select="@name"/>
65+
<tr>
66+
<td><strong data-file=""><xsl:value-of select="$group"/></strong></td>
67+
<td><xsl:value-of select="count(//files/file[@name = $group]/line)"/></td>
68+
</tr>
69+
</xsl:for-each>
70+
<tfoot>
71+
<tr>
72+
<th><span class="label label-info"><xsl:value-of select="count(//files/file[generate-id() = generate-id(key('file-category', @name)[1])])"/></span></th>
73+
<th>
74+
<span class="label label-danger"><xsl:value-of select="count(//files/file/line)" /></span>
75+
<span class="label label-warning"><xsl:value-of select="/phpa/@percentage" /><xsl:text>%</xsl:text></span>
76+
</th>
77+
</tr>
78+
</tfoot>
79+
</table>
80+
</div>
81+
82+
<div role="tabpanel" class="tab-pane" id="errors">
83+
<div class="fixed-navbar">
84+
<div class="input-group" style="width: 20em">
85+
<span class="input-group-addon"><span class="glyphicon glyphicon-search" aria-hidden="true"></span></span>
86+
<input data-search="errors" type="text" class="form-control" placeholder="undefined..." />
87+
</div>
88+
</div>
89+
<script>
90+
onDocumentReady.push(function () {
91+
var groups = $('[data-filterable] tbody tr[data-permanent]');
92+
var rows = $('[data-filterable] tbody tr:not([data-permanent])');
93+
94+
$("[data-search]").keyup(function () {
95+
var term = $(this).val().toLowerCase();
96+
97+
rows.hide();
98+
groups.show();
99+
matchElements(rows).show();
100+
matchEmptyGroups().hide();
101+
102+
function matchElements(elements) {
103+
return elements.filter(function () {
104+
var rowContent = $(this).text().toLowerCase();
105+
return rowContent.indexOf(term) !== -1
106+
});
107+
}
108+
109+
function matchEmptyGroups() {
110+
return groups.filter(function () {
111+
var group = $(this).data('permanent');
112+
return rows
113+
.filter(function () {
114+
return $(this).data('group') == group <![CDATA[&&]]> $(this).is(':visible');
115+
})
116+
.length == 0;
117+
});
118+
}
119+
});
120+
});
121+
</script>
122+
123+
<table class="table" data-filterable="errors">
124+
<thead>
125+
<tr>
126+
<th>Error</th>
127+
<th>Line</th>
128+
</tr>
129+
</thead>
130+
<xsl:for-each select="//files/file[generate-id() = generate-id(key('file-category', ./@name)[1])]">
131+
<xsl:variable name="group" select="@name"/>
132+
<tr>
133+
<xsl:attribute name="data-permanent">
134+
<xsl:value-of select="$group" />
135+
</xsl:attribute>
136+
<td colspan="3" class="file"><strong data-file=""><xsl:value-of select="$group" /></strong></td>
137+
</tr>
138+
<xsl:for-each select="//files/file[@name = $group]/line">
139+
<tr>
140+
<xsl:attribute name="data-group">
141+
<xsl:value-of select="../@name" />
142+
</xsl:attribute>
143+
<td>
144+
<pre class="text-muted"><xsl:value-of select="@message" /></pre>
145+
</td>
146+
<td><xsl:value-of select="@number" /></td>
147+
</tr>
148+
</xsl:for-each>
149+
</xsl:for-each>
150+
</table>
151+
</div>
152+
</div>
153+
</div>
154+
155+
156+
<script><xsl:attribute name="src"><xsl:value-of select="$jquery.min.js" /></xsl:attribute></script>
157+
<script><xsl:attribute name="src"><xsl:value-of select="$bootstrap.min.js" /></xsl:attribute></script>
158+
<script>
159+
$(document).ready(onDocumentReady);
160+
</script>
161+
</body>
162+
</html>
163+
</xsl:template>
164+
</xsl:stylesheet>

0 commit comments

Comments
 (0)