Skip to content

Commit 13b231c

Browse files
authored
Merge pull request #3 from olivertappin/hotfix/2
Fixed issue with non-zero exit code after displaying violations
2 parents fff4bcf + 216afd3 commit 13b231c

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ matrix:
1616
- php: nightly
1717

1818
before_script:
19-
- composer update
19+
- composer update --no-interaction
2020

2121
script:
22-
- vendor/bin/phpunit
22+
- vendor/bin/phpunit --stop-on-failure
2323

src/Mapper/PhpcsOutputMapper.php renamed to src/Mapper/PhpcsViolationsMapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace PhpcsDiff\Mapper;
44

5-
class PhpcsOutputMapper implements MapperInterface
5+
class PhpcsViolationsMapper implements MapperInterface
66
{
77
/**
88
* @var array

src/PhpcsDiff.php

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use PhpcsDiff\Filter\Filter;
88
use PhpcsDiff\Filter\Rule\HasMessagesRule;
99
use PhpcsDiff\Filter\Rule\PhpFileRule;
10-
use PhpcsDiff\Mapper\PhpcsOutputMapper;
10+
use PhpcsDiff\Mapper\PhpcsViolationsMapper;
1111

1212
class PhpcsDiff
1313
{
@@ -168,7 +168,7 @@ public function run()
168168
$this->climate->comment('Comparing phpcs output with changes lines from git diff.');
169169
}
170170

171-
$output = (new PhpcsOutputMapper(
171+
$violations = (new PhpcsViolationsMapper(
172172
$changedLinesPerFile,
173173
getcwd()
174174
))->map($files);
@@ -177,14 +177,12 @@ public function run()
177177
$this->climate->comment('Preparing report.');
178178
}
179179

180-
if (empty($output)) {
180+
if (empty($violations)) {
181181
$this->climate->info('No violations to report.');
182182
return;
183183
}
184184

185-
$this->climate->flank(strtoupper('Start of phpcs check'), '#', 10)->br();
186-
$this->climate->out(implode(PHP_EOL, $output));
187-
$this->climate->flank(strtoupper('End of phpcs check'), '#', 11);
185+
$this->outputViolations($violations);
188186
}
189187

190188
/**
@@ -210,6 +208,18 @@ protected function runPhpcs(array $files = [], $ruleset = 'ruleset.xml')
210208
);
211209
}
212210

211+
/**
212+
* @param array $output
213+
*/
214+
protected function outputViolations(array $output)
215+
{
216+
$this->climate->flank(strtoupper('Start of phpcs check'), '#', 10)->br();
217+
$this->climate->out(implode(PHP_EOL, $output));
218+
$this->climate->flank(strtoupper('End of phpcs check'), '#', 11)->br();
219+
220+
$this->error('Violations have been reported.');
221+
}
222+
213223
/**
214224
* Returns a list of files which are within the diff based on the current branch
215225
*

tests/Mapper/PhpcsOutputMapperTest.php renamed to tests/Mapper/PhpcsViolationsMapperTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@
33
namespace PhpcsDiff\Tests\Mapper;
44

55
use PhpcsDiff\Mapper\MapperInterface;
6-
use PhpcsDiff\Mapper\PhpcsOutputMapper;
6+
use PhpcsDiff\Mapper\PhpcsViolationsMapper;
77
use PhpcsDiff\Tests\TestBase;
88

9-
class PhpcsOutputMapperTest extends TestBase
9+
class PhpcsViolationsMapperTest extends TestBase
1010
{
1111
/**
1212
* @covers PhpcsOutputMapper::__construct
1313
*/
1414
public function testMapperInstance()
1515
{
16-
$mapper = new PhpcsOutputMapper([], '');
16+
$mapper = new PhpcsViolationsMapper([], '');
1717

1818
$this->assertInstanceOf(MapperInterface::class, $mapper);
1919
}
@@ -23,7 +23,7 @@ public function testMapperInstance()
2323
*/
2424
public function testEmptyMapper()
2525
{
26-
$mappedData = (new PhpcsOutputMapper([], ''))->map([]);
26+
$mappedData = (new PhpcsViolationsMapper([], ''))->map([]);
2727

2828
$this->assertEmpty($mappedData);
2929
}

0 commit comments

Comments
 (0)