Skip to content
Snippets Groups Projects
Verified Commit bf41246a authored by James Walker's avatar James Walker
Browse files

Minor source revisions for PHP8 as revealed by PHPStan

parent e727a63d
No related branches found
No related tags found
1 merge request!7PHPStan@v1
......@@ -33,7 +33,7 @@ final class ConfigApp extends ConfigClass {
$path = (getcwd() . "/trainline.json");
if (file_exists($path) && is_readable($path)) {
if ($content = file_get_contents($path)) {
return json_decode($content, true, JSON_THROW_ON_ERROR);
return ((array) json_decode($content, true, JSON_THROW_ON_ERROR));
}
}
return [];
......
......@@ -70,7 +70,15 @@ final class LoggerCli implements Logger {
}
else $this -> Cli -> green() -> inline("All OK!");
$this -> Cli -> inline(" ") -> out(sprintf(
/**
* @var CLImate $inlineCli
*
* This line is for PHPStan's benefit, as CLImate
* has no return type defined for `inline()` calls.
*/
$inlineCli = $this -> Cli -> inline(" ");
$inlineCli -> out(sprintf(
"(%s test(s) in %s unit(s), %s%s OK).",
$run -> count(),
$run -> countUnits(),
......
......@@ -21,7 +21,7 @@ final class TestUnit {
*/
public function __construct(protected string $cls) {
if (!self::valid($cls)) {
throw new Exceptions\TestUnitException($cls);
self::handleInvalid($cls);
}
}
......@@ -38,8 +38,13 @@ final class TestUnit {
* Get an instance of the test unit.
*/
public function getInstance() : UnitInterface {
$cls = $this -> getClass();
return new $cls();
$instance = new $cls();
if ($instance instanceof UnitInterface) return $instance;
else self::handleInvalid($cls);
}
......@@ -50,6 +55,14 @@ final class TestUnit {
return (class_exists($cls) && is_a($cls, UnitInterface::CLASS, true));
}
/**
* Handle an invalid class being used as a test unit.
*/
public static function handleInvalid(string $cls) : never {
throw new Exceptions\TestUnitException($cls);
}
}
?>
......@@ -29,6 +29,7 @@ final class FrameworkUnitTests extends Unit {
final public function testB() : void {}
final public function __hiddenTest() : void {}
final protected function protectedTest() : void {}
/** @phpstan-ignore-next-line (intentionally unused) */
private function privateTest() : void {}
};
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment