Skip to content

Commit

Permalink
Updata ignore-files library and apply ignore in handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
bruli committed Feb 27, 2016
1 parent 5734db3 commit 1be64c3
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 34 deletions.
8 changes: 4 additions & 4 deletions composer.lock

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

4 changes: 3 additions & 1 deletion config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,15 @@
</service>
<service id="code.sniffer.handler" class="PhpGitHooks\Infrastructure\CodeSniffer\CodeSnifferHandler">
<argument type="service" id="output.handler" />
<argument type="service" id="ignore.files" />
</service>
<service id="check.php.mess.detection.pre.commit.executor" class="PhpGitHooks\Application\PhpMD\CheckPhpMessDetectionPreCommitExecutor">
<argument type="service" id="pre.commit.config"/>
<argument type="service" id="phpmd.handler"/>
</service>
<service id="phpmd.handler" class="PhpGitHooks\Infrastructure\PhpMD\PhpMDHandler">
<argument type="service" id="output.handler" />
<argument type="service" id="ignore.files" />
</service>
<service id="unit.test.pre.commit.executor" class="PhpGitHooks\Application\PhpUnit\UnitTestPreCommitExecutor">
<argument type="service" id="pre.commit.config"/>
Expand Down Expand Up @@ -104,7 +106,7 @@
<argument type="service" id="output.handler" />
</service>
<service id="file.reader" class="IgnoreFiles\Infrastructure\Disk\FileReader">
<argument type="string">ignore_files</argument>
<argument type="string">"ignore-files"</argument>
</service>
</services>
</container>
38 changes: 29 additions & 9 deletions src/PhpGitHooks/Infrastructure/CodeSniffer/CodeSnifferHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace PhpGitHooks\Infrastructure\CodeSniffer;

use IgnoreFiles\IgnoreFiles;
use PhpGitHooks\Application\Message\MessageConfigData;
use PhpGitHooks\Command\BadJobLogo;
use PhpGitHooks\Command\OutputHandlerInterface;
use PhpGitHooks\Infrastructure\Common\ToolHandler;
use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;
Expand All @@ -19,6 +21,22 @@ class CodeSnifferHandler extends ToolHandler
private $neddle;
/** @var string */
private $standard = 'PSR2';
/**
* @var IgnoreFiles
*/
private $ignoreFiles;

/**
* CodeSnifferHandler constructor.
*
* @param OutputHandlerInterface $outputHandler
* @param IgnoreFiles $ignoreFiles
*/
public function __construct(OutputHandlerInterface $outputHandler, IgnoreFiles $ignoreFiles)
{
parent::__construct($outputHandler);
$this->ignoreFiles = $ignoreFiles;
}

/**
* @param array $messages
Expand All @@ -35,17 +53,19 @@ public function run(array $messages)
continue;
}

$processBuilder = new ProcessBuilder(array('php', 'bin/phpcs', '--standard='.$this->standard, $file));
/** @var Process $phpCs */
$phpCs = $processBuilder->getProcess();
$phpCs->run();
if (false === $this->ignoreFiles->isIgnored($file)) {
$processBuilder = new ProcessBuilder(array('php', 'bin/phpcs', '--standard='.$this->standard, $file));
/** @var Process $phpCs */
$phpCs = $processBuilder->getProcess();
$phpCs->run();

if (false === $phpCs->isSuccessful()) {
$this->outputHandler->setError($phpCs->getOutput());
$this->output->writeln($this->outputHandler->getError());
$this->output->writeln(BadJobLogo::paint($messages[MessageConfigData::KEY_ERROR_MESSAGE]));
if (false === $phpCs->isSuccessful()) {
$this->outputHandler->setError($phpCs->getOutput());
$this->output->writeln($this->outputHandler->getError());
$this->output->writeln(BadJobLogo::paint($messages[MessageConfigData::KEY_ERROR_MESSAGE]));

throw new InvalidCodingStandardException();
throw new InvalidCodingStandardException();
}
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/PhpGitHooks/Infrastructure/PhpCsFixer/PhpCsFixerHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public function run(array $messages)
$errors = array();

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

if (!$srcFile) {
continue;
}
if (!$srcFile) {
continue;
}

if (false === $this->ignoreFiles->isIgnored($file)) {
$processBuilder = new ProcessBuilder(
array(
'php',
Expand Down
50 changes: 35 additions & 15 deletions src/PhpGitHooks/Infrastructure/PhpMD/PhpMDHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace PhpGitHooks\Infrastructure\PhpMD;

use IgnoreFiles\IgnoreFiles;
use PhpGitHooks\Application\Message\MessageConfigData;
use PhpGitHooks\Command\OutputHandlerInterface;
use PhpGitHooks\Infrastructure\Common\RecursiveToolInterface;
use PhpGitHooks\Infrastructure\Common\ToolHandler;
use Symfony\Component\Process\ProcessBuilder;
Expand All @@ -16,6 +18,22 @@ class PhpMDHandler extends ToolHandler implements RecursiveToolInterface
private $files;
/** @var string */
private $needle;
/**
* @var IgnoreFiles
*/
private $ignoreFiles;

/**
* PhpMDHandler constructor.
*
* @param OutputHandlerInterface $outputHandler
* @param IgnoreFiles $ignoreFiles
*/
public function __construct(OutputHandlerInterface $outputHandler, IgnoreFiles $ignoreFiles)
{
parent::__construct($outputHandler);
$this->ignoreFiles = $ignoreFiles;
}

/**
* @param array $messages
Expand All @@ -34,22 +52,24 @@ public function run(array $messages)
continue;
}

$processBuilder = new ProcessBuilder(
array(
'php',
'bin/phpmd',
$file,
'text',
'PmdRules.xml',
'--minimumpriority',
1,
)
);
$process = $processBuilder->getProcess();
$process->run();
if (false === $this->ignoreFiles->isIgnored($file)) {
$processBuilder = new ProcessBuilder(
array(
'php',
'bin/phpmd',
$file,
'text',
'PmdRules.xml',
'--minimumpriority',
1,
)
);
$process = $processBuilder->getProcess();
$process->run();

if (false === $process->isSuccessful()) {
$errors[] = $process->getOutput();
if (false === $process->isSuccessful()) {
$errors[] = $process->getOutput();
}
}
}

Expand Down

0 comments on commit 1be64c3

Please sign in to comment.