Skip to content

Commit 5f4a36c

Browse files
committed
Add PSR12 formatting
1 parent 38c6221 commit 5f4a36c

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"require": {},
1818
"require-dev": {
19-
"phpunit/phpunit": "^8"
19+
"phpunit/phpunit": "^8",
20+
"squizlabs/php_codesniffer": "3.*"
2021
}
2122
}

phpcs.xml

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="PSR12">
3+
<description>PSR12</description>
4+
<file>./src</file>
5+
<rule ref="PSR12"/>
6+
</ruleset>

src/Printer.php

+23-9
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,44 @@ protected function printDefectTrace(TestFailure $defect): void
4040
$e = $defect->thrownException();
4141

4242
$errorLines = array_filter(
43-
explode(PHP_EOL, (string)$e),
44-
function($l){ return $l; }
43+
explode(PHP_EOL, (string)$e),
44+
function ($l) {
45+
return $l;
46+
}
4547
);
4648

4749
list($path, $line) = explode(":", end($errorLines));
4850

4951
if (!$path) {
50-
list($path, $line) = $this->getReflectionFromTest($defect->getTestName());
52+
list($path, $line) = $this->getReflectionFromTest(
53+
$defect->getTestName()
54+
);
5155
}
5256

5357
$message = explode(PHP_EOL, $e->getMessage())[0];
5458

55-
$this->write("::{$this->getCurrentType()} file={$this->relativePath($path)},line={$line}::{$message}\n");
59+
$type = $this->getCurrentType();
60+
$file = "file={$this->relativePath($path)}";
61+
$line = "line={$line}";
62+
$this->write("::{$type} $file,$line::{$message}\n");
5663
}
5764

58-
protected function getCurrentType() {
59-
return in_array($this->currentType, ['error', 'failure']) ? 'error' : 'warning';
65+
protected function getCurrentType()
66+
{
67+
if (in_array($this->currentType, ['error', 'failure'])) {
68+
return 'error';
69+
}
70+
71+
return 'warning';
6072
}
6173

62-
protected function relativePath(string $path) {
63-
return str_replace(getcwd().'/', '', $path);
74+
protected function relativePath(string $path)
75+
{
76+
return str_replace(getcwd() . '/', '', $path);
6477
}
6578

66-
protected function getReflectionFromTest(string $name) {
79+
protected function getReflectionFromTest(string $name)
80+
{
6781
list($klass, $method) = explode('::', $name);
6882
$c = new \ReflectionClass($klass);
6983
$m = $c->getMethod($method);

0 commit comments

Comments
 (0)