Skip to content

Commit 5734db3

Browse files
committed
Add ignore files library and testing.
1 parent a1ebee5 commit 5734db3

File tree

15 files changed

+110
-39
lines changed

15 files changed

+110
-39
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
"symfony/config": "~3.0",
3535
"symfony/yaml": "~3.0",
3636
"fiunchinho/phpunit-randomizer": "~2.0",
37-
"seld/jsonlint": "1.3.*"
37+
"seld/jsonlint": "1.3.*",
38+
"bruli/ignore-files": "dev-master"
3839
},
3940
"require-dev": {
4041
"composer/composer": "^1.0@dev"

composer.lock

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

config/services.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@
4444
<argument type="service" id="pre.commit.config"/>
4545
<argument type="service" id="php.cs.fixer.handler"/>
4646
</service>
47+
<service id="ignore.files" class="IgnoreFiles\IgnoreFiles">
48+
</service>
4749
<service id="php.cs.fixer.handler" class="PhpGitHooks\Infrastructure\PhpCsFixer\PhpCsFixerHandler">
4850
<argument type="service" id="output.handler" />
51+
<argument type="service" id="ignore.files"/>
4952
</service>
5053
<service id="check.code.style.code.sniffer.pre.commit.executor" class="PhpGitHooks\Application\CodeSniffer\CheckCodeStyleCodeSnifferPreCommitExecutor">
5154
<argument type="service" id="pre.commit.config"/>
@@ -100,5 +103,8 @@
100103
<service id="json.lint.handler" class="PhpGitHooks\Infrastructure\JsonLint\JsonLintHandler">
101104
<argument type="service" id="output.handler" />
102105
</service>
106+
<service id="file.reader" class="IgnoreFiles\Infrastructure\Disk\FileReader">
107+
<argument type="string">ignore_files</argument>
108+
</service>
103109
</services>
104110
</container>

src/PhpGitHooks/Command/OutputHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function getTitle()
3131
$text = $this->title;
3232
$length = $this->getLength();
3333

34-
for ($i = 0; $i < $length; $i++) {
34+
for ($i = 0; $i < $length; ++$i) {
3535
$text .= self::TITLE_SEPARATOR;
3636
}
3737

src/PhpGitHooks/Infrastructure/Composer/InMemoryIOInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public function write($messages, $newline = true)
8181
*
8282
* @param string|array $messages The message as an array of lines or a single string
8383
* @param bool $newline Whether to add a newline or not
84-
* @param integer $size The size of line
84+
* @param int $size The size of line
8585
*/
8686
public function overwrite($messages, $newline = true, $size = null)
8787
{
@@ -125,7 +125,7 @@ public function askConfirmation($question, $default = true)
125125
*
126126
* @param string|array $question The question to ask
127127
* @param callback $validator A PHP callback
128-
* @param bool|integer $attempts Max number of times to ask before giving
128+
* @param bool|int $attempts Max number of times to ask before giving
129129
* up (false by default, which means infinite)
130130
* @param string $default The default answer if none is given by the user
131131
*
@@ -162,7 +162,7 @@ public function getAuthentications()
162162
*
163163
* @param string $repositoryName The unique name of repository
164164
*
165-
* @return boolean
165+
* @return bool
166166
*/
167167
public function hasAuthentication($repositoryName)
168168
{
@@ -214,7 +214,7 @@ public function writeError($messages, $newline = true)
214214
*
215215
* @param string|array $messages The message as an array of lines or a single string
216216
* @param bool $newline Whether to add a newline or not
217-
* @param integer $size The size of line
217+
* @param int $size The size of line
218218
*/
219219
public function overwriteError($messages, $newline = true, $size = null)
220220
{

src/PhpGitHooks/Infrastructure/Config/InMemoryCheckConfigFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function getFile()
2727
}
2828

2929
/**
30-
* @param boolean $exists
30+
* @param bool $exists
3131
*/
3232
public function setExists($exists)
3333
{

src/PhpGitHooks/Infrastructure/Git/HooksFileCopier.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ class HooksFileCopier
1313

1414
/**
1515
* @param string $hook
16-
* @param bool $enabled
16+
* @param bool $enabled
1717
*/
1818
public function copy($hook, $enabled)
1919
{
2020
if (true === $enabled) {
21-
if (false === file_exists(self::GIT_HOOKS_PATH . $hook)) {
21+
if (false === file_exists(self::GIT_HOOKS_PATH.$hook)) {
2222
$copy = new Process(
23-
'cp ' . __DIR__ . '/../../../../hooks/' . $hook . ' ' . self::GIT_HOOKS_PATH . $hook
23+
'cp '.__DIR__.'/../../../../hooks/'.$hook.' '.self::GIT_HOOKS_PATH.$hook
2424
);
2525
$copy->run();
2626

27-
$permissions = new Process('chmod 775 ' . self::GIT_HOOKS_PATH . $hook);
27+
$permissions = new Process('chmod 775 '.self::GIT_HOOKS_PATH.$hook);
2828
$permissions->run();
2929
}
3030
}

src/PhpGitHooks/Infrastructure/Git/InMemoryMergeValidator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class InMemoryMergeValidator implements MergeValidatorInterface
1111
private $merge;
1212

1313
/**
14-
* @param boolean $merge
14+
* @param bool $merge
1515
*/
1616
public function setMerge($merge)
1717
{
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<?php
2+
23
namespace PhpGitHooks\Infrastructure\PhpCsFixer;
34

45
/**
56
* Class PhpCsFixerException.
67
*/
78
class PhpCsFixerException extends \Exception
89
{
9-
protected $message = "There are some PhpCsFixer styling errors!.";
10+
protected $message = 'There are some PhpCsFixer styling errors!.';
1011
}

src/PhpGitHooks/Infrastructure/PhpCsFixer/PhpCsFixerHandler.php

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

33
namespace PhpGitHooks\Infrastructure\PhpCsFixer;
44

5+
use IgnoreFiles\IgnoreFiles;
56
use PhpGitHooks\Application\Message\MessageConfigData;
7+
use PhpGitHooks\Command\OutputHandlerInterface;
68
use PhpGitHooks\Infrastructure\Common\InteractiveToolInterface;
79
use PhpGitHooks\Infrastructure\Common\ToolHandler;
810
use Symfony\Component\Process\ProcessBuilder;
@@ -15,6 +17,22 @@ class PhpCsFixerHandler extends ToolHandler implements InteractiveToolInterface,
1517
private $filesToAnalyze;
1618
/** @var array */
1719
private $levels = [];
20+
/**
21+
* @var IgnoreFiles
22+
*/
23+
private $ignoreFiles;
24+
25+
/**
26+
* PhpCsFixerHandler constructor.
27+
*
28+
* @param OutputHandlerInterface $outputHandler
29+
* @param IgnoreFiles $ignoreFiles
30+
*/
31+
public function __construct(OutputHandlerInterface $outputHandler, IgnoreFiles $ignoreFiles)
32+
{
33+
parent::__construct($outputHandler);
34+
$this->ignoreFiles = $ignoreFiles;
35+
}
1836

1937
/**
2038
* @throws PhpCsFixerException
@@ -29,28 +47,30 @@ public function run(array $messages)
2947
$errors = array();
3048

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

34-
if (!$srcFile) {
35-
continue;
36-
}
53+
if (!$srcFile) {
54+
continue;
55+
}
3756

38-
$processBuilder = new ProcessBuilder(
39-
array(
40-
'php',
41-
'bin/php-cs-fixer',
42-
'--dry-run',
43-
'fix',
44-
$file,
45-
'--level='.$level,
46-
)
47-
);
57+
$processBuilder = new ProcessBuilder(
58+
array(
59+
'php',
60+
'bin/php-cs-fixer',
61+
'--dry-run',
62+
'fix',
63+
$file,
64+
'--level='.$level,
65+
)
66+
);
4867

49-
$phpCsFixer = $processBuilder->getProcess();
50-
$phpCsFixer->run();
68+
$phpCsFixer = $processBuilder->getProcess();
69+
$phpCsFixer->run();
5170

52-
if (false === $phpCsFixer->isSuccessful()) {
53-
$errors[] = $phpCsFixer->getOutput();
71+
if (false === $phpCsFixer->isSuccessful()) {
72+
$errors[] = $phpCsFixer->getOutput();
73+
}
5474
}
5575
}
5676

0 commit comments

Comments
 (0)