Skip to content

Commit

Permalink
phpstorm reporter
Browse files Browse the repository at this point in the history
  • Loading branch information
wickedOne committed Oct 2, 2021
1 parent 134775f commit 47d311c
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor/
1 change: 1 addition & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
don't be a dick
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# PHP CodeSniffer PhpStorm reporter

prints additional PhpStorm editor url in PHPCS cli output.

## installation
```bash
$ composer require --dev wickedone/phpcs-reporter
```

### command line usage:
specify this report on the command line:

```bash
$ php vendor/bin/phpcs --report='WickedOne\PHPCSReport\PhpStormReport'
```

### phpcs xml configuration
specify this report in your ``phpcs.xml.dist``:
```xml
<?xml version="1.0" encoding="UTF-8"?>

<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="report" value="WickedOne\PHPCSReport\PhpStormReport" />
...

```
28 changes: 28 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "wickedone/phpcs-reporter",
"description": "PHP Codesniffer output with phpstorm editor url",
"type": "library",
"keywords": [
"phpcs",
"phpstorm",
"testing"
],
"require": {
"php": ">=7.3",
"squizlabs/php_codesniffer": "^3.6"
},
"license": "MIT",
"authors": [
{
"name": "wickedOne",
"email": "[email protected]"
}
],
"autoload": {
"psr-4": {
"WickedOne\\PHPCSReport\\": "src/"
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
77 changes: 77 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions src/PhpStormReport.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

declare(strict_types=1);

/*
* This file is part of WickedOne\PHPCSReporter.
*
* (c) wicliff <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace WickedOne\PHPCSReport;

use PHP_CodeSniffer\Files\File;
use PHP_CodeSniffer\Reports\Full;

/**
* PhpStorm Report
*
* @author wicliff <[email protected]>
*/
class PhpStormReport extends Full
{
/**
* {@inheritdoc
*/
public function generateFileReport($report, File $phpcsFile, $showSources = false, $width = 80): bool
{
if ($report['errors'] === 0 && $report['warnings'] === 0) {
return false;
}

parent::generateFileReport($report, $phpcsFile, $showSources, $width);

if (count($report['messages']) > 1) {
echo sprintf("✏️ phpstorm://open?file=%s", $phpcsFile->path).PHP_EOL;
} else {
echo sprintf("✏️ phpstorm://open?file=%s&line=%d", $phpcsFile->path, key($report['messages'])).PHP_EOL;
}

return true;
}
}

0 comments on commit 47d311c

Please sign in to comment.