Skip to content

Commit cb5f883

Browse files
committed
coding style
1 parent fe3f765 commit cb5f883

File tree

17 files changed

+88
-50
lines changed

17 files changed

+88
-50
lines changed

src/CodeCoverage/Collector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static function start(string $file, string $engine): void
6161
self::{'start' . $engine}();
6262

6363
register_shutdown_function(function (): void {
64-
register_shutdown_function([__CLASS__, 'save']);
64+
register_shutdown_function([self::class, 'save']);
6565
});
6666
}
6767

src/Framework/Assert.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,12 @@ public static function type($type, $value, string $description = null): void
281281
/**
282282
* Asserts that a function throws exception of given type and its message matches given pattern.
283283
*/
284-
public static function exception(callable $function, string $class, string $message = null, $code = null): ?\Throwable
285-
{
284+
public static function exception(
285+
callable $function,
286+
string $class,
287+
string $message = null,
288+
$code = null
289+
): ?\Throwable {
286290
self::$counter++;
287291
$e = null;
288292
try {

src/Framework/DomQuery.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static function fromHtml(string $html): self
2929
return $m[1] . str_replace('</', '<\/', $m[2]) . $m[3];
3030
}, $html);
3131

32-
$dom = new \DOMDocument();
32+
$dom = new \DOMDocument;
3333
$old = libxml_use_internal_errors(true);
3434
libxml_clear_errors();
3535
$dom->loadHTML($html);
@@ -41,13 +41,13 @@ public static function fromHtml(string $html): self
4141
trigger_error(__METHOD__ . ": $error->message on line $error->line.", E_USER_WARNING);
4242
}
4343
}
44-
return simplexml_import_dom($dom, __CLASS__);
44+
return simplexml_import_dom($dom, self::class);
4545
}
4646

4747

4848
public static function fromXml(string $xml): self
4949
{
50-
return simplexml_load_string($xml, __CLASS__);
50+
return simplexml_load_string($xml, self::class);
5151
}
5252

5353

src/Framework/Dumper.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ public static function toLine($var): string
6262
} elseif (strlen($var) > self::$maxLength) {
6363
$var = substr($var, 0, self::$maxLength) . '...';
6464
}
65-
return preg_match('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', $var) || preg_last_error() ? '"' . strtr($var, $table) . '"' : "'$var'";
65+
return preg_match('#[^\x09\x0A\x0D\x20-\x7E\xA0-\x{10FFFF}]#u', $var) || preg_last_error()
66+
? '"' . strtr($var, $table) . '"'
67+
: "'$var'";
6668

