diff --git a/.php_cs.dist b/.php_cs.dist index 0f254c63283bd..87483d5b33a15 100644 --- a/.php_cs.dist +++ b/.php_cs.dist @@ -4,10 +4,6 @@ * See COPYING.txt for license details. */ -/** - * Pre-commit hook installation: - * vendor/bin/static-review.php hook:install dev/tools/Magento/Tools/StaticReview/pre-commit .git/hooks/pre-commit - */ $finder = PhpCsFixer\Finder::create() ->name('*.phtml') ->exclude('dev/tests/functional/generated') diff --git a/dev/tools/Magento/Tools/StaticReview/PhpCsFixerReview.php b/dev/tools/Magento/Tools/StaticReview/PhpCsFixerReview.php deleted file mode 100644 index 113b139555dfb..0000000000000 --- a/dev/tools/Magento/Tools/StaticReview/PhpCsFixerReview.php +++ /dev/null @@ -1,66 +0,0 @@ - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * @see http://github.com/sjparkinson/static-review/blob/master/LICENSE.md - */ -namespace Magento\Tools\StaticReview; - -use StaticReview\File\FileInterface; -use StaticReview\Reporter\ReporterInterface; -use StaticReview\Review\AbstractReview; - -class PhpCsFixerReview extends AbstractReview -{ - /** - * @var array - */ - protected $options; - - /** - * @param array $options - */ - public function __construct($options = []) - { - $this->options = $options; - } - - /** - * Obtained from .php_cs configuration file. - * - * @param FileInterface $file - * @return bool - */ - public function canReview(FileInterface $file) - { - return in_array($file->getExtension(), ['php', 'phtml', 'xml', 'yml']); - } - - /** - * Checks and fixes PHP files using PHP Coding Standards Fixer. - * - * @param ReporterInterface $reporter - * @param FileInterface $file - * @return void - * @SuppressWarnings(PHPMD.UnusedFormalParameter) - */ - public function review(ReporterInterface $reporter, FileInterface $file) - { - $cmd = 'vendor/bin/php-cs-fixer -vvv '; - foreach ($this->options as $key => $value) { - $cmd .= ' --' . $key . '=' . escapeshellarg($value); - } - $cmd .= ' fix ' . escapeshellarg($file->getRelativePath()); - - $process = $this->getProcess($cmd); - $process->run(); - - $process = $this->getProcess('git add ' . escapeshellarg($file->getRelativePath())); - $process->run(); - } -} diff --git a/dev/tools/Magento/Tools/StaticReview/pre-commit b/dev/tools/Magento/Tools/StaticReview/pre-commit deleted file mode 100755 index 0bbb62797f434..0000000000000 --- a/dev/tools/Magento/Tools/StaticReview/pre-commit +++ /dev/null @@ -1,71 +0,0 @@ -#!/usr/bin/env php - - * - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - * - * @see https://github.com/sjparkinson/static-review/blob/master/LICENSE - */ -$included = include __DIR__ . '/../../../../../vendor/autoload.php'; -if (!$included) { - echo 'You must set up the project dependencies, run the following commands:' . PHP_EOL - . 'curl -sS https://getcomposer.org/installer | php' . PHP_EOL - . 'php composer.phar install' . PHP_EOL; - - exit(1); -} - -// Installation: -// vendor/bin/static-review.php hook:install dev/tools/Magento/Tools/StaticReview/pre-commit .git/hooks/pre-commit - -// Reference the required classes and the reviews you want to use. -use League\CLImate\CLImate; -use StaticReview\Reporter\Reporter; -use StaticReview\Review\Composer\ComposerLintReview; -use StaticReview\Review\General\LineEndingsReview; -use StaticReview\Review\General\NoCommitTagReview; -use StaticReview\Review\PHP\PhpLeadingLineReview; -use StaticReview\Review\PHP\PhpLintReview; -use Magento\Tools\StaticReview\PhpCsFixerReview; -use StaticReview\StaticReview; -use StaticReview\VersionControl\GitVersionControl; - -$reporter = new Reporter(); -$climate = new CLImate(); -$git = new GitVersionControl(); - -// Apply review which modifies staged files first -$review = new StaticReview($reporter); -$phpCsFixer = new PhpCsFixerReview(); -$review->addReview($phpCsFixer); -$review->review($git->getStagedFiles()); - -// Apply read-only review then -$review = new StaticReview($reporter); -$review->addReview(new LineEndingsReview()) - ->addReview(new PhpLeadingLineReview()) - ->addReview(new NoCommitTagReview()) - ->addReview(new PhpLintReview()) - ->addReview(new ComposerLintReview()); -$review->review($git->getStagedFiles()); - -// Check if any matching issues were found. -if ($reporter->hasIssues()) { - $climate->out('')->out(''); - - foreach ($reporter->getIssues() as $issue) { - $climate->red($issue); - } - - $climate->out('')->red('✘ Please fix the errors above.'); - - exit(1); -} else { - $climate->out('')->green('✔ Looking good.')->white('Have you tested everything?'); - - exit(0); -}