Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHP 8.4] Fixes for implicit nullability deprecation #771

Merged
merged 2 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/CodeCleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class CodeCleaner
* @param bool $yolo run without input validation
* @param bool $strictTypes enforce strict types by default
*/
public function __construct(Parser $parser = null, Printer $printer = null, NodeTraverser $traverser = null, bool $yolo = false, bool $strictTypes = false)
public function __construct(?Parser $parser = null, ?Printer $printer = null, ?NodeTraverser $traverser = null, bool $yolo = false, bool $strictTypes = false)
{
$this->yolo = $yolo;
$this->strictTypes = $strictTypes;
Expand Down Expand Up @@ -284,7 +284,7 @@ public function clean(array $codeLines, bool $requireSemicolons = false)
*
* @param array|null $namespace (default: null)
*/
public function setNamespace(array $namespace = null)
public function setNamespace(?array $namespace = null)
{
$this->namespace = $namespace;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/CodeArgumentParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CodeArgumentParser
{
private $parser;

public function __construct(Parser $parser = null)
public function __construct(?Parser $parser = null)
{
$this->parser = $parser ?? (new ParserFactory())->createParser();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Command/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class Command extends BaseCommand
*
* @api
*/
public function setApplication(Application $application = null): void
public function setApplication(?Application $application = null): void
{
if ($application !== null && !$application instanceof Shell) {
throw new \InvalidArgumentException('PsySH Commands require an instance of Psy\Shell');
Expand Down
4 changes: 2 additions & 2 deletions src/Command/EditCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
* @param bool $noExecOption
* @param string|null $filePath
*/
private function shouldExecuteFile(bool $execOption, bool $noExecOption, string $filePath = null): bool
private function shouldExecuteFile(bool $execOption, bool $noExecOption, ?string $filePath = null): bool
{
if ($execOption) {
return true;
Expand All @@ -136,7 +136,7 @@ private function shouldExecuteFile(bool $execOption, bool $noExecOption, string
*
* @throws \InvalidArgumentException If the variable is not found in the current context
*/
private function extractFilePath(string $fileArgument = null)
private function extractFilePath(?string $fileArgument = null)
{
// If the file argument was a variable, get it from the context
if ($fileArgument !== null &&
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ListCommand/ClassConstantEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ClassConstantEnumerator extends Enumerator
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
// only list constants when a Reflector is present.
if ($reflector === null) {
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ListCommand/ClassEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class ClassEnumerator extends Enumerator
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
// if we have a reflector, ensure that it's a namespace reflector
if (($target !== null || $reflector !== null) && !$reflector instanceof ReflectionNamespace) {
Expand Down Expand Up @@ -66,7 +66,7 @@ protected function listItems(InputInterface $input, \Reflector $reflector = null
*
* @return array
*/
protected function filterClasses(string $key, array $classes, bool $internal, bool $user, string $prefix = null): array
protected function filterClasses(string $key, array $classes, bool $internal, bool $user, ?string $prefix = null): array
{
$ret = [];

Expand Down
4 changes: 2 additions & 2 deletions src/Command/ListCommand/ConstantEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ConstantEnumerator extends Enumerator
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
// if we have a reflector, ensure that it's a namespace reflector
if (($target !== null || $reflector !== null) && !$reflector instanceof ReflectionNamespace) {
Expand Down Expand Up @@ -122,7 +122,7 @@ protected function listItems(InputInterface $input, \Reflector $reflector = null
*
* @return array
*/
protected function getConstants(string $category = null): array
protected function getConstants(?string $category = null): array
{
if (!$category) {
return \get_defined_constants();
Expand Down
4 changes: 2 additions & 2 deletions src/Command/ListCommand/Enumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public function __construct(Presenter $presenter)
*
* @return array
*/
public function enumerate(InputInterface $input, \Reflector $reflector = null, $target = null): array
public function enumerate(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
$this->filter->bind($input);

Expand Down Expand Up @@ -82,7 +82,7 @@ public function enumerate(InputInterface $input, \Reflector $reflector = null, $
*
* @return array
*/
abstract protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array;
abstract protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array;

protected function showItem($name)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Command/ListCommand/FunctionEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class FunctionEnumerator extends Enumerator
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
// if we have a reflector, ensure that it's a namespace reflector
if (($target !== null || $reflector !== null) && !$reflector instanceof ReflectionNamespace) {
Expand Down Expand Up @@ -67,7 +67,7 @@ protected function listItems(InputInterface $input, \Reflector $reflector = null
*
* @return array
*/
protected function getFunctions(string $type = null): array
protected function getFunctions(?string $type = null): array
{
$funcs = \get_defined_functions();

Expand All @@ -86,7 +86,7 @@ protected function getFunctions(string $type = null): array
*
* @return array
*/
protected function prepareFunctions(array $functions, string $prefix = null): array
protected function prepareFunctions(array $functions, ?string $prefix = null): array
{
\natcasesort($functions);

Expand Down
2 changes: 1 addition & 1 deletion src/Command/ListCommand/GlobalVariableEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class GlobalVariableEnumerator extends Enumerator
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
// only list globals when no Reflector is present.
if ($reflector !== null || $target !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ListCommand/MethodEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class MethodEnumerator extends Enumerator
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
// only list methods when a Reflector is present.
if ($reflector === null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ListCommand/PropertyEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class PropertyEnumerator extends Enumerator
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
// only list properties when a Reflector is present.

Expand Down
2 changes: 1 addition & 1 deletion src/Command/ListCommand/VariableEnumerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(Presenter $presenter, Context $context)
/**
* {@inheritdoc}
*/
protected function listItems(InputInterface $input, \Reflector $reflector = null, $target = null): array
protected function listItems(InputInterface $input, ?\Reflector $reflector = null, $target = null): array
{
// only list variables when no Reflector is present.
if ($reflector !== null || $target !== null) {
Expand Down
2 changes: 1 addition & 1 deletion src/Command/ThrowUpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
*
* @return Arg[]
*/
private function prepareArgs(string $code = null): array
private function prepareArgs(?string $code = null): array
{
if (!$code) {
// Default to last exception if nothing else was supplied
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TimeitCommand/TimeitVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ private function getStartCall(): StaticCall
*
* @param Expr|null $arg
*/
private function getEndCall(Expr $arg = null): StaticCall
private function getEndCall(?Expr $arg = null): StaticCall
{
if ($arg === null) {
$arg = NoReturnValue::create();
Expand Down
2 changes: 1 addition & 1 deletion src/Command/TraceCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
*
* @return array Formatted stacktrace lines
*/
protected function getBacktrace(\Throwable $e, int $count = null, bool $includePsy = true): array
protected function getBacktrace(\Throwable $e, ?int $count = null, bool $includePsy = true): array
{
return TraceFormatter::formatTrace($e, $this->filter, $count, $includePsy);
}
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigPaths.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ConfigPaths
* @param string[] $overrides Directory overrides
* @param EnvInterface $env
*/
public function __construct(array $overrides = [], EnvInterface $env = null)
public function __construct(array $overrides = [], ?EnvInterface $env = null)
{
$this->overrideDirs($overrides);

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/BreakException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BreakException extends \Exception implements Exception
/**
* {@inheritdoc}
*/
public function __construct($message = '', $code = 0, \Throwable $previous = null)
public function __construct($message = '', $code = 0, ?\Throwable $previous = null)
{
$this->rawMessage = $message;
parent::__construct(\sprintf('Exit: %s', $message), $code, $previous);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ErrorException extends \ErrorException implements Exception
* @param int|null $lineno (default: null)
* @param \Throwable|null $previous (default: null)
*/
public function __construct($message = '', $code = 0, $severity = 1, $filename = null, $lineno = null, \Throwable $previous = null)
public function __construct($message = '', $code = 0, $severity = 1, $filename = null, $lineno = null, ?\Throwable $previous = null)
{
$this->rawMessage = $message;

Expand Down
2 changes: 1 addition & 1 deletion src/Exception/FatalErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class FatalErrorException extends \ErrorException implements Exception
* @param int|null $lineno (default: null)
* @param \Throwable|null $previous (default: null)
*/
public function __construct($message = '', $code = 0, $severity = 1, $filename = null, $lineno = null, \Throwable $previous = null)
public function __construct($message = '', $code = 0, $severity = 1, $filename = null, $lineno = null, ?\Throwable $previous = null)
{
// Since these are basically always PHP Parser Node line numbers, treat -1 as null.
if ($lineno === -1) {
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RuntimeException extends \RuntimeException implements Exception
* @param int $code (default: 0)
* @param \Throwable|null $previous (default: null)
*/
public function __construct(string $message = '', int $code = 0, \Throwable $previous = null)
public function __construct(string $message = '', int $code = 0, ?\Throwable $previous = null)
{
$this->rawMessage = $message;
parent::__construct($message, $code, $previous);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/UnexpectedTargetException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class UnexpectedTargetException extends RuntimeException
* @param int $code (default: 0)
* @param \Throwable|null $previous (default: null)
*/
public function __construct($target, string $message = '', int $code = 0, \Throwable $previous = null)
public function __construct($target, string $message = '', int $code = 0, ?\Throwable $previous = null)
{
$this->target = $target;
parent::__construct($message, $code, $previous);
Expand Down
6 changes: 3 additions & 3 deletions src/Formatter/CodeFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function format(\Reflector $reflector): string
*
* @return string formatted code
*/
public static function formatCode(string $code, int $startLine = 1, int $endLine = null, int $markLine = null): string
public static function formatCode(string $code, int $startLine = 1, ?int $endLine = null, ?int $markLine = null): string
{
$spans = self::tokenizeSpans($code);
$lines = self::splitLines($spans, $startLine, $endLine);
Expand Down Expand Up @@ -206,7 +206,7 @@ private static function nextHighlightType($token, $currentType)
*
* @return \Generator lines, each an array of [$spanType, $spanText] pairs
*/
private static function splitLines(\Generator $spans, int $startLine = 1, int $endLine = null): \Generator
private static function splitLines(\Generator $spans, int $startLine = 1, ?int $endLine = null): \Generator
{
$lineNum = 1;
$buffer = [];
Expand Down Expand Up @@ -273,7 +273,7 @@ private static function formatLines(\Generator $spanLines): \Generator
*
* @return \Generator Numbered, formatted lines
*/
private static function numberLines(\Generator $lines, int $markLine = null): \Generator
private static function numberLines(\Generator $lines, ?int $markLine = null): \Generator
{
$lines = \iterator_to_array($lines);

Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/TraceFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class TraceFormatter
*
* @return string[] Formatted stacktrace lines
*/
public static function formatTrace(\Throwable $throwable, FilterOptions $filter = null, int $count = null, bool $includePsy = true): array
public static function formatTrace(\Throwable $throwable, ?FilterOptions $filter = null, ?int $count = null, bool $includePsy = true): array
{
if ($cwd = \getcwd()) {
$cwd = \rtrim($cwd, \DIRECTORY_SEPARATOR).\DIRECTORY_SEPARATOR;
Expand Down
2 changes: 1 addition & 1 deletion src/Input/CodeArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CodeArgument extends InputArgument
*
* @throws \InvalidArgumentException When argument mode is not valid
*/
public function __construct(string $name, int $mode = null, string $description = '', $default = null)
public function __construct(string $name, ?int $mode = null, string $description = '', $default = null)
{
if ($mode & InputArgument::IS_ARRAY) {
throw new \InvalidArgumentException('Argument mode IS_ARRAY is not valid');
Expand Down
2 changes: 1 addition & 1 deletion src/Input/FilterOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function hasFilter(): bool
* @param string $string
* @param array $matches
*/
public function match(string $string, array &$matches = null): bool
public function match(string $string, ?array &$matches = null): bool
{
return $this->filter === false || (\preg_match($this->pattern, $string, $matches) xor $this->invert);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Output/ShellOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class ShellOutput extends ConsoleOutput
* @param OutputFormatterInterface|null $formatter (default: null)
* @param string|OutputPager|null $pager (default: null)
*/
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null, $pager = null, $theme = null)
public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, ?OutputFormatterInterface $formatter = null, $pager = null, $theme = null)
{
parent::__construct($verbosity, $decorated, $formatter);

Expand Down
2 changes: 1 addition & 1 deletion src/Readline/GNUReadline.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function readHistory(): bool
/**
* {@inheritdoc}
*/
public function readline(string $prompt = null)
public function readline(?string $prompt = null)
{
return \readline($prompt);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Readline/Hoa/AutocompleterPath.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class AutocompleterPath implements Autocompleter
* Constructor.
*/
public function __construct(
string $root = null,
\Closure $iteratorFactory = null
?string $root = null,
?\Closure $iteratorFactory = null
) {
if (null === $root) {
$root = static::PWD;
Expand Down
2 changes: 1 addition & 1 deletion src/Readline/Hoa/ConsoleCursor.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public static function move(string $steps, int $repeat = 1)
* Move to the line X and the column Y.
* If null, use the current coordinate.
*/
public static function moveTo(int $x = null, int $y = null)
public static function moveTo(?int $x = null, ?int $y = null)
{
if (null === $x || null === $y) {
$position = static::getPosition();
Expand Down
2 changes: 1 addition & 1 deletion src/Readline/Hoa/ConsoleInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ConsoleInput implements StreamIn
/**
* Wraps an `Hoa\Stream\IStream\In` stream.
*/
public function __construct(StreamIn $input = null)
public function __construct(?StreamIn $input = null)
{
if (null === $input) {
if (\defined('STDIN') &&
Expand Down
2 changes: 1 addition & 1 deletion src/Readline/Hoa/ConsoleOutput.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ConsoleOutput implements StreamOut
/**
* Wraps an `Hoa\Stream\IStream\Out` stream.
*/
public function __construct(StreamOut $output = null)
public function __construct(?StreamOut $output = null)
{
$this->_output = $output;

Expand Down
Loading
Loading