6769
} elseif (is_array($var)) {
6870
$out = '';
@@ -291,11 +293,9 @@ public static function dumpException(\Throwable $e): string
291293
if (((is_string($actual) && is_string($expected)) || (is_array($actual) && is_array($expected)))
292294
&& preg_match('#^(.*)(%\d)(.*)(%\d.*)$#Ds', $message, $m)
293295
) {
294-
if (($delta = strlen($m[1]) - strlen($m[3])) >= 3) {
295-
$message = "$m[1]$m[2]\n" . str_repeat(' ', $delta - 3) . "...$m[3]$m[4]";
296-
} else {
297-
$message = "$m[1]$m[2]$m[3]\n" . str_repeat(' ', strlen($m[1]) - 4) . "... $m[4]";
298-
}
296+
$message = ($delta = strlen($m[1]) - strlen($m[3])) >= 3
297+
? "$m[1]$m[2]\n" . str_repeat(' ', $delta - 3) . "...$m[3]$m[4]"
298+
: "$m[1]$m[2]$m[3]\n" . str_repeat(' ', strlen($m[1]) - 4) . "... $m[4]";
299299
}
300300
$message = strtr($message, [
301301
'%1' => self::color('yellow') . self::toLine($actual) . self::color('white'),

src/Framework/Environment.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,17 +104,20 @@ public static function setupErrors(): void
104104
ini_set('html_errors', '0');
105105
ini_set('log_errors', '0');
106106

107-
set_exception_handler([__CLASS__, 'handleException']);
107+
set_exception_handler([self::class, 'handleException']);
108108

109109
set_error_handler(function (int $severity, string $message, string $file, int $line): ?bool {
110-
if (in_array($severity, [E_RECOVERABLE_ERROR, E_USER_ERROR], true) || ($severity & error_reporting()) === $severity) {
110+
if (
111+
in_array($severity, [E_RECOVERABLE_ERROR, E_USER_ERROR], true)
112+
|| ($severity & error_reporting()) === $severity
113+
) {
111114
self::handleException(new \ErrorException($message, 0, $severity, $file, $line));
112115
}
113116
return false;
114117
});
115118

116119
register_shutdown_function(function (): void {
117-
Assert::$onFailure = [__CLASS__, 'handleException'];
120+
Assert::$onFailure = [self::class, 'handleException'];
118121

119122
$error = error_get_last();
120123
register_shutdown_function(function () use ($error): void {

src/Framework/Expect.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __call(string $method, array $args): self
7373
$this->constraints[] = (object) ['method' => lcfirst($m[1]), 'args' => $args];
7474
return $this;
7575
}
76-
throw new \Error('Call to undefined method ' . __CLASS__ . '::' . $method . '()');
76+
throw new \Error('Call to undefined method ' . self::class . '::' . $method . '()');
7777
}
7878

7979

@@ -107,7 +107,9 @@ public function dump(): string
107107
$res = [];
108108
foreach ($this->constraints as $cstr) {
109109
if ($cstr instanceof \stdClass) {
110-
$args = isset($cstr->args[0]) ? Dumper::toLine($cstr->args[0]) : '';
110+
$args = isset($cstr->args[0])
111+
? Dumper::toLine($cstr->args[0])
112+
: '';
111113
$res[] = "$cstr->method($args)";
112114

113115
} elseif ($cstr instanceof self) {

src/Framework/FileMock.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public static function create(string $content = '', string $extension = null): s
5656
public static function register(): void
5757
{
5858
if (!in_array(self::PROTOCOL, stream_get_wrappers(), true)) {
59-
stream_wrapper_register(self::PROTOCOL, __CLASS__);
59+
stream_wrapper_register(self::PROTOCOL, self::class);
6060
}
6161
}
6262

src/Framework/FileMutator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function addMutator(callable $mutator): void
3232
{
3333
self::$mutators[] = $mutator;
3434
stream_wrapper_unregister(self::PROTOCOL);
35-
stream_wrapper_register(self::PROTOCOL, __CLASS__);
35+
stream_wrapper_register(self::PROTOCOL, self::class);
3636
}
3737

3838

@@ -227,7 +227,7 @@ private function native(string $func)
227227
return $func(...array_slice(func_get_args(), 1));
228228
} finally {
229229
stream_wrapper_unregister(self::PROTOCOL);
230-
stream_wrapper_register(self::PROTOCOL, __CLASS__);
230+
stream_wrapper_register(self::PROTOCOL, self::class);
231231
}
232232
}
233233
}

src/Framework/TestCase.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class TestCase
2323
/** @var bool */
2424
private $handleErrors = false;
2525

26-
/** @var callable|null|false */
26+
/** @var callable|false|null */
2727
private $prevErrorHandler = false;
2828

2929

@@ -89,7 +89,9 @@ public function runTest(string $method, array $args = null): void
8989
if ($args === null) {
9090
$defaultParams = [];
9191
foreach ($method->getParameters() as $param) {
92-
$defaultParams[$param->getName()] = $param->isDefaultValueAvailable() ? $param->getDefaultValue() : null;
92+
$defaultParams[$param->getName()] = $param->isDefaultValueAvailable()
93+
? $param->getDefaultValue()
94+
: null;
9395
}
9496

9597
foreach ((array) $info['dataprovider'] as $i => $provider) {
@@ -99,7 +101,9 @@ public function runTest(string $method, array $args = null): void
99101
}
100102

101103
foreach ($res as $k => $set) {
102-
$data["$i-$k"] = is_string(key($set)) ? array_merge($defaultParams, $set) : $set;
104+
$data["$i-$k"] = is_string(key($set))
105+
? array_merge($defaultParams, $set)
106+
: $set;
103107
}
104108
}
105109

@@ -121,7 +125,9 @@ public function runTest(string $method, array $args = null): void
121125
$this->silentTearDown();
122126
}
123127

124-
return $this->prevErrorHandler ? ($this->prevErrorHandler)(...func_get_args()) : false;
128+
return $this->prevErrorHandler
129+
? ($this->prevErrorHandler)(...func_get_args())
130+
: false;
125131
});
126132
}
127133

@@ -153,7 +159,8 @@ public function runTest(string $method, array $args = null): void
153159
$this->tearDown();
154160

155161
} catch (AssertException $e) {
156-
throw $e->setMessage(sprintf('%s in %s(%s)%s',
162+
throw $e->setMessage(sprintf(
163+
'%s in %s(%s)%s',
157164
$e->origMessage,
158165
$method->getName(),
159166
substr(Dumper::toLine($params), 1, -1),

src/Runner/CliTester.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,9 @@ private function finishCodeCoverage(string $file): void
257257
echo 'failed. Coverage file is empty. Do you call Tester\Environment::setup() in tests?';
258258
return;
259259
}
260-
if (pathinfo($file, PATHINFO_EXTENSION) === 'xml') {
261-
$generator = new CodeCoverage\Generators\CloverXMLGenerator($file, $this->options['--coverage-src']);
262-
} else {
263-
$generator = new CodeCoverage\Generators\HtmlGenerator($file, $this->options['--coverage-src']);
264-
}
260+
$generator = pathinfo($file, PATHINFO_EXTENSION) === 'xml'
261+
? new CodeCoverage\Generators\CloverXMLGenerator($file, $this->options['--coverage-src'])
262+
: new CodeCoverage\Generators\HtmlGenerator($file, $this->options['--coverage-src']);
265263
$generator->render($file);
266264
echo round($generator->getCoveredPercent()) . "% covered\n";
267265
}
@@ -297,7 +295,7 @@ private function watch(Runner $runner): void
297295
} elseif ($idle >= 60) {
298296
$idle = round($idle / 60) . ' min';
299297
} else {
300-
$idle = $idle . ' sec';
298+
$idle .= ' sec';
301299
}
302300
echo 'Watching ' . implode(', ', $this->options['--watch']) . " (idle for $idle) " . str_repeat('.', ++$counter % 5) . " \r";
303301
sleep(2);

0 commit comments

Comments
 (0)