Skip to content

Commit e445e74

Browse files
committed
added property typehints
1 parent 2286246 commit e445e74

24 files changed

+99
-225
lines changed

src/CodeCoverage/Collector.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ class Collector
2323

2424
/** @var resource */
2525
private static $file;
26-
27-
/** @var string */
28-
private static $engine;
26+
private static string $engine;
2927

3028

3129
public static function detectEngines(): array

src/CodeCoverage/Generators/AbstractGenerator.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,11 @@ abstract class AbstractGenerator
2222
CODE_UNTESTED = -1,
2323
CODE_TESTED = 1;
2424

25-
/** @var array */
26-
public $acceptFiles = ['php', 'phpt', 'phtml'];
27-
28-
/** @var array */
29-
protected $data;
30-
31-
/** @var array */
32-
protected $sources;
33-
34-
/** @var int */
35-
protected $totalSum = 0;
36-
37-
/** @var int */
38-
protected $coveredSum = 0;
25+
public array $acceptFiles = ['php', 'phpt', 'phtml'];
26+
protected array $data;
27+
protected array $sources;
28+
protected int $totalSum = 0;
29+
protected int $coveredSum = 0;
3930

4031

4132
/**

src/CodeCoverage/Generators/CloverXMLGenerator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
class CloverXMLGenerator extends AbstractGenerator
1818
{
19-
private static $metricAttributesMap = [
19+
private static array $metricAttributesMap = [
2020
'packageCount' => 'packages',
2121
'fileCount' => 'files',
2222
'linesOfCode' => 'loc',

src/CodeCoverage/Generators/HtmlGenerator.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ class HtmlGenerator extends AbstractGenerator
2222
self::CODE_UNTESTED => 'u', // untested
2323
self::CODE_DEAD => 'dead', // dead code
2424
];
25-
26-
/** @var string */
27-
private $title;
28-
29-
/** @var array */
30-
private $files = [];
25+
private ?string $title;
26+
private array $files = [];
3127

3228

3329
/**

src/Framework/Assert.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ class Assert
4040
'%(\[.+\][+*?{},\d]*)%' => '$1', // range
4141
];
4242

43-
/** @var bool expand patterns in match() and matchFile() */
44-
public static $expandPatterns = true;
43+
/** expand patterns in match() and matchFile() */
44+
public static bool $expandPatterns = true;
4545

4646
/** @var callable function (AssertException $exception): void */
4747
public static $onFailure;
48-
49-
/** @var int the count of assertions */
50-
public static $counter = 0;
48+
public static int $counter = 0;
5149

5250

