Skip to content

Commit

Permalink
cs nullable typehints
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Dec 12, 2021
1 parent 5b6e3ec commit 531389c
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion src/CodeCoverage/Generators/AbstractGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function __construct(string $file, array $sources = [])
}


public function render(string $file = null): void
public function render(?string $file = null): void
{
$handle = $file ? @fopen($file, 'w') : STDOUT; // @ is escalated to exception
if (!$handle) {
Expand Down
4 changes: 2 additions & 2 deletions src/CodeCoverage/Generators/CloverXMLGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ protected function renderSelf(): void
}


private function calculateClassMetrics(\stdClass $info, array $coverageData = null): \stdClass
private function calculateClassMetrics(\stdClass $info, ?array $coverageData = null): \stdClass
{
$stats = (object) [
'methodCount' => count($info->methods),
Expand Down Expand Up @@ -182,7 +182,7 @@ private function calculateClassMetrics(\stdClass $info, array $coverageData = nu
}


private static function analyzeMethod(\stdClass $info, array $coverageData = null): array
private static function analyzeMethod(\stdClass $info, ?array $coverageData = null): array
{
$count = 0;
$coveredCount = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/CodeCoverage/Generators/HtmlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HtmlGenerator extends AbstractGenerator
* @param string $file path to coverage.dat file
* @param array $sources files/directories
*/
public function __construct(string $file, array $sources = [], string $title = null)
public function __construct(string $file, array $sources = [], ?string $title = null)
{
parent::__construct($file, $sources);
$this->title = $title;
Expand Down
50 changes: 25 additions & 25 deletions src/Framework/Assert.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Assert
/**
* Asserts that two values are equal and have the same type and identity of objects.
*/
public static function same($expected, $actual, string $description = null): void
public static function same($expected, $actual, ?string $description = null): void
{
self::$counter++;
if ($actual !== $expected) {
Expand All @@ -65,7 +65,7 @@ public static function same($expected, $actual, string $description = null): voi
/**
* Asserts that two values are not equal or do not have the same type and identity of objects.
*/
public static function notSame($expected, $actual, string $description = null): void
public static function notSame($expected, $actual, ?string $description = null): void
{
self::$counter++;
if ($actual === $expected) {
Expand All @@ -78,7 +78,7 @@ public static function notSame($expected, $actual, string $description = null):
* Asserts that two values are equal and checks expectations. The identity of objects,
* the order of keys in the arrays and marginally different floats are ignored.
*/
public static function equal($expected, $actual, string $description = null): void
public static function equal($expected, $actual, ?string $description = null): void
{
self::$counter++;
if (!self::isEqual($expected, $actual)) {
Expand All @@ -91,7 +91,7 @@ public static function equal($expected, $actual, string $description = null): vo
* Asserts that two values are not equal and checks expectations. The identity of objects,
* the order of keys in the arrays and marginally different floats are ignored.
*/
public static function notEqual($expected, $actual, string $description = null): void
public static function notEqual($expected, $actual, ?string $description = null): void
{
self::$counter++;
try {
Expand All @@ -110,7 +110,7 @@ public static function notEqual($expected, $actual, string $description = null):
* @param mixed $needle
* @param array|string $actual
*/
public static function contains($needle, $actual, string $description = null): void
public static function contains($needle, $actual, ?string $description = null): void
{
self::$counter++;
if (is_array($actual)) {
Expand All @@ -135,7 +135,7 @@ public static function contains($needle, $actual, string $description = null): v
* @param mixed $needle
* @param array|string $actual
*/
public static function notContains($needle, $actual, string $description = null): void
public static function notContains($needle, $actual, ?string $description = null): void
{
self::$counter++;
if (is_array($actual)) {
Expand All @@ -159,7 +159,7 @@ public static function notContains($needle, $actual, string $description = null)
* Asserts that a haystack has an expected key.
* @param string|int $key
*/
public static function hasKey($key, array $actual, string $description = null): void
public static function hasKey($key, array $actual, ?string $description = null): void
{
self::$counter++;
if (!is_int($key) && !is_string($key)) {
Expand All @@ -175,7 +175,7 @@ public static function hasKey($key, array $actual, string $description = null):
* Asserts that a haystack doesn't have an expected key.
* @param string|int $key
*/
public static function hasNotKey($key, array $actual, string $description = null): void
public static function hasNotKey($key, array $actual, ?string $description = null): void
{
self::$counter++;
if (!is_int($key) && !is_string($key)) {
Expand All @@ -191,7 +191,7 @@ public static function hasNotKey($key, array $actual, string $description = null
* Asserts that a value is true.
* @param mixed $actual
*/
public static function true($actual, string $description = null): void
public static function true($actual, ?string $description = null): void
{
self::$counter++;
if ($actual !== true) {
Expand All @@ -204,7 +204,7 @@ public static function true($actual, string $description = null): void
* Asserts that a value is false.
* @param mixed $actual
*/
public static function false($actual, string $description = null): void
public static function false($actual, ?string $description = null): void
{
self::$counter++;
if ($actual !== false) {
Expand All @@ -217,7 +217,7 @@ public static function false($actual, string $description = null): void
* Asserts that a value is null.
* @param mixed $actual
*/
public static function null($actual, string $description = null): void
public static function null($actual, ?string $description = null): void
{
self::$counter++;
if ($actual !== null) {
Expand All @@ -230,7 +230,7 @@ public static function null($actual, string $description = null): void
* Asserts that a value is not null.
* @param mixed $actual
*/
public static function notNull($actual, string $description = null): void
public static function notNull($actual, ?string $description = null): void
{
self::$counter++;
if ($actual === null) {
Expand All @@ -243,7 +243,7 @@ public static function notNull($actual, string $description = null): void
* Asserts that a value is Not a Number.
* @param mixed $actual
*/
public static function nan($actual, string $description = null): void
public static function nan($actual, ?string $description = null): void
{
self::$counter++;
if (!is_float($actual) || !is_nan($actual)) {
Expand All @@ -256,7 +256,7 @@ public static function nan($actual, string $description = null): void
* Asserts that a value is truthy.
* @param mixed $actual
*/
public static function truthy($actual, string $description = null): void
public static function truthy($actual, ?string $description = null): void
{
self::$counter++;
if (!$actual) {
Expand All @@ -269,7 +269,7 @@ public static function truthy($actual, string $description = null): void
* Asserts that a value is falsey.
* @param mixed $actual
*/
public static function falsey($actual, string $description = null): void
public static function falsey($actual, ?string $description = null): void
{
self::$counter++;
if ($actual) {
Expand All @@ -282,7 +282,7 @@ public static function falsey($actual, string $description = null): void
* Asserts the number of items in an array or Countable.
* @param array|\Countable $value
*/
public static function count(int $count, $value, string $description = null): void
public static function count(int $count, $value, ?string $description = null): void
{
self::$counter++;
if (!$value instanceof \Countable && !is_array($value)) {
Expand All @@ -299,7 +299,7 @@ public static function count(int $count, $value, string $description = null): vo
* @param string|object $type
* @param mixed $value
*/
public static function type($type, $value, string $description = null): void
public static function type($type, $value, ?string $description = null): void
{
self::$counter++;
if (!is_object($type) && !is_string($type)) {
Expand Down Expand Up @@ -329,7 +329,7 @@ public static function type($type, $value, string $description = null): void
public static function exception(
callable $function,
string $class,
string $message = null,
?string $message = null,
$code = null
): ?\Throwable {
self::$counter++;
Expand Down Expand Up @@ -359,7 +359,7 @@ public static function exception(
/**
* Asserts that a function throws exception of given type and its message matches given pattern. Alias for exception().
*/
public static function throws(callable $function, string $class, string $message = null, $code = null): ?\Throwable
public static function throws(callable $function, string $class, ?string $message = null, $code = null): ?\Throwable
{
return self::exception($function, $class, $message, $code);
}
Expand All @@ -372,7 +372,7 @@ public static function throws(callable $function, string $class, string $message
* @throws \Exception
* @throws \Exception
*/
public static function error(callable $function, $expectedType, string $expectedMessage = null): ?\Throwable
public static function error(callable $function, $expectedType, ?string $expectedMessage = null): ?\Throwable
{
if (is_string($expectedType) && !preg_match('#^E_[A-Z_]+$#D', $expectedType)) {
return static::exception($function, $expectedType, $expectedMessage);
Expand Down Expand Up @@ -458,7 +458,7 @@ public static function noError(callable $function): void
* %h% one or more HEX digits
* @param string $pattern mask|regexp; only delimiters ~ and # are supported for regexp
*/
public static function match(string $pattern, $actual, string $description = null): void
public static function match(string $pattern, $actual, ?string $description = null): void
{
self::$counter++;
if (!is_scalar($actual)) {
Expand All @@ -477,7 +477,7 @@ public static function match(string $pattern, $actual, string $description = nul
/**
* Asserts that a string matches a given pattern stored in file.
*/
public static function matchFile(string $file, $actual, string $description = null): void
public static function matchFile(string $file, $actual, ?string $description = null): void
{
self::$counter++;
$pattern = @file_get_contents($file); // @ is escalated to exception
Expand All @@ -504,8 +504,8 @@ public static function fail(
string $message,
$actual = null,
$expected = null,
\Throwable $previous = null,
string $outputName = null
?\Throwable $previous = null,
?string $outputName = null
): void {
$e = new AssertException($message, $expected, $actual, $previous);
$e->outputName = $outputName;
Expand All @@ -517,7 +517,7 @@ public static function fail(
}


private static function describe(string $reason, string $description = null): string
private static function describe(string $reason, ?string $description = null): string
{
return ($description ? $description . ': ' : '') . $reason;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/AssertException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class AssertException extends \Exception
public $outputName;


public function __construct(string $message, $expected, $actual, \Throwable $previous = null)
public function __construct(string $message, $expected, $actual, ?\Throwable $previous = null)
{
parent::__construct('', 0, $previous);
$this->expected = $expected;
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/Dumper.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ public static function saveOutput(string $testFile, $content, string $suffix = '
/**
* Applies color to string.
*/
public static function color(string $color = '', string $s = null): string
public static function color(string $color = '', ?string $s = null): string
{
static $colors = [
'black' => '0;30', 'gray' => '1;30', 'silver' => '0;37', 'white' => '1;37',
Expand Down
2 changes: 1 addition & 1 deletion src/Framework/FileMock.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class FileMock
/**
* @return string file name
*/
public static function create(string $content = '', string $extension = null): string
public static function create(string $content = '', ?string $extension = null): string
{
self::register();

Expand Down
2 changes: 1 addition & 1 deletion src/Framework/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function run(): void
* Runs the test method.
* @param array $args test method parameters (dataprovider bypass)
*/
public function runTest(string $method, array $args = null): void
public function runTest(string $method, ?array $args = null): void
{
if (!method_exists($this, $method)) {
throw new TestCaseException("Method '$method' does not exist.");
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/CommandLine.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function __construct(string $help, array $defaults = [])
}


public function parse(array $args = null): array
public function parse(?array $args = null): array
{
if ($args === null) {
$args = isset($_SERVER['argv']) ? array_slice($_SERVER['argv'], 1) : [];
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Job
private $duration;


public function __construct(Test $test, PhpInterpreter $interpreter, array $envVars = null)
public function __construct(Test $test, PhpInterpreter $interpreter, ?array $envVars = null)
{
if ($test->getResult() !== Test::PREPARED) {
throw new \LogicException("Test '{$test->getSignature()}' already has result '{$test->getResult()}'.");
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Output/ConsolePrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ConsolePrinter implements Tester\Runner\OutputHandler
public function __construct(
Runner $runner,
bool $displaySkipped = false,
string $file = null,
?string $file = null,
bool $ciderMode = false
) {
$this->runner = $runner;
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Output/JUnitPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class JUnitPrinter implements Tester\Runner\OutputHandler
private $results;


public function __construct(string $file = null)
public function __construct(?string $file = null)
{
$this->file = fopen($file ?: 'php://output', 'w');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Output/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Logger implements Tester\Runner\OutputHandler
private $results;


public function __construct(Runner $runner, string $file = null)
public function __construct(Runner $runner, ?string $file = null)
{
$this->runner = $runner;
$this->file = fopen($file ?: 'php://output', 'w');
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Output/TapPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TapPrinter implements Tester\Runner\OutputHandler
private $results;


public function __construct(string $file = null)
public function __construct(?string $file = null)
{
$this->file = fopen($file ?: 'php://output', 'w');
}
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/PhpInterpreter.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function __construct(string $path, array $args = [])
/**
* @return static
*/
public function withPhpIniOption(string $name, string $value = null): self
public function withPhpIniOption(string $name, ?string $value = null): self
{
$me = clone $this;
$me->commandLine .= ' -d ' . Helpers::escapeArg($name . ($value === null ? '' : "=$value"));
Expand Down
2 changes: 1 addition & 1 deletion src/Runner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function getEnvironmentVariables(): array
}


public function addPhpIniOption(string $name, string $value = null): void
public function addPhpIniOption(string $name, ?string $value = null): void
{
$this->interpreter = $this->interpreter->withPhpIniOption($name, $value);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Runner/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Test
private $args = [];


public function __construct(string $file, string $title = null)
public function __construct(string $file, ?string $title = null)
{
$this->file = $file;
$this->title = $title;
Expand Down Expand Up @@ -124,7 +124,7 @@ public function withArguments(array $args): self
/**
* @return static
*/
public function withResult(int $result, ?string $message, float $duration = null): self
public function withResult(int $result, ?string $message, ?float $duration = null): self
{
if ($this->hasResult()) {
throw new \LogicException("Result of test is already set to $this->result with message '$this->message'.");
Expand Down

0 comments on commit 531389c

Please sign in to comment.