From dc76ab95dfcbb44be1778edcd38dc9664012cb9a Mon Sep 17 00:00:00 2001 From: Guy Sartorelli Date: Thu, 2 Nov 2023 11:25:47 +1300 Subject: [PATCH] ENH Tidy-up code --- bin/mdphpcs | 2 +- composer.json | 4 ++-- src/CodeBlock.php | 19 ++++++++++++++++++- src/FixerReport.php | 2 +- src/Sniffer.php | 18 ++++++++++++------ tests/CodeBlockTest.php | 8 ++++---- tests/SnifferFixTest.php | 4 ++-- tests/SnifferTest.php | 4 ++-- 8 files changed, 42 insertions(+), 19 deletions(-) diff --git a/bin/mdphpcs b/bin/mdphpcs index c70ed55..e7af6ae 100755 --- a/bin/mdphpcs +++ b/bin/mdphpcs @@ -2,7 +2,7 @@ path = $path; + $this->realPath = $realPath; + $this->num = $num; + } + public function cleanUp() { $this->finalContent = $this->content ?? ''; diff --git a/src/FixerReport.php b/src/FixerReport.php index c43d8f0..e86d5ea 100644 --- a/src/FixerReport.php +++ b/src/FixerReport.php @@ -1,6 +1,6 @@ ruleset, $sniffer->config); - $dummy->num = $block['num']; - $dummy->path = $block['path']; - $dummy->realPath = $block['realpath']; + $dummy = new CodeBlock( + $sniffer->ruleset, + $sniffer->config, + $block['content'], + $block['path'], + $block['realpath'], + $block['num'] + ); $todo[] = $dummy; } @@ -107,6 +111,7 @@ public function run(string $lintLanguage, bool $fixing, bool $usingExplicitStand $sniffer->reporter->printReports(); + // These return values are directly from Runner::runPHPCS() if ($numErrors === 0) { // No errors found. return 0; @@ -148,6 +153,7 @@ private function prepareConfig(bool $usingExplicitStandard, string $lintLanguage $config->standards = [__DIR__ . '/../phpcs.default.xml']; } + // Most of these overrides are directly from Runner::runPHPCBF() if ($fixing) { // Override some of the command line settings that might break the fixes. $config->generator = null; @@ -228,7 +234,7 @@ private function sniff(Runner $sniffer, array $todo): int // Turn all sniff errors into exceptions. set_error_handler([$sniffer, 'handleErrors']); - $lastDir = ''; + $lastDir = ''; $numBlocks = count($todo); // Process each block sequentially - running sniff in parallel isn't supported diff --git a/tests/CodeBlockTest.php b/tests/CodeBlockTest.php index edb18ca..604b294 100644 --- a/tests/CodeBlockTest.php +++ b/tests/CodeBlockTest.php @@ -1,12 +1,12 @@ assertSame('This is the content', $block->getContent()); @@ -34,7 +34,7 @@ public function testGetContent() public function testCleanup() { $config = new Config(); - $block = new CodeBlock('This is the content', new Ruleset($config), $config); + $block = new CodeBlock(new Ruleset($config), $config, 'This is the content', '', '', 0); $block->cleanUp(); $this->assertSame('This is the content', $block->getContent()); diff --git a/tests/SnifferFixTest.php b/tests/SnifferFixTest.php index 211ec4a..c3429cb 100644 --- a/tests/SnifferFixTest.php +++ b/tests/SnifferFixTest.php @@ -1,12 +1,12 @@