Skip to content

Commit 1be64c3

Browse files
committed
Updata ignore-files library and apply ignore in handlers
1 parent 5734db3 commit 1be64c3

File tree

5 files changed

+76
-34
lines changed

5 files changed

+76
-34
lines changed

composer.lock

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

config/services.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,15 @@
5656
</service>
5757
<service id="code.sniffer.handler" class="PhpGitHooks\Infrastructure\CodeSniffer\CodeSnifferHandler">
5858
<argument type="service" id="output.handler" />
59+
<argument type="service" id="ignore.files" />
5960
</service>
6061
<service id="check.php.mess.detection.pre.commit.executor" class="PhpGitHooks\Application\PhpMD\CheckPhpMessDetectionPreCommitExecutor">
6162
<argument type="service" id="pre.commit.config"/>
6263
<argument type="service" id="phpmd.handler"/>
6364
</service>
6465
<service id="phpmd.handler" class="PhpGitHooks\Infrastructure\PhpMD\PhpMDHandler">
6566
<argument type="service" id="output.handler" />
67+
<argument type="service" id="ignore.files" />
6668
</service>
6769
<service id="unit.test.pre.commit.executor" class="PhpGitHooks\Application\PhpUnit\UnitTestPreCommitExecutor">
6870
<argument type="service" id="pre.commit.config"/>
@@ -104,7 +106,7 @@
104106
<argument type="service" id="output.handler" />
105107
</service>
106108
<service id="file.reader" class="IgnoreFiles\Infrastructure\Disk\FileReader">
107-
<argument type="string">ignore_files</argument>
109+
<argument type="string">"ignore-files"</argument>
108110
</service>
109111
</services>
110112
</container>

src/PhpGitHooks/Infrastructure/CodeSniffer/CodeSnifferHandler.php

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace PhpGitHooks\Infrastructure\CodeSniffer;
44

5+
use IgnoreFiles\IgnoreFiles;
56
use PhpGitHooks\Application\Message\MessageConfigData;
67
use PhpGitHooks\Command\BadJobLogo;
8+
use PhpGitHooks\Command\OutputHandlerInterface;
79
use PhpGitHooks\Infrastructure\Common\ToolHandler;
810
use Symfony\Component\Process\Process;
911
use Symfony\Component\Process\ProcessBuilder;
@@ -19,6 +21,22 @@ class CodeSnifferHandler extends ToolHandler
1921
private $neddle;
2022
/** @var string */
2123
private $standard = 'PSR2';
24+
/**
25+
* @var IgnoreFiles
26+
*/
27+
private $ignoreFiles;
28+
29+
/**
30+
* CodeSnifferHandler constructor.
31+
*
32+
* @param OutputHandlerInterface $outputHandler
33+
* @param IgnoreFiles $ignoreFiles
34+
*/
35+
public function __construct(OutputHandlerInterface $outputHandler, IgnoreFiles $ignoreFiles)
36+
{
37+
parent::__construct($outputHandler);
38+
$this->ignoreFiles = $ignoreFiles;
39+
}
2240

2341
/**
2442
* @param array $messages
@@ -35,17 +53,19 @@ public function run(array $messages)
3553
continue;
3654
}
3755

38-
$processBuilder = new ProcessBuilder(array('php', 'bin/phpcs', '--standard='.$this->standard, $file));
39-
/** @var Process $phpCs */
40-
$phpCs = $processBuilder->getProcess();
41-
$phpCs->run();
56+
if (false === $this->ignoreFiles->isIgnored($file)) {
57+
$processBuilder = new ProcessBuilder(array('php', 'bin/phpcs', '--standard='.$this->standard, $file));
58+
/** @var Process $phpCs */
59+
$phpCs = $processBuilder->getProcess();
60+
$phpCs->run();
4261

43-
if (false === $phpCs->isSuccessful()) {
44-
$this->outputHandler->setError($phpCs->getOutput());
45-
$this->output->writeln($this->outputHandler->getError());
46-
$this->output->writeln(BadJobLogo::paint($messages[MessageConfigData::KEY_ERROR_MESSAGE]));
62+
if (false === $phpCs->isSuccessful()) {
63+
$this->outputHandler->setError($phpCs->getOutput());
64+
$this->output->writeln($this->outputHandler->getError());
65+
$this->output->writeln(BadJobLogo::paint($messages[MessageConfigData::KEY_ERROR_MESSAGE]));
4766

48-
throw new InvalidCodingStandardException();
67+
throw new InvalidCodingStandardException();
68+
}
4969
}
5070
}
5171

