Permalink
Browse files

used PHP 7.1 features

  • Loading branch information...
dg committed Mar 20, 2018
1 parent e636600 commit dda08f91ae5c4d2912e8ba662270ee2b9212d40f
@@ -82,7 +82,7 @@ public static function save()
throw new \LogicException('Code coverage collector has not been started.');
}
list($positive, $negative) = call_user_func([__CLASS__, self::$collector]);
[$positive, $negative] = [__CLASS__, self::$collector]();
flock(self::$file, LOCK_EX);
fseek(self::$file, 0);
@@ -13,7 +13,7 @@
*/
abstract class AbstractGenerator
{
const
protected const
CODE_DEAD = -2,
CODE_UNTESTED = -1,
CODE_TESTED = 1;
@@ -164,7 +164,7 @@ private function calculateClassMetrics(\stdClass $info, array $coverageData = nu
];
foreach ($info->methods as $name => $methodInfo) {
list($lineCount, $coveredLineCount) = $this->analyzeMethod($methodInfo, $coverageData);
[$lineCount, $coveredLineCount] = $this->analyzeMethod($methodInfo, $coverageData);
$stats->statementCount += $lineCount;
@@ -160,10 +160,7 @@
$prevClass = null;
$closeTag = $buffer = '';
for ($i = 1; $i < $lineCount; $i++) {
$class = isset($info->lines[$i]) && isset($classes[$info->lines[$i]])
? $classes[$info->lines[$i]]
: '';
$class = $classes[$info->lines[$i]] ?? '';
if ($class !== $prevClass) {
echo rtrim($buffer) . $closeTag;
$buffer = '';
@@ -118,7 +118,7 @@ public function parse($code)
$function = (object) [
'start' => $line,
'end' => null,
'visibility' => isset($visibility) ? $visibility : 'public',
'visibility' => $visibility ?? 'public',
];
} else {
@@ -171,7 +171,7 @@ private static function fetch(&$tokens, $take)
{
$res = null;
while ($token = current($tokens)) {
list($token, $s) = is_array($token) ? $token : [$token, $token];
[$token, $s] = is_array($token) ? $token : [$token, $token];
if (in_array($token, (array) $take, true)) {
$res .= $s;
} elseif (!in_array($token, [T_DOC_COMMENT, T_WHITESPACE, T_COMMENT], true)) {
@@ -14,7 +14,7 @@
class Assert
{
/** used by equal() for comparing floats */
const EPSILON = 1e-10;
private const EPSILON = 1e-10;
/** used by match(); in values, each $ followed by number is backreference */
public static $patterns = [
@@ -266,7 +266,7 @@ public static function type($type, $value, $description = null)
} elseif (in_array($type, ['array', 'bool', 'callable', 'float',
'int', 'integer', 'null', 'object', 'resource', 'scalar', 'string', ], true)
) {
if (!call_user_func("is_$type", $value)) {
if (!("is_$type")($value)) {
self::fail(self::describe(gettype($value) . " should be $type", $description));
}
@@ -290,7 +290,7 @@ public static function exception(callable $function, $class, $message = null, $c
self::$counter++;
$e = null;
try {
call_user_func($function);
$function();
} catch (\Throwable $e) {
}
if ($e === null) {
@@ -352,7 +352,7 @@ public static function error(callable $function, $expectedType, $expectedMessage
}
$errorStr = Helpers::errorTypeToString($severity) . ($message ? " ($message)" : '');
list($expectedType, $expectedMessage, $expectedTypeStr) = array_shift($expected);
[$expectedType, $expectedMessage, $expectedTypeStr] = array_shift($expected);
if ($expectedType === null) {
self::fail("Generated more errors than expected: $errorStr was generated in file $file on line $line");
@@ -366,7 +366,7 @@ public static function error(callable $function, $expectedType, $expectedMessage
reset($expected);
try {
call_user_func($function);
$function();
restore_error_handler();
} catch (\Exception $e) {
restore_error_handler();
@@ -421,7 +421,7 @@ public static function match($pattern, $actual, $description = null)
self::fail(self::describe('%1 should match %2', $description), $actual, $pattern);
} elseif (!self::isMatching($pattern, $actual)) {
list($pattern, $actual) = self::expandMatchingPatterns($pattern, $actual);
[$pattern, $actual] = self::expandMatchingPatterns($pattern, $actual);
self::fail(self::describe('%1 should match %2', $description), $actual, $pattern);
}
}
@@ -442,7 +442,7 @@ public static function matchFile($file, $actual, $description = null)
self::fail(self::describe('%1 should match %2', $description), $actual, $pattern);
} elseif (!self::isMatching($pattern, $actual)) {
list($pattern, $actual) = self::expandMatchingPatterns($pattern, $actual);
[$pattern, $actual] = self::expandMatchingPatterns($pattern, $actual);
self::fail(self::describe('%1 should match %2', $description), $actual, $pattern);
}
}
@@ -456,7 +456,7 @@ public static function fail($message, $actual = null, $expected = null, $previou
{
$e = new AssertException($message, $expected, $actual, $previous);
if (self::$onFailure) {
call_user_func(self::$onFailure, $e);
(self::$onFailure)($e);
} else {
throw $e;
}
@@ -26,9 +26,9 @@ public static function load($file, $query = '')
}
if (pathinfo($file, PATHINFO_EXTENSION) === 'php') {
$data = call_user_func(function () {
$data = (function () {
return require func_get_arg(0);
}, realpath($file));
})(realpath($file));
if ($data instanceof \Traversable) {
$data = iterator_to_array($data);
@@ -66,8 +66,8 @@ public static function testQuery($input, $query)
static $replaces = ['' => '=', '=>' => '>=', '=<' => '<='];
$tokens = preg_split('#\s+#', $input);
preg_match_all('#\s*,?\s*(<=|=<|<|==|=|!=|<>|>=|=>|>)?\s*([^\s,]+)#A', $query, $queryParts, PREG_SET_ORDER);
foreach ($queryParts as list(, $operator, $operand)) {
$operator = isset($replaces[$operator]) ? $replaces[$operator] : $operator;
foreach ($queryParts as [, $operator, $operand]) {
$operator = $replaces[$operator] ?? $operator;
$token = (string) array_shift($tokens);
$res = preg_match('#^[0-9.]+\z#', $token)
? version_compare($token, $operand, $operator)
@@ -14,16 +14,16 @@
class Environment
{
/** Should Tester use console colors? */
const COLORS = 'NETTE_TESTER_COLORS';
public const COLORS = 'NETTE_TESTER_COLORS';
/** Test is run by Runner */
const RUNNER = 'NETTE_TESTER_RUNNER';
public const RUNNER = 'NETTE_TESTER_RUNNER';
/** Code coverage file */
const COVERAGE = 'NETTE_TESTER_COVERAGE';
public const COVERAGE = 'NETTE_TESTER_COVERAGE';
/** Thread number when run tests in multi threads */
const THREAD = 'NETTE_TESTER_THREAD';
public const THREAD = 'NETTE_TESTER_THREAD';
/** @var bool used for debugging Tester itself */
public static $debugMode = true;
@@ -200,15 +200,15 @@ public static function bypassFinals()
public static function loadData()
{
if (isset($_SERVER['argv']) && ($tmp = preg_filter('#--dataprovider=(.*)#Ai', '$1', $_SERVER['argv']))) {
list($query, $file) = explode('|', reset($tmp), 2);
[$query, $file] = explode('|', reset($tmp), 2);
} else {
$annotations = self::getTestAnnotations();
if (!isset($annotations['dataprovider'])) {
throw new \Exception('Missing annotation @dataProvider.');
}
$provider = (array) $annotations['dataprovider'];
list($file, $query) = DataProvider::parseAnnotation($provider[0], $annotations['file']);
[$file, $query] = DataProvider::parseAnnotation($provider[0], $annotations['file']);
}
$data = DataProvider::load($file, $query);
return reset($data);
@@ -13,7 +13,7 @@
*/
class FileMock
{
const PROTOCOL = 'mock';
private const PROTOCOL = 'mock';
/** @var string[] */
public static $files = [];
@@ -13,7 +13,7 @@
*/
class FileMutator
{
const PROTOCOL = 'file';
private const PROTOCOL = 'file';
/** @var resource|null */
public $context;
@@ -133,7 +133,7 @@ public function stream_open($path, $mode, $options, &$openedPath)
return false;
} else {
foreach (self::$mutators as $mutator) {
$content = call_user_func($mutator, $content);
$content = $mutator($content);
}
$this->handle = tmpfile();
$this->native('fwrite', $this->handle, $content);
@@ -208,7 +208,7 @@ public function url_stat($path, $flags)
private function native($func)
{
stream_wrapper_restore(self::PROTOCOL);
$res = call_user_func_array($func, array_slice(func_get_args(), 1));
$res = $func(...array_slice(func_get_args(), 1));
stream_wrapper_unregister(self::PROTOCOL);
stream_wrapper_register(self::PROTOCOL, __CLASS__);
return $res;
@@ -14,7 +14,7 @@
class TestCase
{
/** @internal */
const
public const
LIST_METHODS = 'nette-tester-list-methods',
METHOD_PATTERN = '#^test[A-Z0-9_]#';
@@ -121,7 +121,7 @@ public function runTest($method, array $args = null)
$this->silentTearDown();
}
return $this->prevErrorHandler ? call_user_func_array($this->prevErrorHandler, func_get_args()) : false;
return $this->prevErrorHandler ? ($this->prevErrorHandler)(...func_get_args()) : false;
});
}
@@ -131,16 +131,17 @@ public function runTest($method, array $args = null)
$this->setUp();
$this->handleErrors = true;
$params = array_values($params);
try {
if ($info['throws']) {
$e = Assert::error(function () use ($method, $params) {
call_user_func_array([$this, $method->getName()], $params);
[$this, $method->getName()](...$params);
}, ...$throws);
if ($e instanceof AssertException) {
throw $e;
}
} else {
call_user_func_array([$this, $method->getName()], $params);
[$this, $method->getName()](...$params);
}
} catch (\Exception $e) {
$this->handleErrors = false;
@@ -167,7 +168,7 @@ protected function getData($provider)
return $this->$provider();
} else {
$rc = new \ReflectionClass($this);
list($file, $query) = DataProvider::parseAnnotation($provider, $rc->getFileName());
[$file, $query] = DataProvider::parseAnnotation($provider, $rc->getFileName());
return DataProvider::load($file, $query);
}
}
@@ -217,9 +217,9 @@ private function createRunner()
}
if ($this->options['--setup']) {
call_user_func(function () use ($runner) {
(function () use ($runner) {
require func_get_arg(0);
}, $this->options['--setup']);
})($this->options['--setup']);
}
return $runner;
}
@@ -13,7 +13,7 @@
*/
class CommandLine
{
const
public const
ARGUMENT = 'argument',
OPTIONAL = 'optional',
REPEATABLE = 'repeatable',
@@ -47,13 +47,13 @@ public function __construct($help, array $defaults = [])
}
$name = end($m[1]);
$opts = isset($this->options[$name]) ? $this->options[$name] : [];
$opts = $this->options[$name] ?? [];
$this->options[$name] = $opts + [
self::ARGUMENT => (bool) end($m[2]),
self::OPTIONAL => isset($line[2]) || (substr(end($m[2]), 0, 1) === '[') || isset($opts[self::VALUE]),
self::REPEATABLE => (bool) end($m[3]),
self::ENUM => count($enums = explode('|', trim(end($m[2]), '<[]>'))) > 1 ? $enums : null,
self::VALUE => isset($line[2]) ? $line[2] : null,
self::VALUE => $line[2] ?? null,
];
if ($name !== $m[1][0]) {
$this->aliases[$m[1][0]] = $name;
@@ -93,7 +93,7 @@ public function parse(array $args = null)
continue;
}
list($name, $arg) = strpos($arg, '=') ? explode('=', $arg, 2) : [$arg, true];
[$name, $arg] = strpos($arg, '=') ? explode('=', $arg, 2) : [$arg, true];
if (isset($this->aliases[$name])) {
$name = $this->aliases[$name];
@@ -15,17 +15,17 @@
*/
class Job
{
const
public const
CODE_NONE = -1,
CODE_OK = 0,
CODE_SKIP = 177,
CODE_FAIL = 178,
CODE_ERROR = 255;
/** waiting time between process activity check in microseconds */
const RUN_USLEEP = 10000;
public const RUN_USLEEP = 10000;
const
public const
RUN_ASYNC = 1,
RUN_COLLECT_ERRORS = 2;
@@ -128,7 +128,7 @@ public function run($flags = 0)
putenv($name);
}
list($stdin, $this->stdout, $stderr) = $pipes;
[$stdin, $this->stdout, $stderr] = $pipes;
fclose($stdin);
if ($flags & self::RUN_COLLECT_ERRORS) {
$this->stderr = $stderr;
@@ -176,7 +176,7 @@ public function isRunning()
$this->exitCode = $code === self::CODE_NONE ? $status['exitcode'] : $code;
if ($this->interpreter->isCgi() && count($tmp = explode("\r\n\r\n", $this->test->stdout, 2)) >= 2) {
list($headers, $this->test->stdout) = $tmp;
[$headers, $this->test->stdout] = $tmp;
foreach (explode("\r\n", $headers) as $header) {
$pos = strpos($header, ':');
if ($pos !== false) {
@@ -13,7 +13,7 @@
*/
class Test
{
const
public const
PREPARED = 0,
FAILED = 1,
PASSED = 2,
Oops, something went wrong.

0 comments on commit dda08f9

Please sign in to comment.