Skip to content

Commit 60a38ca

Browse files
committed
cs nullable typehints
1 parent 5d9062a commit 60a38ca

17 files changed

+43
-43
lines changed

src/CodeCoverage/Generators/AbstractGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function __construct(string $file, array $sources = [])
7272
}
7373

7474

75-
public function render(string $file = null): void
75+
public function render(?string $file = null): void
7676
{
7777
$handle = $file ? @fopen($file, 'w') : STDOUT; // @ is escalated to exception
7878
if (!$handle) {

src/CodeCoverage/Generators/CloverXMLGenerator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ protected function renderSelf(): void
151151
}
152152

153153

154-
private function calculateClassMetrics(\stdClass $info, array $coverageData = null): \stdClass
154+
private function calculateClassMetrics(\stdClass $info, ?array $coverageData = null): \stdClass
155155
{
156156
$stats = (object) [
157157
'methodCount' => count($info->methods),
@@ -182,7 +182,7 @@ private function calculateClassMetrics(\stdClass $info, array $coverageData = nu
182182
}
183183

184184

185-
private static function analyzeMethod(\stdClass $info, array $coverageData = null): array
185+
private static function analyzeMethod(\stdClass $info, ?array $coverageData = null): array
186186
{
187187
$count = 0;
188188
$coveredCount = 0;

src/CodeCoverage/Generators/HtmlGenerator.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class HtmlGenerator extends AbstractGenerator
3434
* @param string $file path to coverage.dat file
3535
* @param array $sources files/directories
3636
*/
37-
public function __construct(string $file, array $sources = [], string $title = null)
37+
public function __construct(string $file, array $sources = [], ?string $title = null)
3838
{
3939
parent::__construct($file, $sources);
4040
$this->title = $title;

src/Framework/Assert.php

+25-25
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class Assert
5353
/**
5454
* Asserts that two values are equal and have the same type and identity of objects.
5555
*/
56-
public static function same($expected, $actual, string $description = null): void
56+
public static function same($expected, $actual, ?string $description = null): void
5757
{
5858
self::$counter++;
5959
if ($actual !== $expected) {
@@ -65,7 +65,7 @@ public static function same($expected, $actual, string $description = null): voi
6565
/**
6666
* Asserts that two values are not equal or do not have the same type and identity of objects.
6767
*/
68-
public static function notSame($expected, $actual, string $description = null): void
68+
public static function notSame($expected, $actual, ?string $description = null): void
6969
{
7070
self::$counter++;
7171
if ($actual === $expected) {
@@ -78,7 +78,7 @@ public static function notSame($expected, $actual, string $description = null):
7878
* Asserts that two values are equal and checks expectations. The identity of objects,
7979
* the order of keys in the arrays and marginally different floats are ignored.
8080
*/
81-
public static function equal($expected, $actual, string $description = null): void
81+
public static function equal($expected, $actual, ?string $description = null): void
8282
{
8383
self::$counter++;
8484
if (!self::isEqual($expected, $actual)) {
@@ -91,7 +91,7 @@ public static function equal($expected, $actual, string $description = null): vo
9191
* Asserts that two values are not equal and checks expectations. The identity of objects,
9292
* the order of keys in the arrays and marginally different floats are ignored.
9393
*/
94-
public static function notEqual($expected, $actual, string $description = null): void
94+
public static function notEqual($expected, $actual, ?string $description = null): void
9595
{
9696
self::$counter++;
9797
try {
@@ -110,7 +110,7 @@ public static function notEqual($expected, $actual, string $description = null):
110110
* @param mixed $needle
111111
* @param array|string $actual
112112
*/
113-
public static function contains($needle, $actual, string $description = null): void
113+
public static function contains($needle, $actual, ?string $description = null): void
114114
{
115115
self::$counter++;
116116
if (is_array($actual)) {
@@ -135,7 +135,7 @@ public static function contains($needle, $actual, string $description = null): v
135135
* @param mixed $needle
136136
* @param array|string $actual
137137
*/
138-
public static function notContains($needle, $actual, string $description = null): void
138+
public static function notContains($needle, $actual, ?string $description = null): void
139139
{
140140
self::$counter++;
141141
if (is_array($actual)) {
@@ -159,7 +159,7 @@ public static function notContains($needle, $actual, string $description = null)
159159
* Asserts that a haystack has an expected key.
160160
* @param string|int $key
161161
*/
162-
public static function hasKey($key, array $actual, string $description = null): void
162+
public static function hasKey($key, array $actual, ?string $description = null): void
163163
{
164164
self::$counter++;
165165
if (!is_int($key) && !is_string($key)) {
@@ -175,7 +175,7 @@ public static function hasKey($key, array $actual, string $description = null):
175175
* Asserts that a haystack doesn't have an expected key.
176176
* @param string|int $key
177177
*/
178-
public static function hasNotKey($key, array $actual, string $description = null): void
178+
public static function hasNotKey($key, array $actual, ?string $description = null): void
179179
{
180180
self::$counter++;
181181
if (!is_int($key) && !is_string($key)) {
@@ -191,7 +191,7 @@ public static function hasNotKey($key, array $actual, string $description = null
191191
* Asserts that a value is true.
192192
* @param mixed $actual
193193
*/
194-
public static function true($actual, string $description = null): void
194+
public static function true($actual, ?string $description = null): void
195195
{
196196
self::$counter++;
197197
if ($actual !== true) {
@@ -204,7 +204,7 @@ public static function true($actual, string $description = null): void
204204
* Asserts that a value is false.
205205
* @param mixed $actual
206206
*/
207-
public static function false($actual, string $description = null): void
207+
public static function false($actual, ?string $description = null): void
208208
{
209209
self::$counter++;
210210
if ($actual !== false) {
@@ -217,7 +217,7 @@ public static function false($actual, string $description = null): void
217217
* Asserts that a value is null.
218218
* @param mixed $actual
219219
*/
220-
public static function null($actual, string $description = null): void
220+
public static function null($actual, ?string $description = null): void
221221
{
222222
self::$counter++;
223223
if ($actual !== null) {
@@ -230,7 +230,7 @@ public static function null($actual, string $description = null): void
230230
* Asserts that a value is not null.
231231
* @param mixed $actual
232232
*/
233-
public static function notNull($actual, string $description = null): void
233+
public static function notNull($actual, ?string $description = null): void
234234
{
235235
self::$counter++;
236236
if ($actual === null) {
@@ -243,7 +243,7 @@ public static function notNull($actual, string $description = null): void
243243
* Asserts that a value is Not a Number.
244244
* @param mixed $actual
245245
*/
246-
public static function nan($actual, string $description = null): void
246+
public static function nan($actual, ?string $description = null): void
247247
{
248248
self::$counter++;
249249
if (!is_float($actual) || !is_nan($actual)) {
@@ -256,7 +256,7 @@ public static function nan($actual, string $description = null): void
256256
* Asserts that a value is truthy.
257257
* @param mixed $actual
258258
*/
259-
public static function truthy($actual, string $description = null): void
259+
public static function truthy($actual, ?string $description = null): void
260260
{
261261
self::$counter++;
262262
if (!$actual) {
@@ -269,7 +269,7 @@ public static function truthy($actual, string $description = null): void
269269
* Asserts that a value is falsey.
270270
* @param mixed $actual
271271
*/
272-
public static function falsey($actual, string $description = null): void
272+
public static function falsey($actual, ?string $description = null): void
273273
{
274274
self::$counter++;
275275
if ($actual) {
@@ -282,7 +282,7 @@ public static function falsey($actual, string $description = null): void
282282
* Asserts the number of items in an array or Countable.
283283
* @param array|\Countable $value
284284
*/
285-
public static function count(int $count, $value, string $description = null): void
285+
public static function count(int $count, $value, ?string $description = null): void
286286
{
287287
self::$counter++;
288288
if (!$value instanceof \Countable && !is_array($value)) {
@@ -299,7 +299,7 @@ public static function count(int $count, $value, string $description = null): vo
299299
* @param string|object $type
300300
* @param mixed $value
301301
*/
302-
public static function type($type, $value, string $description = null): void
302+
public static function type($type, $value, ?string $description = null): void
303303
{
304304
self::$counter++;
305305
if (!is_object($type) && !is_string($type)) {
@@ -329,7 +329,7 @@ public static function type($type, $value, string $description = null): void
329329
public static function exception(
330330
callable $function,
331331
string $class,
332-
string $message = null,
332+
?string $message = null,
333333
$code = null
334334
): ?\Throwable {
335335
self::$counter++;
@@ -359,7 +359,7 @@ public static function exception(
359359
/**
360360
* Asserts that a function throws exception of given type and its message matches given pattern. Alias for exception().
361361
*/
362-
public static function throws(callable $function, string $class, string $message = null, $code = null): ?\Throwable
362+
public static function throws(callable $function, string $class, ?string $message = null, $code = null): ?\Throwable
363363
{
364364
return self::exception($function, $class, $message, $code);
365365
}
@@ -372,7 +372,7 @@ public static function throws(callable $function, string $class, string $message
372372
* @throws \Exception
373373
* @throws \Exception
374374
*/
375-
public static function error(callable $function, $expectedType, string $expectedMessage = null): ?\Throwable
375+
public static function error(callable $function, $expectedType, ?string $expectedMessage = null): ?\Throwable
376376
{
377377
if (is_string($expectedType) && !preg_match('#^E_[A-Z_]+$#D', $expectedType)) {
378378
return static::exception($function, $expectedType, $expectedMessage);
@@ -458,7 +458,7 @@ public static function noError(callable $function): void
458458
* %h% one or more HEX digits
459459
* @param string $pattern mask|regexp; only delimiters ~ and # are supported for regexp
460460
*/
461-
public static function match(string $pattern, $actual, string $description = null): void
461+
public static function match(string $pattern, $actual, ?string $description = null): void
462462
{
463463
self::$counter++;
464464
if (!is_scalar($actual)) {
@@ -477,7 +477,7 @@ public static function match(string $pattern, $actual, string $description = nul
477477
/**
478478
* Asserts that a string matches a given pattern stored in file.
479479
*/
480-
public static function matchFile(string $file, $actual, string $description = null): void
480+
public static function matchFile(string $file, $actual, ?string $description = null): void
481481
{
482482
self::$counter++;
483483
$pattern = @file_get_contents($file); // @ is escalated to exception
@@ -504,8 +504,8 @@ public static function fail(
504504
string $message,
505505
$actual = null,
506506
$expected = null,
507-
\Throwable $previous = null,
508-
string $outputName = null
507+
?\Throwable $previous = null,
508+
?string $outputName = null
509509
): void {
510510
$e = new AssertException($message, $expected, $actual, $previous);
511511
$e->outputName = $outputName;
@@ -517,7 +517,7 @@ public static function fail(
517517
}
518518

519519

520-
private static function describe(string $reason, string $description = null): string
520+
private static function describe(string $reason, ?string $description = null): string
521521
{
522522
return ($description ? $description . ': ' : '') . $reason;
523523
}

src/Framework/AssertException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AssertException extends \Exception
2424
public $outputName;
2525

2626

27-
public function __construct(string $message, $expected, $actual, \Throwable $previous = null)
27+
public function __construct(string $message, $expected, $actual, ?\Throwable $previous = null)
2828
{
2929
parent::__construct('', 0, $previous);
3030
$this->expected = $expected;

src/Framework/Dumper.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ public static function saveOutput(string $testFile, $content, string $suffix = '
418418
/**
419419
* Applies color to string.
420420
*/
421-
public static function color(string $color = '', string $s = null): string
421+
public static function color(string $color = '', ?string $s = null): string
422422
{
423423
$colors = [
424424
'black' => '0;30', 'gray' => '1;30', 'silver' => '0;37', 'white' => '1;37',

src/Framework/FileMock.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class FileMock
4242
/**
4343
* @return string file name
4444
*/
45-
public static function create(string $content = '', string $extension = null): string
45+
public static function create(string $content = '', ?string $extension = null): string
4646
{
4747
self::register();
4848

src/Framework/TestCase.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function run(): void
6868
* Runs the test method.
6969
* @param array $args test method parameters (dataprovider bypass)
7070
*/
71-
public function runTest(string $method, array $args = null): void
71+
public function runTest(string $method, ?array $args = null): void
7272
{
7373
if (!method_exists($this, $method)) {
7474
throw new TestCaseException("Method '$method' does not exist.");

src/Runner/CommandLine.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function __construct(string $help, array $defaults = [])
7171
}
7272

7373

74-
public function parse(array $args = null): array
74+
public function parse(?array $args = null): array
7575
{
7676
if ($args === null) {
7777
$args = isset($_SERVER['argv']) ? array_slice($_SERVER['argv'], 1) : [];

src/Runner/Job.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class Job
5959
private $duration;
6060

6161

62-
public function __construct(Test $test, PhpInterpreter $interpreter, array $envVars = null)
62+
public function __construct(Test $test, PhpInterpreter $interpreter, ?array $envVars = null)
6363
{
6464
if ($test->getResult() !== Test::PREPARED) {
6565
throw new \LogicException("Test '{$test->getSignature()}' already has result '{$test->getResult()}'.");

src/Runner/Output/ConsolePrinter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class ConsolePrinter implements Tester\Runner\OutputHandler
5151
public function __construct(
5252
Runner $runner,
5353
bool $displaySkipped = false,
54-
string $file = null,
54+
?string $file = null,
5555
bool $ciderMode = false
5656
) {
5757
$this->runner = $runner;

src/Runner/Output/JUnitPrinter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class JUnitPrinter implements Tester\Runner\OutputHandler
3131
private $results;
3232

3333

34-
public function __construct(string $file = null)
34+
public function __construct(?string $file = null)
3535
{
3636
$this->file = fopen($file ?: 'php://output', 'w');
3737
}

src/Runner/Output/Logger.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Logger implements Tester\Runner\OutputHandler
3232
private $results;
3333

3434

35-
public function __construct(Runner $runner, string $file = null)
35+
public function __construct(Runner $runner, ?string $file = null)
3636
{
3737
$this->runner = $runner;
3838
$this->file = fopen($file ?: 'php://output', 'w');

src/Runner/Output/TapPrinter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class TapPrinter implements Tester\Runner\OutputHandler
2525
private $results;
2626

2727

28-
public function __construct(string $file = null)
28+
public function __construct(?string $file = null)
2929
{
3030
$this->file = fopen($file ?: 'php://output', 'w');
3131
}

src/Runner/PhpInterpreter.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function __construct(string $path, array $args = [])
8989
/**
9090
* @return static
9191
*/
92-
public function withPhpIniOption(string $name, string $value = null): self
92+
public function withPhpIniOption(string $name, ?string $value = null): self
9393
{
9494
$me = clone $this;
9595
$me->commandLine .= ' -d ' . Helpers::escapeArg($name . ($value === null ? '' : "=$value"));

src/Runner/Runner.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getEnvironmentVariables(): array
7676
}
7777

7878

79-
public function addPhpIniOption(string $name, string $value = null): void
79+
public function addPhpIniOption(string $name, ?string $value = null): void
8080
{
8181
$this->interpreter = $this->interpreter->withPhpIniOption($name, $value);
8282
}

src/Runner/Test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class Test
4646
private $args = [];
4747

4848

49-
public function __construct(string $file, string $title = null)
49+
public function __construct(string $file, ?string $title = null)
5050
{
5151
$this->file = $file;
5252
$this->title = $title;
@@ -124,7 +124,7 @@ public function withArguments(array $args): self
124124
/**
125125
* @return static
126126
*/
127-
public function withResult(int $result, ?string $message, float $duration = null): self
127+
public function withResult(int $result, ?string $message, ?float $duration = null): self
128128
{
129129
if ($this->hasResult()) {
130130
throw new \LogicException("Result of test is already set to $this->result with message '$this->message'.");

0 commit comments

Comments
 (0)