src/PhpGitHooks/Infrastructure/PhpCsFixer/PhpCsFixerHandler.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ public function run(array $messages)
4747
$errors = array();
4848

4949
foreach ($this->files as $file) {
50-
if (false === $this->ignoreFiles->isIgnored($file)) {
51-
$srcFile = preg_match($this->filesToAnalyze, $file);
50+
$srcFile = preg_match($this->filesToAnalyze, $file);
5251

53-
if (!$srcFile) {
54-
continue;
55-
}
52+
if (!$srcFile) {
53+
continue;
54+
}
5655

56+
if (false === $this->ignoreFiles->isIgnored($file)) {
5757
$processBuilder = new ProcessBuilder(
5858
array(
5959
'php',

src/PhpGitHooks/Infrastructure/PhpMD/PhpMDHandler.php

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace PhpGitHooks\Infrastructure\PhpMD;
44

5+
use IgnoreFiles\IgnoreFiles;
56
use PhpGitHooks\Application\Message\MessageConfigData;
7+
use PhpGitHooks\Command\OutputHandlerInterface;
68
use PhpGitHooks\Infrastructure\Common\RecursiveToolInterface;
79
use PhpGitHooks\Infrastructure\Common\ToolHandler;
810
use Symfony\Component\Process\ProcessBuilder;
@@ -16,6 +18,22 @@ class PhpMDHandler extends ToolHandler implements RecursiveToolInterface
1618
private $files;
1719
/** @var string */
1820
private $needle;
21+
/**
22+
* @var IgnoreFiles
23+
*/
24+
private $ignoreFiles;
25+
26+
/**
27+
* PhpMDHandler constructor.
28+
*
29+
* @param OutputHandlerInterface $outputHandler
30+
* @param IgnoreFiles $ignoreFiles
31+
*/
32+
public function __construct(OutputHandlerInterface $outputHandler, IgnoreFiles $ignoreFiles)
33+
{
34+
parent::__construct($outputHandler);
35+
$this->ignoreFiles = $ignoreFiles;
36+
}
1937

2038
/**
2139
* @param array $messages
@@ -34,22 +52,24 @@ public function run(array $messages)
3452
continue;
3553
}
3654

37-
$processBuilder = new ProcessBuilder(
38-
array(
39-
'php',
40-
'bin/phpmd',
41-
$file,
42-
'text',
43-
'PmdRules.xml',
44-
'--minimumpriority',
45-
1,
46-
)
47-
);
48-
$process = $processBuilder->getProcess();
49-
$process->run();
55+
if (false === $this->ignoreFiles->isIgnored($file)) {
56+
$processBuilder = new ProcessBuilder(
57+
array(
58+
'php',
59+
'bin/phpmd',
60+
$file,
61+
'text',
62+
'PmdRules.xml',
63+
'--minimumpriority',
64+
1,
65+
)
66+
);
67+
$process = $processBuilder->getProcess();
68+
$process->run();
5069

51-
if (false === $process->isSuccessful()) {
52-
$errors[] = $process->getOutput();
70+
if (false === $process->isSuccessful()) {
71+
$errors[] = $process->getOutput();
72+
}
5373
}
5474
}
5575

0 commit comments

Comments
 (0)