Skip to content

Commit fa68fbf

Browse files
committed
Initial commit :)
0 parents  commit fa68fbf

File tree

4 files changed

+130
-0
lines changed

4 files changed

+130
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
composer.lock
2+
vendor/

LICENSE.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Copyright (c) 2020, Michel Hunziker <[email protected]>.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
8+
* Redistributions of source code must retain the above copyright
9+
notice, this list of conditions and the following disclaimer.
10+
11+
* Redistributions in binary form must reproduce the above copyright
12+
notice, this list of conditions and the following disclaimer in
13+
the documentation and/or other materials provided with the
14+
distribution.
15+
16+
* Neither the name of Michel Hunziker nor the names of his
17+
contributors may be used to endorse or promote products derived
18+
from this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23+
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24+
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25+
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26+
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30+
ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31+
POSSIBILITY OF SUCH DAMAGE.

composer.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "micheh/phpcs-gitlab",
3+
"description": "PHPCodeSniffer report for Gitlab",
4+
"type": "library",
5+
"license": "BSD-3-Clause",
6+
"authors": [
7+
{
8+
"name": "Michel Hunziker",
9+
"email": "[email protected]"
10+
}
11+
],
12+
"minimum-stability": "stable",
13+
"require-dev": {
14+
"squizlabs/php_codesniffer": "^3.5"
15+
},
16+
"autoload": {
17+
"psr-4": {
18+
"Micheh\\PhpCodeSniffer\\": "src/"
19+
}
20+
}
21+
}

src/Report/GitlabReport.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
/**
4+
* @copyright Copyright (c) 2020, Michel Hunziker <[email protected]>
5+
* @license http://www.opensource.org/licenses/BSD-3-Clause The BSD-3-Clause License
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Micheh\PhpCodeSniffer\Report;
11+
12+
use PHP_CodeSniffer\Files\File;
13+
use PHP_CodeSniffer\Reports\Report;
14+
15+
use function md5;
16+
use function str_replace;
17+
18+
use const PHP_EOL;
19+
20+
class GitlabReport implements Report
21+
{
22+
/**
23+
* @inheritDoc
24+
*/
25+
public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80): bool
26+
{
27+
$hasOutput = false;
28+
29+
foreach ($report['messages'] as $line => $lineErrors) {
30+
foreach ($lineErrors as $column => $colErrors) {
31+
foreach ($colErrors as $error) {
32+
$issue = [
33+
'type' => 'issue',
34+
'categories' => ['Style'],
35+
'check_name' => $error['source'],
36+
'fingerprint' => md5($report['filename'] . $error['message'] . $line),
37+
'description' => str_replace(["\n", "\r", "\t"], ['\n', '\r', '\t'], $error['message']),
38+
'location' => [
39+
'path' => $report['filename'],
40+
'lines' => [
41+
'begin' => $line,
42+
'end' => $line,
43+
]
44+
],
45+
];
46+
47+
if ($hasOutput) {
48+
echo ',';
49+
}
50+
51+
echo json_encode($issue, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
52+
$hasOutput = true;
53+
}
54+
}
55+
}
56+
57+
return $hasOutput;
58+
}
59+
60+
/**
61+
* @inheritDoc
62+
*/
63+
public function generate(
64+
$cachedData,
65+
$totalFiles,
66+
$totalErrors,
67+
$totalWarnings,
68+
$totalFixable,
69+
$showSources = false,
70+
$width = 80,
71+
$interactive = false,
72+
$toScreen = true
73+
): void {
74+
echo '[' . $cachedData . ']' . PHP_EOL;
75+
}
76+
}

0 commit comments

Comments
 (0)