Skip to content

Commit 1f1c6e1

Browse files
committed
Added PHP-CS-Fixer to build
1 parent 08ce05a commit 1f1c6e1

File tree

6 files changed

+22
-15
lines changed

6 files changed

+22
-15
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/tests export-ignore
22
.gitattributes export-ignore
33
.gitignore export-ignore
4+
.php_cs export-ignore
45
.travis.yml export-ignore
56
phpunit.xml export-ignore

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
/vendor
2-
composer.lock
2+
.php_cs.cache

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ language: php
22

33
sudo: false
44

5+
cache:
6+
directory:
7+
- $HOME/.composer/cache
8+
59
php:
610
- 7.0
711
- 7.1
812

913
install:
10-
- composer self-update
1114
- composer install --prefer-dist
1215

1316
script:
1417
- phpunit --coverage-text
18+
- vendor/bin/php-cs-fixer --diff --dry-run --verbose fix
1519

1620
notifications:
1721
email: false

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
"SlamTest\\ErrorHandler\\": "tests/"
2121
}
2222
},
23-
"require" : {
24-
"php" : "^7.0"
23+
"require": {
24+
"php": "^7.0"
2525
},
2626
"require-dev": {
27+
"slam/php-cs-fixer-extensions": "^1.0",
2728
"slam/php-debug-r": "^1.0.2"
2829
}
2930
}

lib/ErrorHandler.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function setAutoExit(bool $autoExit)
5050
$this->autoExit = $autoExit;
5151
}
5252

53-
public function autoExit() : bool
53+
public function autoExit(): bool
5454
{
5555
return $this->autoExit;
5656
}
@@ -60,7 +60,7 @@ public function setCli(bool $cli)
6060
$this->cli = $cli;
6161
}
6262

63-
public function isCli() : bool
63+
public function isCli(): bool
6464
{
6565
if ($this->cli === null) {
6666
$this->setCli(PHP_SAPI === 'cli');
@@ -115,7 +115,7 @@ public function setLogErrors(bool $logErrors)
115115
$this->logErrors = $logErrors;
116116
}
117117

118-
public function logErrors() : bool
118+
public function logErrors(): bool
119119
{
120120
if ($this->logErrors === null) {
121121
$this->setLogErrors(
@@ -132,7 +132,7 @@ public function setLogVariables(bool $logVariables)
132132
$this->logVariables = $logVariables;
133133
}
134134

135-
public function logVariables() : bool
135+
public function logVariables(): bool
136136
{
137137
return $this->logVariables;
138138
}
@@ -176,9 +176,9 @@ public function exceptionHandler(\Throwable $exception)
176176
$line = $lines[$i];
177177

178178
if (isset($line[$width])) {
179-
$lines[$i] = substr($line, 0, $width);
179+
$lines[$i] = mb_substr($line, 0, $width);
180180
if (isset($line[0]) and $line[0] !== '#') {
181-
array_splice($lines, $i + 1, 0, ' ' . substr($line, $width));
181+
array_splice($lines, $i + 1, 0, ' ' . mb_substr($line, $width));
182182
}
183183
}
184184

@@ -188,7 +188,7 @@ public function exceptionHandler(\Throwable $exception)
188188
$this->outputError(PHP_EOL);
189189
$this->outputError(sprintf('<error> %s </error>', str_repeat(' ', $width)));
190190
foreach ($lines as $line) {
191-
$this->outputError(sprintf('<error> %s%s </error>', $line, str_repeat(' ', max(0, $width - strlen($line)))));
191+
$this->outputError(sprintf('<error> %s%s </error>', $line, str_repeat(' ', max(0, $width - mb_strlen($line)))));
192192
}
193193
$this->outputError(sprintf('<error> %s </error>', str_repeat(' ', $width)));
194194
$this->outputError(PHP_EOL);
@@ -356,7 +356,7 @@ private function getExceptionCode(\Throwable $exception)
356356
return $code;
357357
}
358358

359-
private function purgeTrace(string $trace) : string
359+
private function purgeTrace(string $trace): string
360360
{
361361
return defined('ROOT_PATH') ? str_replace(ROOT_PATH, '.', $trace) : $trace;
362362
}

tests/ErrorHandlerTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
namespace SlamTest\ErrorHandler;
66

77
use ErrorException;
8-
use Slam\ErrorHandler\ErrorHandler;
98
use PHPUnit\Framework\TestCase;
9+
use Slam\ErrorHandler\ErrorHandler;
1010

1111
final class ErrorHandlerTest extends TestCase
1212
{
@@ -42,7 +42,8 @@ protected function tearDown()
4242

4343
public function testDefaultConfiguration()
4444
{
45-
$errorHandler = new ErrorHandler(function(){});
45+
$errorHandler = new ErrorHandler(function () {
46+
});
4647

4748
$this->assertTrue($errorHandler->isCli());
4849
$this->assertTrue($errorHandler->autoExit());
@@ -198,7 +199,7 @@ public function testCanHideVariablesFromEmail()
198199
public function testErroriNellInvioDellaMailVengonoComunqueLoggati()
199200
{
200201
$mailError = uniqid('mail_not_sent_');
201-
$mailCallback = function ($body, $text) use ($mailError){
202+
$mailCallback = function ($body, $text) use ($mailError) {
202203
throw new ErrorException($mailError, E_USER_ERROR);
203204
};
204205
$errorHandler = new ErrorHandler($mailCallback);

0 commit comments

Comments
 (0)