5351
/**

src/Framework/AssertException.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@
1515
*/
1616
class AssertException extends \Exception
1717
{
18-
public $origMessage;
18+
public string $origMessage;
19+
public mixed $actual;
20+
public mixed $expected;
21+
public ?string $outputName;
1922

20-
public $actual;
2123

22-
public $expected;
23-
24-
public $outputName;
25-
26-
27-
public function __construct(string $message, $expected, $actual, ?\Throwable $previous = null)
24+
public function __construct(string $message, mixed $expected, mixed $actual, ?\Throwable $previous = null)
2825
{
2926
parent::__construct('', 0, $previous);
3027
$this->expected = $expected;

src/Framework/Dumper.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,10 @@
1616
*/
1717
class Dumper
1818
{
19-
public static $maxLength = 70;
20-
21-
public static $maxDepth = 10;
22-
23-
public static $dumpDir = 'output';
24-
25-
public static $maxPathSegments = 3;
26-
19+
public static int $maxLength = 70;
20+
public static int $maxDepth = 10;
21+
public static string $dumpDir = 'output';
22+
public static int $maxPathSegments = 3;
2723
public static $pathSeparator;
2824

2925

src/Framework/Environment.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,10 @@ class Environment
3030
/** Thread number when run tests in multi threads */
3131
public const THREAD = 'NETTE_TESTER_THREAD';
3232

33-
/** @var bool */
34-
public static $checkAssertions = false;
35-
36-
/** @var bool */
37-
public static $useColors;
38-
39-
/** @var int initial output buffer level */
40-
private static $obLevel;
41-
42-
/** @var int */
43-
private static $exitCode = 0;
33+
public static bool $checkAssertions = false;
34+
public static bool $useColors;
35+
private static int $obLevel;
36+
private static int $exitCode = 0;
4437

4538

4639
/**

src/Framework/Expect.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
*/
5050
class Expect
5151
{
52-
/** @var array of self|\Closure|\stdClass */
53-
private $constraints = [];
52+
/** array<self|\Closure|\stdClass> */
53+
private array $constraints = [];
5454

5555

5656
public static function __callStatic(string $method, array $args): self

src/Framework/FileMock.php

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,17 @@ class FileMock
1818
private const Protocol = 'mock';
1919

2020
/** @var string[] */
21-
public static $files = [];
21+
public static array $files = [];
2222

2323
/** @var resource used by PHP itself */
2424
public $context;
2525

26-
/** @var string */
27-
private $content;
28-
29-
/** @var int */
30-
private $readingPos;
31-
32-
/** @var int */
33-
private $writingPos;
34-
35-
/** @var bool */
36-
private $appendMode;
37-
38-
/** @var bool */
39-
private $isReadable;
40-
41-
/** @var bool */
42-
private $isWritable;
26+
private string $content;
27+
private int $readingPos;
28+
private int $writingPos;
29+
private bool $appendMode;
30+
private bool $isReadable;
31+
private bool $isWritable;
4332

4433

4534
/**
@@ -84,8 +73,9 @@ public function stream_open(string $path, string $mode): bool
8473
self::$files[$path] = '';
8574
}
8675

87-
$this->content = &self::$files[$path];
88-
$this->content = (string) $this->content;
76+
$tmp = &self::$files[$path];
77+
$tmp = (string) $tmp;
78+
$this->content = &$tmp;
8979
$this->appendMode = $m[1] === 'a';
9080
$this->readingPos = 0;
9181
$this->writingPos = $this->appendMode ? strlen($this->content) : 0;

src/Framework/FileMutator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class FileMutator
2525
private $handle;
2626

2727
/** @var callable[] */
28-
private static $mutators = [];
28+
private static array $mutators = [];
2929

3030

3131
public static function addMutator(callable $mutator): void

src/Framework/TestCase.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ class TestCase
2020
ListMethods = 'nette-tester-list-methods',
2121
MethodPattern = '#^test[A-Z0-9_]#';
2222

23-
/** @var bool */
24-
private $handleErrors = false;
23+
private bool $handleErrors = false;
2524

2625
/** @var callable|false|null */
2726
private $prevErrorHandler = false;

src/Runner/CliTester.php

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,10 @@
2020
*/
2121
class CliTester
2222
{
23-
/** @var array */
24-
private $options;
25-
26-
/** @var PhpInterpreter */
27-
private $interpreter;
28-
29-
/** @var bool */
30-
private $debugMode = true;
31-
32-
/** @var string|null */
33-
private $stdoutFormat;
23+
private array $options;
24+
private PhpInterpreter $interpreter;
25+
private bool $debugMode = true;
26+
private ?string $stdoutFormat = null;
3427

3528

3629
public function run(): ?int
@@ -219,7 +212,7 @@ private function createRunner(): Runner
219212
$runner = new Runner($this->interpreter);
220213
$runner->paths = $this->options['paths'];
221214
$runner->threadCount = max(1, (int) $this->options['-j']);
222-
$runner->stopOnFail = $this->options['--stop-on-fail'];
215+
$runner->stopOnFail = (bool) $this->options['--stop-on-fail'];
223216

224217
if ($this->options['--temp'] !== null) {
225218
$runner->setTempDirectory($this->options['--temp']);

src/Runner/CommandLine.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,14 @@ class CommandLine
2525
Value = 'default';
2626

2727
/** @var array[] */
28-
private $options = [];
28+
private array $options = [];
2929

3030
/** @var string[] */
31-
private $aliases = [];
31+
private array $aliases = [];
3232

3333
/** @var string[] */
34-
private $positional = [];
35-
36-
/** @var string */
37-
private $help;
34+
private array $positional = [];
35+
private string $help;
3836

3937

4038
public function __construct(string $help, array $defaults = [])

src/Runner/Job.php

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,11 @@ class Job
3131
RUN_ASYNC = 1,
3232
RUN_COLLECT_ERRORS = 2;
3333

34-
/** @var Test */
35-
private $test;
36-
37-
/** @var PhpInterpreter */
38-
private $interpreter;
34+
private Test $test;
35+
private PhpInterpreter $interpreter;
3936

4037
/** @var string[] environment variables for test */
41-
private $envVars;
38+
private array $envVars;
4239

4340
/** @var resource|null */
4441
private $proc;
@@ -48,15 +45,11 @@ class Job
4845

4946
/** @var resource|null */
5047
private $stderr;
51-
52-
/** @var int */
53-
private $exitCode = self::CODE_NONE;
48+
private int $exitCode = self::CODE_NONE;
5449

5550
/** @var string[] output headers */
56-
private $headers = [];
57-
58-
/** @var float|null */
59-
private $duration;
51+
private array $headers = [];
52+
private ?float $duration;
6053

6154

6255
public function __construct(Test $test, PhpInterpreter $interpreter, ?array $envVars = null)

src/Runner/Output/ConsolePrinter.php

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,17 @@
2020
*/
2121
class ConsolePrinter implements Tester\Runner\OutputHandler
2222
{
23-
/** @var Runner */
24-
private $runner;
25-
26-
/** @var bool display skipped tests information? */
27-
private $displaySkipped = false;
23+
private Runner $runner;
2824

2925
/** @var resource */
3026
private $file;
31-
32-
/** @var string */
33-
private $buffer;
34-
35-
/** @var float */
36-
private $time;
37-
38-
/** @var int */
39-
private $count;
40-
41-
/** @var array */
42-
private $results;
43-
44-
/** @var string */
45-
private $baseDir;
46-
47-
/** @var array */
48-
private $symbols;
27+
private bool $displaySkipped = false;
28+
private string $buffer;
29+
private float $time;
30+
private int $count;
31+
private array $results;
32+
private ?string $baseDir;
33+
private array $symbols;
4934

5035

5136
public function __construct(
@@ -68,6 +53,7 @@ public function __construct(
6853
public function begin(): void
6954
{
7055
$this->count = 0;
56+
$this->buffer = '';
7157
$this->baseDir = null;
7258
$this->results = [
7359
Test::PASSED => 0,
@@ -132,6 +118,6 @@ public function end(): void
132118
. ($this->count !== $run ? ($this->count - $run) . ' not run, ' : '')
133119
. sprintf('%0.1f', $this->time + microtime(true)) . ' seconds)' . Dumper::color() . "\n");
134120

135-
$this->buffer = null;
121+
$this->buffer = '';
136122
}
137123
}

src/Runner/Output/JUnitPrinter.php

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,9 @@ class JUnitPrinter implements Tester\Runner\OutputHandler
2020
{
2121
/** @var resource */
2222
private $file;
23-
24-
/** @var string */
25-
private $buffer;
26-
27-
/** @var float */
28-
private $startTime;
29-
30-
/** @var array */
31-
private $results;
23+
private string $buffer;
24+
private float $startTime;
25+
private array $results;
3226

3327

3428
public function __construct(?string $file = null)
@@ -39,6 +33,7 @@ public function __construct(?string $file = null)
3933

4034
public function begin(): void
4135
{
36+
$this->buffer = '';
4237
$this->results = [
4338
Test::PASSED => 0,
4439
Test::SKIPPED => 0,

0 commit comments

Comments
 (0)