From 47d311cd08201af9da65614644657b2c8a2791d2 Mon Sep 17 00:00:00 2001 From: wickedOne Date: Sat, 2 Oct 2021 11:49:55 +0200 Subject: [PATCH] phpstorm reporter --- .gitignore | 1 + CODE_OF_CONDUCT.md | 1 + README.md | 28 +++++++++++++++ composer.json | 28 +++++++++++++++ composer.lock | 77 ++++++++++++++++++++++++++++++++++++++++++ src/PhpStormReport.php | 45 ++++++++++++++++++++++++ 6 files changed, 180 insertions(+) create mode 100644 .gitignore create mode 100644 CODE_OF_CONDUCT.md create mode 100644 README.md create mode 100644 composer.json create mode 100644 composer.lock create mode 100644 src/PhpStormReport.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..42cd73d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/vendor/ \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..25f31a8 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1 @@ +don't be a dick \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..5f50bc1 --- /dev/null +++ b/README.md @@ -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 + + + + + + ... + +``` \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..d88fa9f --- /dev/null +++ b/composer.json @@ -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": "wicliff.wolda@gmail.com" + } + ], + "autoload": { + "psr-4": { + "WickedOne\\PHPCSReport\\": "src/" + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..c230d55 --- /dev/null +++ b/composer.lock @@ -0,0 +1,77 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "845d8d291cd5539aebf53bc82c71a5f8", + "packages": [ + { + "name": "squizlabs/php_codesniffer", + "version": "3.6.0", + "source": { + "type": "git", + "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "reference": "ffced0d2c8fa8e6cdc4d695a743271fab6c38625", + "shasum": "" + }, + "require": { + "ext-simplexml": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^4.0 || ^5.0 || ^6.0 || ^7.0" + }, + "bin": [ + "bin/phpcs", + "bin/phpcbf" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.x-dev" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Greg Sherwood", + "role": "lead" + } + ], + "description": "PHP_CodeSniffer tokenizes PHP, JavaScript and CSS files and detects violations of a defined set of coding standards.", + "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", + "keywords": [ + "phpcs", + "standards" + ], + "support": { + "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", + "source": "https://github.com/squizlabs/PHP_CodeSniffer", + "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" + }, + "time": "2021-04-09T00:54:41+00:00" + } + ], + "packages-dev": [], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": true, + "prefer-lowest": false, + "platform": { + "php": ">=7.3" + }, + "platform-dev": [], + "plugin-api-version": "2.1.0" +} diff --git a/src/PhpStormReport.php b/src/PhpStormReport.php new file mode 100644 index 0000000..9bf9533 --- /dev/null +++ b/src/PhpStormReport.php @@ -0,0 +1,45 @@ + + * + * 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 + */ +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; + } +}