Skip to content

Commit 47d311c

Browse files
committed
phpstorm reporter
1 parent 134775f commit 47d311c

File tree

6 files changed

+180
-0
lines changed

6 files changed

+180
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/vendor/

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
don't be a dick

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# PHP CodeSniffer PhpStorm reporter
2+
3+
prints additional PhpStorm editor url in PHPCS cli output.
4+
5+
## installation
6+
```bash
7+
$ composer require --dev wickedone/phpcs-reporter
8+
```
9+
10+
### command line usage:
11+
specify this report on the command line:
12+
13+
```bash
14+
$ php vendor/bin/phpcs --report='WickedOne\PHPCSReport\PhpStormReport'
15+
```
16+
17+
### phpcs xml configuration
18+
specify this report in your ``phpcs.xml.dist``:
19+
```xml
20+
<?xml version="1.0" encoding="UTF-8"?>
21+
22+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
24+
25+
<arg name="report" value="WickedOne\PHPCSReport\PhpStormReport" />
26+
...
27+
28+
```

composer.json

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"name": "wickedone/phpcs-reporter",
3+
"description": "PHP Codesniffer output with phpstorm editor url",
4+
"type": "library",
5+
"keywords": [
6+
"phpcs",
7+
"phpstorm",
8+
"testing"
9+
],
10+
"require": {
11+
"php": ">=7.3",
12+
"squizlabs/php_codesniffer": "^3.6"
13+
},
14+
"license": "MIT",
15+
"authors": [
16+
{
17+
"name": "wickedOne",
18+
"email": "[email protected]"
19+
}
20+
],
21+
"autoload": {
22+
"psr-4": {
23+
"WickedOne\\PHPCSReport\\": "src/"
24+
}
25+
},
26+
"minimum-stability": "dev",
27+
"prefer-stable": true
28+
}

composer.lock

Lines changed: 77 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/PhpStormReport.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of WickedOne\PHPCSReporter.
7+
*
8+
* (c) wicliff <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace WickedOne\PHPCSReport;
15+
16+
use PHP_CodeSniffer\Files\File;
17+
use PHP_CodeSniffer\Reports\Full;
18+
19+
/**
20+
* PhpStorm Report
21+
*
22+
* @author wicliff <[email protected]>
23+
*/
24+
class PhpStormReport extends Full
25+
{
26+
/**
27+
* {@inheritdoc
28+
*/
29+
public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80): bool
30+
{
31+
if ($report['errors'] === 0 && $report['warnings'] === 0) {
32+
return false;
33+
}
34+
35+
parent::generateFileReport($report, $phpcsFile, $showSources, $width);
36+
37+
if (count($report['messages']) > 1) {
38+
echo sprintf("✏️ phpstorm://open?file=%s", $phpcsFile->path).PHP_EOL;
39+
} else {
40+
echo sprintf("✏️ phpstorm://open?file=%s&line=%d", $phpcsFile->path, key($report['messages'])).PHP_EOL;
41+
}
42+
43+
return true;
44+
}
45+
}

0 commit comments

Comments
 (0)