Skip to content

Commit

Permalink
chore(cs) Update to latest PHPCSFixer API.
Browse files Browse the repository at this point in the history
  • Loading branch information
Hywan authored and jubianchi committed Mar 2, 2018
1 parent d3b3da8 commit b25d916
Show file tree
Hide file tree
Showing 94 changed files with 2,028 additions and 1,747 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.php_cs.cache
composer.lock
vendor/
48 changes: 23 additions & 25 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<?php

use Symfony\CS;
use PhpCsFixer as CS;

$finder = CS\Finder::create()
->files()
->name(__FILE__)
->name('*.php')
->name('*.php.dist')
->in(__DIR__)
;

return
CS\Config::create()
->level(CS\FixerInterface::PSR2_LEVEL)
->fixers([
'blankline_after_open_tag',
'concat_with_spaces',
'join_function',
'native_function_casing',
'no_blank_lines_after_class_opening',
'ordered_use',
'phpdoc_no_access',
'remove_leading_slash_use',
'remove_leading_slash_uses',
'self_accessor',
'short_array_syntax',
'spaces_cast',
'unused_use',
'whitespacy_lines'
->setRules([
'@PSR2' => true,
'array_syntax' => ['syntax' => 'short'],
'blank_line_after_opening_tag' => true,
'concat_space' => ['spacing' => 'one'],
'native_function_casing' => true,
'no_blank_lines_after_class_opening' => true,
'no_unused_imports' => true,
'no_unused_imports' => true,
'no_whitespace_in_blank_line' => true,
'ordered_imports' => true,
'phpdoc_no_access' => true,
])
->finder(
CS\Finder::create()
->files()
->name(__FILE__)
->name('*.php')
->name('*.php.dist')
->in(__DIR__)
);
->setFinder($finder)
;
3 changes: 2 additions & 1 deletion classes/report/fields/runner/coverage/html.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ public function __toString()
if ($methodCoverageValue === null) {
$methodCoverageUnavailableTemplates->build(['methodName' => $methodName]);
} else {
$methodCoverageAvailableTemplates->build([
$methodCoverageAvailableTemplates->build(
[
'methodName' => $methodName,
'methodCoverageValue' => round($methodCoverageValue * 100, 2)
]
Expand Down
7 changes: 4 additions & 3 deletions classes/report/fields/runner/duration/phing.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ public function __toString()
sprintf(
$this->locale->_('%1$s: %2$s.'),
$this->titleColorizer->colorize($this->locale->_('Running duration')),
$this->durationColorizer->colorize($this->value === null ? $this->locale->_('unknown') : sprintf($this->locale->__('%4.2f second', '%4.2f seconds', $this->value), $this->value)
)
);
$this->durationColorizer->colorize(
$this->value === null ? $this->locale->_('unknown') : sprintf($this->locale->__('%4.2f second', '%4.2f seconds', $this->value), $this->value)
)
);
}
}
3 changes: 2 additions & 1 deletion classes/report/fields/runner/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ abstract class event extends report\fields\event
{
public function __construct()
{
parent::__construct([
parent::__construct(
[
runner::runStart,
test::fail,
test::error,
Expand Down
1 change: 0 additions & 1 deletion classes/report/fields/runner/tests/coverage/phing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace mageekguy\atoum\report\fields\runner\tests\coverage;

use mageekguy\atoum\locale;
use mageekguy\atoum\report;

class phing extends report\fields\runner\tests\coverage\cli
Expand Down
1 change: 0 additions & 1 deletion classes/report/fields/runner/tests/duration/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use mageekguy\atoum\cli\colorizer;
use mageekguy\atoum\cli\prompt;
use mageekguy\atoum\locale;
use mageekguy\atoum\report;

class cli extends report\fields\runner\tests\duration
Expand Down
1 change: 0 additions & 1 deletion classes/report/fields/runner/tests/memory/cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use mageekguy\atoum\cli\colorizer;
use mageekguy\atoum\cli\prompt;
use mageekguy\atoum\locale;
use mageekguy\atoum\report;

class cli extends report\fields\runner\tests\memory
Expand Down
2 changes: 0 additions & 2 deletions classes/report/fields/runner/tests/memory/phing.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace mageekguy\atoum\report\fields\runner\tests\memory;

use mageekguy\atoum\cli\prompt;
use mageekguy\atoum\locale;
use mageekguy\atoum\report;

class phing extends report\fields\runner\tests\memory\cli
Expand Down
3 changes: 2 additions & 1 deletion classes/report/fields/test/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ abstract class event extends report\fields\event
{
public function __construct()
{
parent::__construct([
parent::__construct(
[
test::runStart,
test::fail,
test::error,
Expand Down
3 changes: 2 additions & 1 deletion classes/report/fields/test/event/tap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class tap extends report\fields\event

public function __construct()
{
parent::__construct([
parent::__construct(
[
runner::runStart,
test::fail,
test::error,
Expand Down
10 changes: 6 additions & 4 deletions classes/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,13 @@ protected function findTestClasses($testBaseClass = null)
$reflectionClassFactory = $this->reflectionClassFactory;
$testBaseClass = $testBaseClass ?: __NAMESPACE__ . '\test';

return array_filter($this->adapter->get_declared_classes(), function ($class) use ($reflectionClassFactory, $testBaseClass) {
$class = $reflectionClassFactory($class);
return array_filter(
$this->adapter->get_declared_classes(),
function ($class) use ($reflectionClassFactory, $testBaseClass) {
$class = $reflectionClassFactory($class);

return ($class->isSubClassOf($testBaseClass) === true && $class->isAbstract() === false);
}
return ($class->isSubClassOf($testBaseClass) === true && $class->isAbstract() === false);
}
);
}

Expand Down
18 changes: 10 additions & 8 deletions classes/score.php
Original file line number Diff line number Diff line change
Expand Up @@ -471,15 +471,17 @@ private static function cleanAssertion(array $assertion)

private static function sort(array $array)
{
usort($array, function ($a, $b) {
if ($a['file'] !== $b['file']) {
return strcmp($a['file'], $b['file']);
} elseif ($a['line'] === $b['line']) {
return 0;
} else {
return ($a['line'] < $b['line'] ? -1 : 1);
usort(
$array,
function ($a, $b) {
if ($a['file'] !== $b['file']) {
return strcmp($a['file'], $b['file']);
} elseif ($a['line'] === $b['line']) {
return 0;
} else {
return ($a['line'] < $b['line'] ? -1 : 1);
}
}
}
);

return $array;
Expand Down
3 changes: 2 additions & 1 deletion classes/score/coverage.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ public function getReflectionClassFactory()

public function serialize()
{
return serialize([
return serialize(
[
$this->classes,
$this->methods,
$this->paths,
Expand Down
8 changes: 5 additions & 3 deletions classes/script/arguments/parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ public function parse(atoum\script $script, array $array = [])

$values = $this->values;

uksort($values, function ($arg1, $arg2) use ($priorities) {
switch (true) {
uksort(
$values,
function ($arg1, $arg2) use ($priorities) {
switch (true) {
case isset($priorities[$arg1]) === false && isset($priorities[$arg2]) === false:
return 0;
case isset($priorities[$arg1]) === false && isset($priorities[$arg2]) === true:
Expand All @@ -87,7 +89,7 @@ public function parse(atoum\script $script, array $array = [])
default:
return ($priorities[$arg1] > $priorities[$arg2] ? -1 : ($priorities[$arg1] == $priorities[$arg2] ? 0 : 1));
}
}
}
);

foreach ($values as $argument => $value) {
Expand Down
65 changes: 34 additions & 31 deletions classes/scripts/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,38 +685,40 @@ public static function enableAutorun($name)
$autorunner = & static::$autorunner;
$calledClass = get_called_class();

register_shutdown_function(function () use (& $autorunner, $calledClass) {
if ($autorunner instanceof $calledClass) {
set_error_handler(function ($error, $message, $file, $line) use ($autorunner) {
$errorReporting = error_reporting();
register_shutdown_function(
function () use (& $autorunner, $calledClass) {
if ($autorunner instanceof $calledClass) {
set_error_handler(function ($error, $message, $file, $line) use ($autorunner) {
$errorReporting = error_reporting();

if ($errorReporting !== 0 && $errorReporting & $error) {
$autorunner->writeError($message . ' in ' . $file . ' at line ' . $line, $error);
if ($errorReporting !== 0 && $errorReporting & $error) {
$autorunner->writeError($message . ' in ' . $file . ' at line ' . $line, $error);

exit(3);
}
});
exit(3);
}
});

try {
$score = $autorunner->run()->getRunner()->getScore();
$isSuccess = $score->getFailNumber() <= 0 && $score->getErrorNumber() <= 0 && $score->getExceptionNumber() <= 0 && $score->getUncompletedMethodNumber() <= 0;
try {
$score = $autorunner->run()->getRunner()->getScore();
$isSuccess = $score->getFailNumber() <= 0 && $score->getErrorNumber() <= 0 && $score->getExceptionNumber() <= 0 && $score->getUncompletedMethodNumber() <= 0;

if ($autorunner->shouldFailIfVoidMethods() && $score->getVoidMethodNumber() > 0) {
$isSuccess = false;
}
if ($autorunner->shouldFailIfVoidMethods() && $score->getVoidMethodNumber() > 0) {
$isSuccess = false;
}

if ($autorunner->shouldFailIfSkippedMethods() && $score->getSkippedMethodNumber() > 0) {
$isSuccess = false;
}
if ($autorunner->shouldFailIfSkippedMethods() && $score->getSkippedMethodNumber() > 0) {
$isSuccess = false;
}

exit($isSuccess ? 0 : 1);
} catch (\exception $exception) {
$autorunner->writeError($exception->getMessage());
exit($isSuccess ? 0 : 1);
} catch (\exception $exception) {
$autorunner->writeError($exception->getMessage());

exit(2);
exit(2);
}
}
}
});
);

$autorunIsRegistered = true;
}
Expand Down Expand Up @@ -1187,15 +1189,16 @@ function ($script, $argument, $values) {
)
;

$this->setDefaultArgumentHandler(function ($script, $argument) {
try {
$script->getRunner()->addTest($argument);
} catch (\exception $exception) {
return false;
}
$this->setDefaultArgumentHandler(
function ($script, $argument) {
try {
$script->getRunner()->addTest($argument);
} catch (\exception $exception) {
return false;
}

return true;
}
return true;
}
);

return $this;
Expand Down
Loading

0 comments on commit b25d916

Please sign in to comment.