diff --git a/src/Psalm/Codebase.php b/src/Psalm/Codebase.php index 63ba43330..256f5c5f1 100644 --- a/src/Psalm/Codebase.php +++ b/src/Psalm/Codebase.php @@ -95,7 +95,7 @@ class Codebase /** * @var null|'always'|'auto' */ - public $find_unused_code = null; + public $find_unused_code; /** * @var FileProvider @@ -179,7 +179,7 @@ class Codebase /** * @var ?Internal\Codebase\TaintFlowGraph */ - public $taint_flow_graph = null; + public $taint_flow_graph; /** * @var bool @@ -614,7 +614,7 @@ class Codebase public function getStubbedConstantType(string $const_id): ?Type\Union { - return isset(self::$stubbed_constants[$const_id]) ? self::$stubbed_constants[$const_id] : null; + return self::$stubbed_constants[$const_id] ?? null; } /** @@ -1614,7 +1614,7 @@ class Codebase $insertion_text = Type::getStringFromFQCLN( $fq_class_name, $aliases && $aliases->namespace ? $aliases->namespace : null, - $aliases ? $aliases->uses_flipped : [], + $aliases->uses_flipped ?? [], null ); diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index bd8ad77d2..7f58038ed 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -55,7 +55,6 @@ use function getcwd; use function glob; use function implode; use function in_array; -use function intval; use function is_a; use function is_dir; use function is_file; @@ -80,7 +79,6 @@ use function strlen; use function strpos; use function strrpos; use function strtolower; -use function strtr; use function substr; use function substr_count; use function sys_get_temp_dir; @@ -182,7 +180,7 @@ class Config * * @var bool|null */ - public $load_xdebug_stub = null; + public $load_xdebug_stub; /** * The directory to store PHP Parser (and other) caches @@ -288,7 +286,7 @@ class Config /** * @var ?bool */ - public $show_mixed_issues = null; + public $show_mixed_issues; /** @var bool */ public $strict_binary_operands = false; @@ -501,7 +499,7 @@ class Config public $hash = ''; /** @var string|null */ - public $error_baseline = null; + public $error_baseline; /** * @var bool @@ -978,7 +976,7 @@ class Config } if (isset($config_xml['maxStringLength'])) { - $attribute_text = intval($config_xml['maxStringLength']); + $attribute_text = (int)$config_xml['maxStringLength']; $config->max_string_length = $attribute_text; } @@ -2115,7 +2113,7 @@ class Config $psr4_prefixes = $this->composer_class_loader->getPrefixesPsr4(); // PSR-4 lookup - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . '.php'; + $logicalPathPsr4 = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; $candidate_path = null; @@ -2200,11 +2198,7 @@ class Config public function getPhpVersion(): ?string { - if (isset($this->configured_php_version)) { - return $this->configured_php_version; - } - - return $this->getPHPVersionFromComposerJson(); + return $this->configured_php_version ?? $this->getPHPVersionFromComposerJson(); } private function setBooleanAttribute(string $name, bool $value): void diff --git a/src/Psalm/Config/Creator.php b/src/Psalm/Config/Creator.php index 6ddf8a7a2..e54294888 100644 --- a/src/Psalm/Config/Creator.php +++ b/src/Psalm/Config/Creator.php @@ -76,13 +76,11 @@ class Creator ); } - $template = str_replace( + return str_replace( 'errorLevel="1"', 'errorLevel="' . $level . '"', $template ); - - return $template; } public static function createBareConfig( diff --git a/src/Psalm/Config/ProjectFileFilter.php b/src/Psalm/Config/ProjectFileFilter.php index 6899e435d..dc03681f0 100644 --- a/src/Psalm/Config/ProjectFileFilter.php +++ b/src/Psalm/Config/ProjectFileFilter.php @@ -11,7 +11,7 @@ class ProjectFileFilter extends FileFilter /** * @var ProjectFileFilter|null */ - private $file_filter = null; + private $file_filter; /** * @return static diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index 97c5564b3..34c74cabc 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -103,7 +103,7 @@ class Context /** * @var null|CodeLocation */ - public $include_location = null; + public $include_location; /** * @var string|null @@ -194,7 +194,7 @@ class Context * * @var array|null */ - public $initialized_methods = null; + public $initialized_methods; /** * @var array @@ -290,27 +290,27 @@ class Context /** * @var Internal\Scope\LoopScope|null */ - public $loop_scope = null; + public $loop_scope; /** * @var Internal\Scope\CaseScope|null */ - public $case_scope = null; + public $case_scope; /** * @var Internal\Scope\FinallyScope|null */ - public $finally_scope = null; + public $finally_scope; /** * @var Context|null */ - public $if_context = null; + public $if_context; /** * @var \Psalm\Internal\Scope\IfScope|null */ - public $if_scope = null; + public $if_scope; /** * @var bool @@ -418,7 +418,7 @@ class Context ? $end_context->vars_in_scope[$var_id] : null; - $existing_type = isset($this->vars_in_scope[$var_id]) ? $this->vars_in_scope[$var_id] : null; + $existing_type = $this->vars_in_scope[$var_id] ?? null; if (!$existing_type) { if ($new_type) { diff --git a/src/Psalm/DocComment.php b/src/Psalm/DocComment.php index e4b2f53bc..bb0fb86ea 100644 --- a/src/Psalm/DocComment.php +++ b/src/Psalm/DocComment.php @@ -16,6 +16,7 @@ use function rtrim; use function str_repeat; use function str_replace; use function strlen; +use function strpos; use function strspn; use function substr; use function trim; @@ -156,7 +157,7 @@ class DocComment $docblock = preg_replace('/^\s*\n/', '', $docblock); foreach ($special as $special_key => $_) { - if (substr($special_key, 0, 6) === 'psalm-') { + if (strpos($special_key, 'psalm-') === 0) { $special_key = substr($special_key, 6); if (!in_array( @@ -186,7 +187,7 @@ class DocComment ); foreach ($parsed_docblock->tags as $special_key => $_) { - if (substr($special_key, 0, 6) === 'psalm-') { + if (strpos($special_key, 'psalm-') === 0) { $special_key = substr($special_key, 6); if (!in_array( diff --git a/src/Psalm/FileManipulation.php b/src/Psalm/FileManipulation.php index 891f02dac..e94489fe5 100644 --- a/src/Psalm/FileManipulation.php +++ b/src/Psalm/FileManipulation.php @@ -55,7 +55,7 @@ class FileManipulation $indentation = substr($existing_contents, $newline_pos, $this->start - $newline_pos); if (trim($indentation) === '') { - $this->insertion_text = $this->insertion_text . $indentation; + $this->insertion_text .= $indentation; } } diff --git a/src/Psalm/Internal/Analyzer/CanAlias.php b/src/Psalm/Internal/Analyzer/CanAlias.php index eaa47fd21..573125b8c 100644 --- a/src/Psalm/Internal/Analyzer/CanAlias.php +++ b/src/Psalm/Internal/Analyzer/CanAlias.php @@ -47,7 +47,7 @@ trait CanAlias foreach ($stmt->uses as $use) { $use_path = implode('\\', $use->name->parts); - $use_alias = $use->alias ? $use->alias->name : $use->name->getLast(); + $use_alias = $use->alias->name ?? $use->name->getLast(); switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $stmt->type) { case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION: @@ -107,7 +107,7 @@ trait CanAlias foreach ($stmt->uses as $use) { $use_path = $use_prefix . '\\' . implode('\\', $use->name->parts); - $use_alias = $use->alias ? $use->alias->name : $use->name->getLast(); + $use_alias = $use->alias->name ?? $use->name->getLast(); switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $stmt->type) { case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION: diff --git a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php index 5cd72ec1f..0d5116bc8 100644 --- a/src/Psalm/Internal/Analyzer/ClassAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassAnalyzer.php @@ -368,7 +368,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer $this->fq_class_name . ', defined abstract in ' . $declaring_class_name, new CodeLocation( $this, - $class->name ? $class->name : $class, + $class->name ?? $class, $class_context->include_location, true ) @@ -984,7 +984,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer return; } - $fq_class_name = $class_context->self ? $class_context->self : $this->fq_class_name; + $fq_class_name = $class_context->self ?: $this->fq_class_name; $fq_class_name_lc = strtolower($fq_class_name); $included_file_path = $this->getFilePath(); @@ -1913,9 +1913,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer ); } - $overridden_method_ids = isset($class_storage->overridden_method_ids[strtolower($stmt->name->name)]) - ? $class_storage->overridden_method_ids[strtolower($stmt->name->name)] - : []; + $overridden_method_ids = $class_storage->overridden_method_ids[strtolower($stmt->name->name)] ?? []; if (!$return_type && !$class_storage->is_interface @@ -2276,7 +2274,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer $code_location = new CodeLocation( $this, - $class->name ? $class->name : $class, + $class->name ?? $class, $class_context->include_location, true ); @@ -2488,7 +2486,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer $code_location = new CodeLocation( $this, $extended_class, - $class_context ? $class_context->include_location : null, + $class_context->include_location ?? null, true ); @@ -2592,7 +2590,7 @@ class ClassAnalyzer extends ClassLikeAnalyzer $code_location = new CodeLocation( $this, $class->name ?: $class, - $class_context ? $class_context->include_location : null, + $class_context->include_location ?? null, true ); diff --git a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php index f1b66b95e..622cf8b15 100644 --- a/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ClassLikeAnalyzer.php @@ -454,7 +454,7 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer public function getClassName(): ?string { - return $this->class->name ? $this->class->name->name : null; + return $this->class->name->name ?? null; } /** @@ -580,22 +580,17 @@ abstract class ClassLikeAnalyzer extends SourceAnalyzer return $emit_issues ? null : true; case self::VISIBILITY_PRIVATE: - if (!$context->self || $appearing_property_class !== $context->self) { - if ($emit_issues && IssueBuffer::accepts( - new InaccessibleProperty( - 'Cannot access private property ' . $property_id . ' from context ' . $context->self, - $code_location - ), - $suppressed_issues - )) { - // fall through - } - - return null; + if ($emit_issues && IssueBuffer::accepts( + new InaccessibleProperty( + 'Cannot access private property ' . $property_id . ' from context ' . $context->self, + $code_location + ), + $suppressed_issues + )) { + // fall through } - return $emit_issues ? null : true; - + return null; case self::VISIBILITY_PROTECTED: if (!$context->self) { if ($emit_issues && IssueBuffer::accepts( diff --git a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php index c0d39267a..eb0d8e49a 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLike/ReturnTypeAnalyzer.php @@ -41,8 +41,8 @@ use Psalm\Type; use function array_diff; use function count; use function in_array; +use function strpos; use function strtolower; -use function substr; /** * @internal @@ -109,7 +109,7 @@ class ReturnTypeAnalyzer $is_to_string = $function instanceof ClassMethod && strtolower($function->name->name) === '__tostring'; if ($function instanceof ClassMethod - && substr($function->name->name, 0, 2) === '__' + && strpos($function->name->name, '__') === 0 && !$is_to_string && !$return_type ) { @@ -170,7 +170,7 @@ class ReturnTypeAnalyzer $function_always_exits = $control_actions === [ScopeAnalyzer::ACTION_END]; - $function_returns_implicitly = !!array_diff( + $function_returns_implicitly = (bool)array_diff( $control_actions, [ScopeAnalyzer::ACTION_END, ScopeAnalyzer::ACTION_RETURN] ); @@ -748,8 +748,8 @@ class ReturnTypeAnalyzer $fleshed_out_return_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $storage->return_type, - $classlike_storage ? $classlike_storage->name : null, - $classlike_storage ? $classlike_storage->name : null, + $classlike_storage->name ?? null, + $classlike_storage->name ?? null, $parent_class ); @@ -770,8 +770,8 @@ class ReturnTypeAnalyzer $fleshed_out_signature_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $storage->signature_return_type, - $classlike_storage ? $classlike_storage->name : null, - $classlike_storage ? $classlike_storage->name : null, + $classlike_storage->name ?? null, + $classlike_storage->name ?? null, $parent_class ); @@ -792,8 +792,8 @@ class ReturnTypeAnalyzer $fleshed_out_return_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $storage->return_type, - $classlike_storage ? $classlike_storage->name : null, - $classlike_storage ? $classlike_storage->name : null, + $classlike_storage->name ?? null, + $classlike_storage->name ?? null, $parent_class, true, true @@ -936,7 +936,7 @@ class ReturnTypeAnalyzer true ), $inferred_return_type->canBeFullyExpressedInPhp($codebase->php_major_version, $codebase->php_minor_version), - $function_like_storage ? $function_like_storage->return_type_description : null + $function_like_storage->return_type_description ?? null ); } } diff --git a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php index 524a204ca..0cf5923e0 100644 --- a/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/FunctionLikeAnalyzer.php @@ -1624,16 +1624,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer return []; } - public function getFQCLN(): ?string - { - return $this->source->getFQCLN(); - } - - public function getClassName(): ?string - { - return $this->source->getClassName(); - } - /** * @return array>|null */ @@ -1647,16 +1637,6 @@ abstract class FunctionLikeAnalyzer extends SourceAnalyzer return $this->storage->template_types; } - public function getParentFQCLN(): ?string - { - return $this->source->getParentFQCLN(); - } - - public function getNodeTypeProvider() : \Psalm\NodeTypeProvider - { - return $this->source->getNodeTypeProvider(); - } - public function isStatic(): bool { return $this->is_static; diff --git a/src/Psalm/Internal/Analyzer/MethodComparator.php b/src/Psalm/Internal/Analyzer/MethodComparator.php index 977f23448..154cb460f 100644 --- a/src/Psalm/Internal/Analyzer/MethodComparator.php +++ b/src/Psalm/Internal/Analyzer/MethodComparator.php @@ -26,8 +26,8 @@ use Psalm\Storage\MethodStorage; use Psalm\Type; use function in_array; +use function strpos; use function strtolower; -use function substr; class MethodComparator { @@ -412,7 +412,7 @@ class MethodComparator && $implementer_classlike_storage->user_defined && $implementer_param->location && $guide_method_storage->cased_name - && substr($guide_method_storage->cased_name, 0, 2) !== '__' + && strpos($guide_method_storage->cased_name, '__') !== 0 && $config->isInProjectDirs( $implementer_param->location->file_path ) diff --git a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php index 8dcb978bd..ad7eb1b46 100644 --- a/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/ProjectAnalyzer.php @@ -660,7 +660,7 @@ class ProjectAnalyzer $this->codebase->classlikes->consolidateAnalyzedData( $this->codebase->methods, $this->progress, - !!$this->codebase->find_unused_code + (bool)$this->codebase->find_unused_code ); } @@ -688,7 +688,7 @@ class ProjectAnalyzer && $destination_pos === (strlen($destination) - 1) ) { foreach ($this->codebase->classlike_storage_provider->getAll() as $class_storage) { - if (substr($class_storage->name, 0, $source_pos) === substr($source, 0, -1)) { + if (strpos($source, substr($class_storage->name, 0, $source_pos)) === 0) { $this->to_refactor[$class_storage->name] = substr($destination, 0, -1) . substr($class_storage->name, $source_pos); } @@ -1334,13 +1334,11 @@ class ProjectAnalyzer $file_path = $this->codebase->scanner->getClassLikeFilePath($fq_class_name_lc); - $file_analyzer = new FileAnalyzer( + return new FileAnalyzer( $this, $file_path, $this->config->shortenFileName($file_path) ); - - return $file_analyzer; } public function getMethodMutations( diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php index 124381ebd..713de3d8d 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/ForeachAnalyzer.php @@ -250,7 +250,7 @@ class ForeachAnalyzer $foreach_context->branch_point ?: (int) $stmt->getAttribute('startFilePos'); } - if ($stmt->keyVar && $stmt->keyVar instanceof PhpParser\Node\Expr\Variable && is_string($stmt->keyVar->name)) { + if ($stmt->keyVar instanceof PhpParser\Node\Expr\Variable && is_string($stmt->keyVar->name)) { $key_type = $key_type ?: Type::getMixed(); AssignmentAnalyzer::analyze( diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php index de9a01690..9ff0bda05 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php @@ -159,7 +159,7 @@ class ElseIfAnalyzer if (array_filter( $entry_clauses, function ($clause): bool { - return !!$clause->possibilities; + return (bool)$clause->possibilities; } )) { $omit_keys = array_reduce( diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php index 24cf46aac..ac8e7e55d 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/IfAnalyzer.php @@ -139,7 +139,7 @@ class IfAnalyzer $if_scope->reasonable_clauses = Context::filterClauses( $var_id, $if_scope->reasonable_clauses, - isset($if_context->vars_in_scope[$var_id]) ? $if_context->vars_in_scope[$var_id] : null, + $if_context->vars_in_scope[$var_id] ?? null, $statements_analyzer ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php index 93241c267..26de808b9 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElseAnalyzer.php @@ -234,7 +234,7 @@ class IfElseAnalyzer if (array_filter( $context->clauses, function ($clause): bool { - return !!$clause->possibilities; + return (bool)$clause->possibilities; } )) { $omit_keys = array_reduce( @@ -449,9 +449,7 @@ class IfElseAnalyzer $if_scope->reasonable_clauses = Context::filterClauses( $var_id, $if_scope->reasonable_clauses, - isset($context->vars_in_scope[$var_id]) - ? $context->vars_in_scope[$var_id] - : null, + $context->vars_in_scope[$var_id] ?? null, $statements_analyzer ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php index bbedadc6c..1a7afc01e 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/SwitchCaseAnalyzer.php @@ -39,6 +39,7 @@ use function array_merge; use function count; use function in_array; use function is_string; +use function strpos; use function substr; /** @@ -82,7 +83,7 @@ class SwitchCaseAnalyzer $fake_switch_condition = false; - if ($switch_var_id && substr($switch_var_id, 0, 15) === '$__tmp_switch__') { + if ($switch_var_id && strpos($switch_var_id, '$__tmp_switch__') === 0) { $switch_condition = new VirtualVariable( substr($switch_var_id, 1), $stmt->cond->getAttributes() @@ -402,7 +403,7 @@ class SwitchCaseAnalyzer $case_context->inside_loop, new CodeLocation( $statements_analyzer->getSource(), - $case->cond ? $case->cond : $case, + $case->cond ?? $case, $context->include_location ) ); diff --git a/src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php index 97c2246fb..2295dff5c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/BreakAnalyzer.php @@ -21,10 +21,7 @@ class BreakAnalyzer if ($loop_scope) { if ($context->break_types && \end($context->break_types) === 'switch' - && (!$stmt->num - || !$stmt->num instanceof PhpParser\Node\Scalar\LNumber - || $stmt->num->value < 2 - ) + && (!$stmt->num instanceof PhpParser\Node\Scalar\LNumber || $stmt->num->value < 2) ) { $loop_scope->final_actions[] = ScopeAnalyzer::ACTION_LEAVE_SWITCH; } else { diff --git a/src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php index 49759c6a4..f13daeec0 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ContinueAnalyzer.php @@ -17,10 +17,7 @@ class ContinueAnalyzer PhpParser\Node\Stmt\Continue_ $stmt, Context $context ): void { - $count = $stmt->num - && $stmt->num instanceof PhpParser\Node\Scalar\LNumber - ? $stmt->num->value - : 1; + $count = $stmt->num instanceof PhpParser\Node\Scalar\LNumber? $stmt->num->value : 1; $loop_scope = $context->loop_scope; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php index 2a1b9d4f8..c1ccd6a27 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssertionFinder.php @@ -133,7 +133,7 @@ class AssertionFinder $this_class_name, $source, $codebase, - false, + false, //should this be $inside_negation?? $cache, $inside_conditional ); @@ -147,7 +147,7 @@ class AssertionFinder $this_class_name, $source, $codebase, - false, + false, //should this be $inside_negation?? $cache, $inside_conditional ); @@ -2114,7 +2114,7 @@ class AssertionFinder ?Codebase $codebase, bool $inside_negation, int $false_position - ) { + ): array { $if_types = []; if ($false_position === self::ASSIGNMENT_TO_RIGHT) { @@ -2492,7 +2492,7 @@ class AssertionFinder $if_types[$var_name] = [['!=object']]; } elseif ($var_type === 'resource (closed)') { $if_types[$var_name] = [['!closed-resource']]; - } elseif (substr($var_type, 0, 10) === 'resource (') { + } elseif (strpos($var_type, 'resource (') === 0) { $if_types[$var_name] = [['!=resource']]; } else { $if_types[$var_name] = [['!' . $var_type]]; @@ -2550,7 +2550,7 @@ class AssertionFinder $if_types[$var_name] = [['!=object']]; } elseif ($var_type === 'resource (closed)') { $if_types[$var_name] = [['!closed-resource']]; - } elseif (substr($var_type, 0, 10) === 'resource (') { + } elseif (strpos($var_type, 'resource (') === 0) { $if_types[$var_name] = [['!=resource']]; } else { $if_types[$var_name] = [['!' . $var_type]]; @@ -2807,7 +2807,7 @@ class AssertionFinder bool $inside_negation, bool $cache, int $true_position - ) { + ): array { $if_types = []; if ($true_position === self::ASSIGNMENT_TO_RIGHT) { @@ -3173,7 +3173,7 @@ class AssertionFinder $if_types[$var_name] = [['=object']]; } elseif ($var_type === 'resource (closed)') { $if_types[$var_name] = [['closed-resource']]; - } elseif (substr($var_type, 0, 10) === 'resource (') { + } elseif (strpos($var_type, 'resource (') === 0) { $if_types[$var_name] = [['=resource']]; } else { $if_types[$var_name] = [[$var_type]]; @@ -3231,7 +3231,7 @@ class AssertionFinder $if_types[$var_name] = [['=object']]; } elseif ($var_type === 'resource (closed)') { $if_types[$var_name] = [['closed-resource']]; - } elseif (substr($var_type, 0, 10) === 'resource (') { + } elseif (strpos($var_type, 'resource (') === 0) { $if_types[$var_name] = [['=resource']]; } else { $if_types[$var_name] = [[$var_type]]; @@ -3418,7 +3418,7 @@ class AssertionFinder if ($first_var_name) { $first_arg = $expr->args[0]->value; $second_arg = $expr->args[1]->value; - $third_arg = isset($expr->args[2]->value) ? $expr->args[2]->value : null; + $third_arg = $expr->args[2]->value ?? null; if ($third_arg instanceof PhpParser\Node\Expr\ConstFetch) { if (!in_array(strtolower($third_arg->name->parts[0]), ['true', 'false'])) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php index 02a0c287f..07a61a267 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/AssignmentAnalyzer.php @@ -62,7 +62,6 @@ use function is_string; use function reset; use function strpos; use function strtolower; -use function substr; /** * @internal @@ -232,8 +231,7 @@ class AssignmentAnalyzer if ($comment_type && $comment_type_location) { $temp_assign_value_type = $assign_value_type - ? $assign_value_type - : ($assign_value ? $statements_analyzer->node_data->getType($assign_value) : null); + ?? ($assign_value ? $statements_analyzer->node_data->getType($assign_value) : null); if ($codebase->find_unused_variables && $temp_assign_value_type @@ -361,7 +359,7 @@ class AssignmentAnalyzer if (!$assign_var instanceof PhpParser\Node\Expr\PropertyFetch && !strpos($root_var_id ?? '', '->') && !$comment_type - && substr($var_id ?? '', 0, 2) !== '$_' + && strpos($var_id ?? '', '$_') !== 0 ) { $origin_locations = []; @@ -1350,9 +1348,8 @@ class AssignmentAnalyzer $can_be_empty = !$assign_value_atomic_type instanceof Type\Atomic\TNonEmptyList; } elseif ($assign_value_atomic_type instanceof Type\Atomic\TKeyedArray) { - if ($assign_var_item->key - && ($assign_var_item->key instanceof PhpParser\Node\Scalar\String_ - || $assign_var_item->key instanceof PhpParser\Node\Scalar\LNumber) + if (($assign_var_item->key instanceof PhpParser\Node\Scalar\String_ + || $assign_var_item->key instanceof PhpParser\Node\Scalar\LNumber) && isset($assign_value_atomic_type->properties[$assign_var_item->key->value]) ) { $new_assign_type = diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/BitwiseNotAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/BitwiseNotAnalyzer.php index 74a2e04d3..25e183d99 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/BitwiseNotAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/BitwiseNotAnalyzer.php @@ -100,8 +100,7 @@ class BitwiseNotAnalyzer private static function addDataFlow( StatementsAnalyzer $statements_analyzer, PhpParser\Node\Expr $stmt, - PhpParser\Node\Expr $value, - string $type = 'bitwisenot' + PhpParser\Node\Expr $value ): void { $result_type = $statements_analyzer->node_data->getType($stmt); if ($statements_analyzer->data_flow_graph instanceof VariableUseGraph && $result_type) { @@ -109,7 +108,7 @@ class BitwiseNotAnalyzer $stmt_value_type = $statements_analyzer->node_data->getType($value); - $new_parent_node = DataFlowNode::getForAssignment($type, $var_location); + $new_parent_node = DataFlowNode::getForAssignment('bitwisenot', $var_location); $statements_analyzer->data_flow_graph->addNode($new_parent_node); $result_type->parent_nodes = [ $new_parent_node->id => $new_parent_node, @@ -117,7 +116,7 @@ class BitwiseNotAnalyzer if ($stmt_value_type && $stmt_value_type->parent_nodes) { foreach ($stmt_value_type->parent_nodes as $parent_node) { - $statements_analyzer->data_flow_graph->addPath($parent_node, $new_parent_node, $type); + $statements_analyzer->data_flow_graph->addPath($parent_node, $new_parent_node, 'bitwisenot'); } } } diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php index e4c51bec0..22b65571a 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentAnalyzer.php @@ -253,12 +253,12 @@ class ArgumentAnalyzer $param_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $param_type, - $classlike_storage ? $classlike_storage->name : null, - $static_classlike_storage ? $static_classlike_storage->name : null, + $classlike_storage->name ?? null, + $static_classlike_storage->name ?? null, $parent_class, true, false, - $static_classlike_storage ? $static_classlike_storage->final : false, + $static_classlike_storage->final ?? false, true ); @@ -384,12 +384,12 @@ class ArgumentAnalyzer $param_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $param_type, - $classlike_storage ? $classlike_storage->name : null, - $static_classlike_storage ? $static_classlike_storage->name : null, + $classlike_storage->name ?? null, + $static_classlike_storage->name ?? null, $parent_class, true, false, - $static_classlike_storage ? $static_classlike_storage->final : false, + $static_classlike_storage->final ?? false, true ); } @@ -398,8 +398,8 @@ class ArgumentAnalyzer ? \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $function_param->signature_type, - $classlike_storage ? $classlike_storage->name : null, - $static_classlike_storage ? $static_classlike_storage->name : null, + $classlike_storage->name ?? null, + $static_classlike_storage->name ?? null, $parent_class ) : null; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 5cfba7e5e..454bdb0c3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -70,8 +70,7 @@ class ArgumentsAnalyzer : null; // if this modifies the array type based on further args - if ($method_id - && in_array($method_id, ['array_push', 'array_unshift'], true) + if (in_array($method_id, ['array_push', 'array_unshift'], true) && $function_params && isset($args[0]) && isset($args[1]) @@ -89,7 +88,7 @@ class ArgumentsAnalyzer return null; } - if ($method_id && $method_id === 'array_splice' && $function_params && count($args) > 1) { + if ($method_id === 'array_splice' && $function_params && count($args) > 1) { if (ArrayFunctionArgumentsAnalyzer::handleSplice($statements_analyzer, $args, $context) === false) { return false; } @@ -620,7 +619,7 @@ class ArgumentsAnalyzer $function_params[$i], $i, $i, - $function_storage ? $function_storage->allow_named_arg_calls : true, + $function_storage->allow_named_arg_calls ?? true, new VirtualArg( StubsGenerator::getExpressionFromType($default_type) ), @@ -628,7 +627,7 @@ class ArgumentsAnalyzer $context, $class_generic_params, $template_result, - $function_storage ? $function_storage->specialize_call : true, + $function_storage->specialize_call ?? true, $in_call_map ); } @@ -796,13 +795,13 @@ class ArgumentsAnalyzer $function_param, $argument_offset + $i, $i, - $function_storage ? $function_storage->allow_named_arg_calls : true, + $function_storage->allow_named_arg_calls ?? true, $arg, $arg_value_type, $context, $class_generic_params, $template_result, - $function_storage ? $function_storage->specialize_call : true, + $function_storage->specialize_call ?? true, $in_call_map ) === false) { return false; @@ -1364,12 +1363,12 @@ class ArgumentsAnalyzer $fleshed_out_param_type = \Psalm\Internal\Type\TypeExpander::expandUnion( $codebase, $function_param->type, - $class_storage ? $class_storage->name : null, - $calling_class_storage ? $calling_class_storage->name : null, + $class_storage->name ?? null, + $calling_class_storage->name ?? null, null, true, false, - $calling_class_storage ? $calling_class_storage->final : false + $calling_class_storage->final ?? false ); TemplateStandinTypeReplacer::replace( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php index 70aa20b5f..0239bc9b2 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArrayFunctionArgumentsAnalyzer.php @@ -88,7 +88,7 @@ class ArrayFunctionArgumentsAnalyzer $array_arg_types[] = $array_arg_type; } - $closure_arg = isset($args[$closure_index]) ? $args[$closure_index] : null; + $closure_arg = $args[$closure_index] ?? null; $closure_arg_type = null; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php index 4c43208d3..9beaff738 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallAnalyzer.php @@ -352,7 +352,7 @@ class FunctionCallAnalyzer extends CallAnalyzer PhpParser\Node\Name $function_name, Context $context, CodeLocation $code_location - ) { + ): FunctionCallInfo { $function_call_info = new FunctionCallInfo(); $codebase = $statements_analyzer->getCodebase(); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallInfo.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallInfo.php index c27baff25..70a193e8c 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallInfo.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallInfo.php @@ -12,12 +12,12 @@ class FunctionCallInfo /** * @var ?string */ - public $function_id = null; + public $function_id; /** * @var ?bool */ - public $function_exists = null; + public $function_exists; /** * @var bool @@ -42,17 +42,17 @@ class FunctionCallInfo /** * @var ?array */ - public $function_params = null; + public $function_params; /** * @var ?\Psalm\Storage\FunctionLikeStorage */ - public $function_storage = null; + public $function_storage; /** * @var ?PhpParser\Node\Name */ - public $new_function_name = null; + public $new_function_name; /** * @var bool diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php index 1829db052..1da0a3893 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/FunctionCallReturnTypeFetcher.php @@ -222,7 +222,7 @@ class FunctionCallReturnTypeFetcher $fake_call_factory = new BuilderFactory(); if (strpos($proxy_call['fqn'], '::') !== false) { - list($fqcn, $method) = explode('::', $proxy_call['fqn']); + [$fqcn, $method] = explode('::', $proxy_call['fqn']); $fake_call = $fake_call_factory->staticCall($fqcn, $method, $fake_call_arguments); } else { $fake_call = $fake_call_factory->funcCall($proxy_call['fqn'], $fake_call_arguments); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php index ab58381d3..eb187adf3 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php @@ -660,7 +660,7 @@ class AtomicMethodCallAnalyzer extends CallAnalyzer PhpParser\Node\Expr\MethodCall $stmt, StatementsAnalyzer $statements_analyzer, string $fq_class_name - ) { + ): array { $naive_method_exists = false; if ($class_storage->templatedMixins @@ -749,7 +749,7 @@ class AtomicMethodCallAnalyzer extends CallAnalyzer StatementsAnalyzer $statements_analyzer, string $fq_class_name, ?string $lhs_var_id - ) { + ): array { $naive_method_exists = false; foreach ($class_storage->namedMixins as $mixin) { diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php index e92174acb..e1d790932 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/ExistingAtomicMethodCallAnalyzer.php @@ -103,9 +103,7 @@ class ExistingAtomicMethodCallAnalyzer extends CallAnalyzer $context ); - $function_return = $statements_analyzer->node_data->getType($fake_function_call) ?: Type::getMixed(); - - return $function_return; + return $statements_analyzer->node_data->getType($fake_function_call) ?: Type::getMixed(); } $source = $statements_analyzer->getSource(); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodVisibilityAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodVisibilityAnalyzer.php index 803e902b5..51a99a1fc 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodVisibilityAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodVisibilityAnalyzer.php @@ -127,10 +127,7 @@ class MethodVisibilityAnalyzer // Oldest ancestor is at end of array $oldest_ancestor_declaring_method_id = array_pop($overridden_method_ids); } - $oldest_ancestor_declaring_method_class = null; - if ($oldest_ancestor_declaring_method_id) { - $oldest_ancestor_declaring_method_class = $oldest_ancestor_declaring_method_id->fq_class_name; - } + $oldest_ancestor_declaring_method_class = $oldest_ancestor_declaring_method_id->fq_class_name ?? null; switch ($visibility) { case ClassLikeAnalyzer::VISIBILITY_PUBLIC: diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php index af3fd3be9..73c271193 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php @@ -60,10 +60,10 @@ class NamedFunctionCallHandler return; } - $first_arg = isset($stmt->args[0]) ? $stmt->args[0] : null; + $first_arg = $stmt->args[0] ?? null; if ($function_id === 'method_exists') { - $second_arg = isset($stmt->args[1]) ? $stmt->args[1] : null; + $second_arg = $stmt->args[1] ?? null; if ($first_arg && $first_arg->value instanceof PhpParser\Node\Expr\Variable @@ -223,9 +223,7 @@ class NamedFunctionCallHandler if ($function_id === 'func_get_args') { $source = $statements_analyzer->getSource(); - if ($statements_analyzer->data_flow_graph - && $source instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer - ) { + if ($source instanceof \Psalm\Internal\Analyzer\FunctionLikeAnalyzer) { if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph) { foreach ($source->param_nodes as $param_node) { $statements_analyzer->data_flow_graph->addPath( @@ -332,17 +330,13 @@ class NamedFunctionCallHandler ) { $stmt_assertions = $statements_analyzer->node_data->getAssertions($stmt); - if ($stmt_assertions !== null) { - $anded_assertions = $stmt_assertions; - } else { - $anded_assertions = AssertionFinder::processFunctionCall( - $stmt, - $context->self, - $statements_analyzer, - $codebase, - $context->inside_negation - ); - } + $anded_assertions = $stmt_assertions ?? AssertionFinder::processFunctionCall( + $stmt, + $context->self, + $statements_analyzer, + $codebase, + $context->inside_negation + ); $changed_vars = []; @@ -442,7 +436,7 @@ class NamedFunctionCallHandler string $function_id, Context $context ) : void { - $first_arg = isset($stmt->args[0]) ? $stmt->args[0] : null; + $first_arg = $stmt->args[0] ?? null; if ($first_arg) { $var = $first_arg->value; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php index 1b94c2abf..28d16d3f1 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CallAnalyzer.php @@ -191,17 +191,12 @@ class CallAnalyzer || $is_final) ) { $local_vars_in_scope = []; - $local_vars_possibly_in_scope = []; foreach ($context->vars_in_scope as $var_id => $type) { if (strpos($var_id, '$this->') === 0) { if ($type->initialized) { $local_vars_in_scope[$var_id] = $context->vars_in_scope[$var_id]; - if (isset($context->vars_possibly_in_scope[$var_id])) { - $local_vars_possibly_in_scope[$var_id] = $context->vars_possibly_in_scope[$var_id]; - } - unset($context->vars_in_scope[$var_id]); unset($context->vars_possibly_in_scope[$var_id]); } @@ -320,7 +315,7 @@ class CallAnalyzer $args, $method_params, (string) $method_id, - $method_storage ? $method_storage->allow_named_arg_calls : true, + $method_storage->allow_named_arg_calls ?? true, $context, $class_template_result ) === false) { @@ -419,11 +414,11 @@ class CallAnalyzer $codebase, $type, $appearing_class_name, - $calling_class_storage ? $calling_class_storage->name : null, + $calling_class_storage->name ?? null, null, true, false, - $calling_class_storage ? $calling_class_storage->final : false + $calling_class_storage->final ?? false ); } } @@ -1032,7 +1027,7 @@ class CallAnalyzer $bounds_with_equality = array_filter( $lower_bounds, function ($lower_bound) { - return !!$lower_bound->equality_bound_classlike; + return (bool)$lower_bound->equality_bound_classlike; } ); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php index 81c2f902c..a2cc39f97 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/CastAnalyzer.php @@ -66,8 +66,7 @@ class CastAnalyzer new Type\Atomic\TLiteralInt(1), ]); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { $type->parent_nodes = $maybe_type->parent_nodes; } @@ -79,10 +78,9 @@ class CastAnalyzer if ($as_int) { $type = $valid_int_type ?? Type::getInt(); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; + $type->parent_nodes = $maybe_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); @@ -106,10 +104,9 @@ class CastAnalyzer $type = Type::getFloat(); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; + $type->parent_nodes = $maybe_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); @@ -132,10 +129,9 @@ class CastAnalyzer $type = Type::getBool(); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; + $type->parent_nodes = $maybe_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); @@ -183,10 +179,9 @@ class CastAnalyzer $maybe_type = $statements_analyzer->node_data->getType($stmt->expr); - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $maybe_type ? $maybe_type->parent_nodes : []; + $type->parent_nodes = $maybe_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); @@ -237,10 +232,9 @@ class CastAnalyzer $type = Type::getArray(); } - if ($statements_analyzer->data_flow_graph - && $statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph + if ($statements_analyzer->data_flow_graph instanceof \Psalm\Internal\Codebase\VariableUseGraph ) { - $type->parent_nodes = $stmt_expr_type ? $stmt_expr_type->parent_nodes : []; + $type->parent_nodes = $stmt_expr_type->parent_nodes ?? []; } $statements_analyzer->node_data->setType($stmt, $type); diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php index 75b07f429..d85dc8c71 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ArrayFetchAnalyzer.php @@ -1833,8 +1833,7 @@ class ArrayFetchAnalyzer [ new VirtualArg( $stmt->dim - ? $stmt->dim - : new VirtualConstFetch( + ?? new VirtualConstFetch( new VirtualName('null'), $stmt->var->getAttributes() ) @@ -1957,7 +1956,7 @@ class ArrayFetchAnalyzer if ($type instanceof TSingleLetter) { $valid_offset_type = Type::getInt(false, 0); } elseif ($type instanceof TLiteralString) { - if (!strlen($type->value)) { + if ($type->value === '') { $valid_offset_type = Type::getEmpty(); } elseif (strlen($type->value) < 10) { $valid_offsets = []; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php index de730ff64..7d6cf6db4 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/AtomicPropertyFetchAnalyzer.php @@ -1112,8 +1112,6 @@ class AtomicPropertyFetchAnalyzer $has_magic_getter, $var_id ); - - return; } private static function getClassPropertyType( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php index 36a4fbb6e..a608ab4c7 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/IncludeAnalyzer.php @@ -84,7 +84,7 @@ class IncludeAnalyzer // attempts to resolve using get_include_path dirs $include_path = self::resolveIncludePath($path_to_file, dirname($statements_analyzer->getFilePath())); - $path_to_file = $include_path ? $include_path : $path_to_file; + $path_to_file = $include_path ?: $path_to_file; if (DIRECTORY_SEPARATOR === '/') { $is_path_relative = $path_to_file[0] !== DIRECTORY_SEPARATOR; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php index 32398a8e7..ceb43a8a5 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/SimpleTypeInferer.php @@ -282,9 +282,7 @@ class SimpleTypeInferer } return null; - } catch (\InvalidArgumentException $e) { - return null; - } catch (\Psalm\Exception\CircularReferenceException $e) { + } catch (\InvalidArgumentException | \Psalm\Exception\CircularReferenceException $e) { return null; } } diff --git a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php index 65791d9d7..31c39ba5d 100644 --- a/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/ReturnAnalyzer.php @@ -633,7 +633,7 @@ class ReturnAnalyzer $param->type = self::inferInnerClosureTypeFromParent( $statements_analyzer->getCodebase(), $param->type, - $parent_param ? $parent_param->type : null + $parent_param->type ?? null ); } diff --git a/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php b/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php index 0fa0ca3bb..5d25d735f 100644 --- a/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php +++ b/src/Psalm/Internal/Analyzer/Statements/UnusedAssignmentRemover.php @@ -132,7 +132,7 @@ class UnusedAssignmentRemover $iter = 1; // Check if second token is just whitespace - if (is_array($token_list[$iter]) && strlen(trim($token_list[$iter][1])) === 0) { + if (is_array($token_list[$iter]) && trim($token_list[$iter][1]) === '') { $offset_count += strlen($token_list[1][1]); $iter++; } @@ -146,7 +146,7 @@ class UnusedAssignmentRemover $iter++; // Remove any whitespace following assignment operator token (e.g "=", "+=") - if (is_array($token_list[$iter]) && strlen(trim($token_list[$iter][1])) === 0) { + if (is_array($token_list[$iter]) && trim($token_list[$iter][1]) === '') { $offset_count += strlen($token_list[$iter][1]); $iter++; } @@ -156,7 +156,7 @@ class UnusedAssignmentRemover $offset_count += 1; $iter++; // Handle any whitespace after "&" - if (is_array($token_list[$iter]) && strlen(trim($token_list[$iter][1])) === 0) { + if (is_array($token_list[$iter]) && trim($token_list[$iter][1]) === '') { $offset_count += strlen($token_list[$iter][1]); } } diff --git a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php index 82e0e91f0..553e57498 100644 --- a/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/StatementsAnalyzer.php @@ -55,6 +55,7 @@ use function get_class; use function preg_split; use function round; use function strlen; +use function strpos; use function strrpos; use function strtolower; use function substr; @@ -117,12 +118,12 @@ class StatementsAnalyzer extends SourceAnalyzer /** * @var ParsedDocblock|null */ - private $parsed_docblock = null; + private $parsed_docblock; /** * @var ?string */ - private $fake_this_class = null; + private $fake_this_class; /** @var \Psalm\Internal\Provider\NodeDataProvider */ public $node_data; @@ -557,7 +558,7 @@ class StatementsAnalyzer extends SourceAnalyzer $class_analyzer = new ClassAnalyzer( $stmt, $statements_analyzer->source, - $stmt->name ? $stmt->name->name : null + $stmt->name->name ?? null ); $class_analyzer->analyze(null, $global_context); @@ -755,7 +756,7 @@ class StatementsAnalyzer extends SourceAnalyzer } foreach ($this->unused_var_locations as [$var_id, $original_location]) { - if (substr($var_id, 0, 2) === '$_') { + if (strpos($var_id, '$_') === 0) { continue; } @@ -911,12 +912,12 @@ class StatementsAnalyzer extends SourceAnalyzer */ public function getFirstAppearance(string $var_id): ?CodeLocation { - return isset($this->all_vars[$var_id]) ? $this->all_vars[$var_id] : null; + return $this->all_vars[$var_id] ?? null; } public function getBranchPoint(string $var_id): ?int { - return isset($this->var_branch_points[$var_id]) ? $this->var_branch_points[$var_id] : null; + return $this->var_branch_points[$var_id] ?? null; } public function addVariableInitialization(string $var_id, int $branch_point): void diff --git a/src/Psalm/Internal/Cli/LanguageServer.php b/src/Psalm/Internal/Cli/LanguageServer.php index d6afd30fc..b7d2d58d1 100644 --- a/src/Psalm/Internal/Cli/LanguageServer.php +++ b/src/Psalm/Internal/Cli/LanguageServer.php @@ -27,6 +27,7 @@ use function is_string; use function preg_replace; use function realpath; use function setlocale; +use function strpos; use function strtolower; use function substr; @@ -85,7 +86,7 @@ final class LanguageServer * @param string $arg */ function ($arg) use ($valid_long_options): void { - if (substr($arg, 0, 2) === '--' && $arg !== '--') { + if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); if (!in_array($arg_name, $valid_long_options, true) @@ -309,6 +310,6 @@ HELP; $project_analyzer->language_server_verbose = true; } - $project_analyzer->server($options['tcp'] ?? null, isset($options['tcp-server']) ? true : false); + $project_analyzer->server($options['tcp'] ?? null, isset($options['tcp-server'])); } } diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index b60ba4390..7e80ad592 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -251,7 +251,7 @@ final class Psalm } } - $paths_to_check = CliUtils::getPathsToCheck(isset($options['f']) ? $options['f'] : null); + $paths_to_check = CliUtils::getPathsToCheck($options['f'] ?? null); if ($config->resolve_from_config_file) { $current_dir = $config->base_dir; @@ -420,7 +420,7 @@ final class Psalm * @param string $arg */ function ($arg): void { - if (substr($arg, 0, 2) === '--' && $arg !== '--') { + if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); if (!in_array($arg_name, self::LONG_OPTIONS) @@ -434,7 +434,7 @@ final class Psalm ); exit(1); } - } elseif (substr($arg, 0, 1) === '-' && $arg !== '-' && $arg !== '--') { + } elseif (strpos($arg, '-') === 0 && $arg !== '-' && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 1)); if (!in_array($arg_name, self::SHORT_OPTIONS) diff --git a/src/Psalm/Internal/Cli/Psalter.php b/src/Psalm/Internal/Cli/Psalter.php index c386fd64f..40bd193f3 100644 --- a/src/Psalm/Internal/Cli/Psalter.php +++ b/src/Psalm/Internal/Cli/Psalter.php @@ -201,7 +201,7 @@ HELP; // If Xdebug is enabled, restart without it (new \Composer\XdebugHandler\XdebugHandler('PSALTER'))->check(); - $paths_to_check = CliUtils::getPathsToCheck(isset($options['f']) ? $options['f'] : null); + $paths_to_check = CliUtils::getPathsToCheck($options['f'] ?? null); $path_to_config = CliUtils::getPathToConfig($options); @@ -434,7 +434,7 @@ HELP; * @param string $arg */ function ($arg): void { - if (substr($arg, 0, 2) === '--' && $arg !== '--') { + if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); if ($arg_name === 'alter') { diff --git a/src/Psalm/Internal/Cli/Refactor.php b/src/Psalm/Internal/Cli/Refactor.php index d235c968a..b63ef6d10 100644 --- a/src/Psalm/Internal/Cli/Refactor.php +++ b/src/Psalm/Internal/Cli/Refactor.php @@ -75,7 +75,7 @@ final class Refactor * @param string $arg */ function ($arg) use ($valid_long_options): void { - if (substr($arg, 0, 2) === '--' && $arg !== '--') { + if (strpos($arg, '--') === 0 && $arg !== '--') { $arg_name = preg_replace('/=.*$/', '', substr($arg, 2)); if ($arg_name === 'refactor') { diff --git a/src/Psalm/Internal/CliUtils.php b/src/Psalm/Internal/CliUtils.php index 015f6a34a..821c48ffb 100644 --- a/src/Psalm/Internal/CliUtils.php +++ b/src/Psalm/Internal/CliUtils.php @@ -231,7 +231,7 @@ final class CliUtils if ($f_paths) { $input_paths = is_array($f_paths) ? $f_paths : [$f_paths]; } else { - $input_paths = $argv ? $argv : null; + $input_paths = $argv ?: null; } if ($input_paths) { @@ -264,7 +264,7 @@ final class CliUtils continue; } - if (substr($input_path, 0, 2) === '--' && strlen($input_path) > 2) { + if (strpos($input_path, '--') === 0 && strlen($input_path) > 2) { if (substr($input_path, 2) === 'config') { ++$i; } diff --git a/src/Psalm/Internal/Codebase/Analyzer.php b/src/Psalm/Internal/Codebase/Analyzer.php index 37d3c2940..5797be13a 100644 --- a/src/Psalm/Internal/Codebase/Analyzer.php +++ b/src/Psalm/Internal/Codebase/Analyzer.php @@ -148,7 +148,7 @@ class Analyzer * * @var array|null */ - private $files_to_update = null; + private $files_to_update; /** * @var array> @@ -316,7 +316,7 @@ class Analyzer $project_analyzer->prepareMigration(); - $files_to_update = $this->files_to_update !== null ? $this->files_to_update : $this->files_to_analyze; + $files_to_update = $this->files_to_update ?? $this->files_to_analyze; foreach ($files_to_update as $file_path) { $this->updateFile($file_path, $project_analyzer->dry_run); @@ -345,7 +345,7 @@ class Analyzer $this->progress->debug('Analyzing ' . $file_analyzer->getFilePath() . "\n"); - $file_analyzer->analyze(null); + $file_analyzer->analyze(); $file_analyzer->context = null; $file_analyzer->clearSourceBeforeDestruction(); unset($file_analyzer); diff --git a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php index 99f4345f7..a32fed6f9 100644 --- a/src/Psalm/Internal/Codebase/ConstantTypeResolver.php +++ b/src/Psalm/Internal/Codebase/ConstantTypeResolver.php @@ -134,12 +134,12 @@ class ConstantTypeResolver || $cond instanceof Type\Atomic\TLiteralString ) { if ($cond->value) { - return $if ? $if : $cond; + return $if ?? $cond; } } elseif ($cond instanceof Type\Atomic\TFalse || $cond instanceof Type\Atomic\TNull) { return $else; } elseif ($cond instanceof Type\Atomic\TTrue) { - return $if ? $if : $cond; + return $if ?? $cond; } } diff --git a/src/Psalm/Internal/Codebase/DataFlowGraph.php b/src/Psalm/Internal/Codebase/DataFlowGraph.php index 5d4f9547a..279e4c0e9 100644 --- a/src/Psalm/Internal/Codebase/DataFlowGraph.php +++ b/src/Psalm/Internal/Codebase/DataFlowGraph.php @@ -10,6 +10,7 @@ use function array_merge; use function array_reverse; use function array_sum; use function strlen; +use function strpos; use function substr; abstract class DataFlowGraph @@ -65,7 +66,7 @@ abstract class DataFlowGraph // arraykey-fetch requires a matching arraykey-assignment at the same level // otherwise the tainting is not valid - if (substr($path_type, 0, $el + 7) === $expression_type . '-fetch-' || $path_type === 'arraykey-fetch') { + if (strpos($path_type, $expression_type . '-fetch-') === 0 || $path_type === 'arraykey-fetch') { $fetch_nesting = 0; $previous_path_types = array_reverse($previous_path_types); @@ -79,11 +80,11 @@ abstract class DataFlowGraph $fetch_nesting--; } - if (substr($previous_path_type, 0, $el + 6) === $expression_type . '-fetch') { + if (strpos($previous_path_type, $expression_type . '-fetch') === 0) { $fetch_nesting++; } - if (substr($previous_path_type, 0, $el + 12) === $expression_type . '-assignment-') { + if (strpos($previous_path_type, $expression_type . '-assignment-') === 0) { if ($fetch_nesting > 0) { $fetch_nesting--; continue; diff --git a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php index 57c187a60..f79ef431b 100644 --- a/src/Psalm/Internal/Codebase/InternalCallMapHandler.php +++ b/src/Psalm/Internal/Codebase/InternalCallMapHandler.php @@ -14,6 +14,7 @@ use function assert; use function count; use function dirname; use function file_exists; +use function strpos; use function strtolower; use function substr; use function version_compare; @@ -32,16 +33,16 @@ class InternalCallMapHandler /** * @var ?int */ - private static $loaded_php_major_version = null; + private static $loaded_php_major_version; /** * @var ?int */ - private static $loaded_php_minor_version = null; + private static $loaded_php_minor_version; /** * @var array>|null */ - private static $call_map = null; + private static $call_map; /** * @var array>|null @@ -274,7 +275,7 @@ class InternalCallMapHandler $optional = true; } - if (substr($arg_name, 0, 3) === '...') { + if (strpos($arg_name, '...') === 0) { $arg_name = substr($arg_name, 3); $variadic = true; } diff --git a/src/Psalm/Internal/Codebase/Methods.php b/src/Psalm/Internal/Codebase/Methods.php index 1a928fe7e..2550677b4 100644 --- a/src/Psalm/Internal/Codebase/Methods.php +++ b/src/Psalm/Internal/Codebase/Methods.php @@ -360,7 +360,7 @@ class Methods if (InternalCallMapHandler::inCallMap((string) $callmap_id)) { $class_storage = $this->classlike_storage_provider->get($callmap_id->fq_class_name); - $declaring_method_name = $declaring_method_id ? $declaring_method_id->method_name : $method_name; + $declaring_method_name = $declaring_method_id->method_name ?? $method_name; if (!$class_storage->stubbed || empty($class_storage->methods[$declaring_method_name]->stubbed)) { $function_callables = InternalCallMapHandler::getCallablesFromCallMap((string) $callmap_id); @@ -1060,11 +1060,7 @@ class Methods $method_name = $method_id->method_name; - if (isset($class_storage->appearing_method_ids[$method_name])) { - return $class_storage->appearing_method_ids[$method_name]; - } - - return null; + return $class_storage->appearing_method_ids[$method_name] ?? null; } /** @@ -1075,11 +1071,7 @@ class Methods $class_storage = $this->classlike_storage_provider->get($method_id->fq_class_name); $method_name = $method_id->method_name; - if (isset($class_storage->overridden_method_ids[$method_name])) { - return $class_storage->overridden_method_ids[$method_name]; - } - - return []; + return $class_storage->overridden_method_ids[$method_name] ?? []; } public function getCasedMethodId(MethodIdentifier $original_method_id): string diff --git a/src/Psalm/Internal/Composer.php b/src/Psalm/Internal/Composer.php index 16abe5369..52ac9350a 100644 --- a/src/Psalm/Internal/Composer.php +++ b/src/Psalm/Internal/Composer.php @@ -35,7 +35,7 @@ final class Composer */ public static function getLockFilePath(string $root): string { - $composer_json_path = static::getJsonFilePath($root); + $composer_json_path = self::getJsonFilePath($root); return "json" === pathinfo($composer_json_path, PATHINFO_EXTENSION) ? substr($composer_json_path, 0, -4).'lock' : $composer_json_path . '.lock'; diff --git a/src/Psalm/Internal/ExecutionEnvironment/SystemCommandExecutor.php b/src/Psalm/Internal/ExecutionEnvironment/SystemCommandExecutor.php index a78e3078d..89d0e3e02 100644 --- a/src/Psalm/Internal/ExecutionEnvironment/SystemCommandExecutor.php +++ b/src/Psalm/Internal/ExecutionEnvironment/SystemCommandExecutor.php @@ -24,7 +24,7 @@ final class SystemCommandExecutor { if (!\function_exists('exec')) { throw new \RuntimeException(sprintf('exec does not exist, failed to execute command: %s', $command)); - }; + } exec($command, $result, $returnValue); diff --git a/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php b/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php index e86990cd7..f3c6e3783 100644 --- a/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php +++ b/src/Psalm/Internal/FileManipulation/FileManipulationBuffer.php @@ -169,11 +169,7 @@ class FileManipulationBuffer */ public static function getManipulationsForFile(string $file_path): array { - if (!isset(self::$file_manipulations[$file_path])) { - return []; - } - - return self::$file_manipulations[$file_path]; + return self::$file_manipulations[$file_path] ?? []; } /** diff --git a/src/Psalm/Internal/Fork/Pool.php b/src/Psalm/Internal/Fork/Pool.php index 21ef1e432..c9409f10f 100644 --- a/src/Psalm/Internal/Fork/Pool.php +++ b/src/Psalm/Internal/Fork/Pool.php @@ -21,7 +21,6 @@ use function get_class; use function gettype; use function in_array; use function ini_get; -use function intval; use function pcntl_fork; use function pcntl_waitpid; use function pcntl_wexitstatus; @@ -307,7 +306,7 @@ class Pool // resource id. $streams = []; foreach ($this->read_streams as $stream) { - $streams[intval($stream)] = $stream; + $streams[(int)$stream] = $stream; } // Create an array for the content received on each stream, @@ -340,12 +339,12 @@ class Pool foreach ($needs_read as $file) { $buffer = fread($file, 1024); if ($buffer !== false) { - $content[intval($file)] .= $buffer; + $content[(int)$file] .= $buffer; } if (strpos($buffer, "\n") !== false) { - $serialized_messages = explode("\n", $content[intval($file)]); - $content[intval($file)] = array_pop($serialized_messages); + $serialized_messages = explode("\n", $content[(int)$file]); + $content[(int)$file] = array_pop($serialized_messages); foreach ($serialized_messages as $serialized_message) { $message = unserialize(base64_decode($serialized_message, true)); @@ -375,13 +374,13 @@ class Pool // If the stream has closed, stop trying to select on it. if (feof($file)) { - if ($content[intval($file)] !== '') { + if ($content[(int)$file] !== '') { error_log('Child did not send full message before closing the connection'); $this->did_have_error = true; } fclose($file); - unset($streams[intval($file)]); + unset($streams[(int)$file]); } } } diff --git a/src/Psalm/Internal/LanguageServer/LanguageServer.php b/src/Psalm/Internal/LanguageServer/LanguageServer.php index 90f6c77bf..24703864a 100644 --- a/src/Psalm/Internal/LanguageServer/LanguageServer.php +++ b/src/Psalm/Internal/LanguageServer/LanguageServer.php @@ -220,7 +220,7 @@ class LanguageServer extends AdvancedJsonRpc\Dispatcher $this->verboseLog("Initializing: Registering stub files..."); $this->clientStatus('initializing', 'registering stub files'); - $codebase->config->visitStubFiles($codebase, null); + $codebase->config->visitStubFiles($codebase); if ($this->textDocument === null) { $this->textDocument = new TextDocument( diff --git a/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php b/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php index d982d875e..cde108ce5 100644 --- a/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php +++ b/src/Psalm/Internal/LanguageServer/ProtocolStreamReader.php @@ -37,7 +37,7 @@ class ProtocolStreamReader implements ProtocolReader /** @var string[] */ private $headers = []; /** @var ?int */ - private $content_length = null; + private $content_length; /** @var bool */ private $did_emit_close = false; diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php b/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php index e297ef9f0..315105342 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/AttributeResolver.php @@ -26,24 +26,17 @@ class AttributeResolver ) : AttributeStorage { if ($stmt->name instanceof PhpParser\Node\Name\FullyQualified) { $fq_type_string = (string)$stmt->name; - - $codebase->scanner->queueClassLikeForScanning($fq_type_string); - $file_storage->referenced_classlikes[strtolower($fq_type_string)] = $fq_type_string; } else { $fq_type_string = ClassLikeAnalyzer::getFQCLNFromNameObject($stmt->name, $aliases); - - $codebase->scanner->queueClassLikeForScanning($fq_type_string); - $file_storage->referenced_classlikes[strtolower($fq_type_string)] = $fq_type_string; } + $codebase->scanner->queueClassLikeForScanning($fq_type_string); + $file_storage->referenced_classlikes[strtolower($fq_type_string)] = $fq_type_string; + $args = []; foreach ($stmt->args as $arg_node) { - $key = null; - - if ($arg_node->name) { - $key = $arg_node->name->name; - } + $key = $arg_node->name->name ?? null; $const_type = SimpleTypeInferer::infer( $codebase, diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php index 7702e6039..8c62963a2 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeDocblockParser.php @@ -489,7 +489,7 @@ class ClassLikeDocblockParser array $specials, string $property_tag ) : void { - $magic_property_comments = isset($specials[$property_tag]) ? $specials[$property_tag] : []; + $magic_property_comments = $specials[$property_tag] ?? []; foreach ($magic_property_comments as $offset => $property) { $line_parts = CommentAnalyzer::splitDocLine($property); diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php index fc933678c..11a9b167d 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ClassLikeNodeScanner.php @@ -366,12 +366,7 @@ class ClassLikeNodeScanner if ($type_aliases) { $this->classlike_type_aliases = $type_aliases; } - } catch (DocblockParseException $e) { - $storage->docblock_issues[] = new InvalidDocblock( - $e->getMessage(), - new CodeLocation($this->file_scanner, $node, null, true) - ); - } catch (TypeParseTreeException $e) { + } catch (DocblockParseException | TypeParseTreeException $e) { $storage->docblock_issues[] = new InvalidDocblock( $e->getMessage(), new CodeLocation($this->file_scanner, $node, null, true) @@ -1390,7 +1385,7 @@ class ClassLikeNodeScanner ); } - $doc_var_group_type = $var_comment ? $var_comment->type : null; + $doc_var_group_type = $var_comment->type ?? null; if ($doc_var_group_type) { $doc_var_group_type->queueClassLikesForScanning($this->codebase, $this->file_storage); @@ -1408,7 +1403,7 @@ class ClassLikeNodeScanner $property_storage->type_location = $signature_type_location; $property_storage->location = new CodeLocation($this->file_scanner, $property->name); $property_storage->stmt_location = new CodeLocation($this->file_scanner, $stmt); - $property_storage->has_default = $property->default ? true : false; + $property_storage->has_default = (bool)$property->default; $property_storage->deprecated = $var_comment ? $var_comment->deprecated : false; $property_storage->suppressed_issues = $var_comment ? $var_comment->suppressed_issues : []; $property_storage->internal = $var_comment ? $var_comment->psalm_internal ?? '' : ''; diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php index 34b09d905..a02a5cb83 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/ExpressionScanner.php @@ -281,7 +281,7 @@ class ExpressionScanner // attempts to resolve using get_include_path dirs $include_path = IncludeAnalyzer::resolveIncludePath($path_to_file, dirname($file_storage->file_path)); - $path_to_file = $include_path ? $include_path : $path_to_file; + $path_to_file = $include_path ?: $path_to_file; if (DIRECTORY_SEPARATOR === '/') { $is_path_relative = $path_to_file[0] !== DIRECTORY_SEPARATOR; diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php index 7aac2cc42..57f0b9a3a 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockParser.php @@ -20,6 +20,7 @@ use function preg_replace; use function preg_split; use function reset; use function str_replace; +use function stripos; use function strlen; use function strpos; use function strtolower; @@ -199,7 +200,7 @@ class FunctionLikeDocblockParser if (count($param_parts) === 2) { $taint_type = $param_parts[1]; - if (substr($taint_type, 0, 5) === 'exec_') { + if (strpos($taint_type, 'exec_') === 0) { $taint_type = substr($taint_type, 5); if ($taint_type === 'tainted') { @@ -375,7 +376,7 @@ class FunctionLikeDocblockParser } } - if (strpos(strtolower($parsed_docblock->description), '@inheritdoc') !== false + if (stripos($parsed_docblock->description, '@inheritdoc') !== false || isset($parsed_docblock->tags['inheritdoc']) || isset($parsed_docblock->tags['inheritDoc']) ) { @@ -490,7 +491,7 @@ class FunctionLikeDocblockParser * @param list $line_parts * @return array{string, string} $line_parts */ - private static function sanitizeAssertionLineParts(array $line_parts) + private static function sanitizeAssertionLineParts(array $line_parts): array { if (count($line_parts) < 2 || strpos($line_parts[1], '$') === false) { throw new IncorrectDocblockException('Misplaced variable'); diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php index 8c01914be..d281fa986 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeDocblockScanner.php @@ -617,7 +617,7 @@ class FunctionLikeDocblockScanner $param_name = $docblock_param['name']; $docblock_param_variadic = false; - if (substr($param_name, 0, 3) === '...') { + if (strpos($param_name, '...') === 0) { $docblock_param_variadic = true; $param_name = substr($param_name, 3); } @@ -987,7 +987,7 @@ class FunctionLikeDocblockScanner if (isset($flow_parts[0]) && \strpos(trim($flow_parts[0]), 'proxy') === 0) { $proxy_call = trim(substr($flow_parts[0], strlen('proxy'))); - list($fully_qualified_name, $source_param_string) = explode('(', $proxy_call, 2); + [$fully_qualified_name, $source_param_string] = explode('(', $proxy_call, 2); if (!empty($fully_qualified_name) && !empty($source_param_string)) { $source_params = preg_split('/, ?/', substr($source_param_string, 0, -1)) ?: []; diff --git a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php index 83157e1b3..fb518a1a4 100644 --- a/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php +++ b/src/Psalm/Internal/PhpVisitor/Reflector/FunctionLikeNodeScanner.php @@ -218,7 +218,7 @@ class FunctionLikeNodeScanner } $existing_params['$' . $param_storage->name] = $i; - $storage->addParam($param_storage, !!$param->type); + $storage->addParam($param_storage, (bool)$param->type); if (!$param_storage->is_optional && !$param_storage->is_variadic) { $required_param_count = $i + 1; @@ -292,7 +292,7 @@ class FunctionLikeNodeScanner $cond_id, $cond_id, $function_stmt->cond, - $this->classlike_storage ? $this->classlike_storage->name : null, + $this->classlike_storage->name ?? null, $this->file_scanner, null ); @@ -585,7 +585,7 @@ class FunctionLikeNodeScanner $property_storage->type_location = $param_storage->type_location; $property_storage->location = $param_storage->location; $property_storage->stmt_location = new CodeLocation($this->file_scanner, $param); - $property_storage->has_default = $param->default ? true : false; + $property_storage->has_default = (bool)$param->default; $param_storage->promoted_property = true; $property_storage->is_promoted = true; diff --git a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php index 8c1a4c320..7d9793583 100644 --- a/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php +++ b/src/Psalm/Internal/PhpVisitor/ReflectorVisitor.php @@ -92,7 +92,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements FileSour /** * @var ?int */ - private $skip_if_descendants = null; + private $skip_if_descendants; /** * @var array @@ -126,17 +126,12 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements FileSour { foreach ($node->getComments() as $comment) { if ($comment instanceof PhpParser\Comment\Doc && !$node instanceof PhpParser\Node\Stmt\ClassLike) { - $self_fqcln = $node instanceof PhpParser\Node\Stmt\ClassLike - && $node->name !== null - ? ($this->aliases->namespace ? $this->aliases->namespace . '\\' : '') . $node->name->name - : null; - try { $type_aliases = Reflector\ClassLikeNodeScanner::getTypeAliasesFromComment( $comment, $this->aliases, $this->type_aliases, - $self_fqcln + null ); foreach ($type_aliases as $type_alias) { @@ -145,12 +140,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements FileSour } $this->type_aliases += $type_aliases; - } catch (DocblockParseException $e) { - $this->file_storage->docblock_issues[] = new InvalidDocblock( - $e->getMessage(), - new CodeLocation($this->file_scanner, $node, null, true) - ); - } catch (TypeParseTreeException $e) { + } catch (DocblockParseException | TypeParseTreeException $e) { $this->file_storage->docblock_issues[] = new InvalidDocblock( $e->getMessage(), new CodeLocation($this->file_scanner, $node, null, true) @@ -434,7 +424,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements FileSour foreach ($node->uses as $use) { $use_path = implode('\\', $use->name->parts); - $use_alias = $use->alias ? $use->alias->name : $use->name->getLast(); + $use_alias = $use->alias->name ?? $use->name->getLast(); switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $node->type) { case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION: @@ -467,7 +457,7 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements FileSour foreach ($node->uses as $use) { $use_path = $use_prefix . '\\' . implode('\\', $use->name->parts); - $use_alias = $use->alias ? $use->alias->name : $use->name->getLast(); + $use_alias = $use->alias->name ?? $use->name->getLast(); switch ($use->type !== PhpParser\Node\Stmt\Use_::TYPE_UNKNOWN ? $use->type : $node->type) { case PhpParser\Node\Stmt\Use_::TYPE_FUNCTION: diff --git a/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php b/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php index 04d41daa3..e2cfdc7b9 100644 --- a/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php +++ b/src/Psalm/Internal/PhpVisitor/SimpleNameResolver.php @@ -68,7 +68,7 @@ class SimpleNameResolver extends NodeVisitorAbstract $this->nameContext->startNamespace($node->name); } elseif ($node instanceof Stmt\Use_) { foreach ($node->uses as $use) { - $this->addAlias($use, $node->type, null); + $this->addAlias($use, $node->type); } } elseif ($node instanceof Stmt\GroupUse) { foreach ($node->uses as $use) { diff --git a/src/Psalm/Internal/PluginManager/PluginList.php b/src/Psalm/Internal/PluginManager/PluginList.php index 2769bace7..916ecdc8e 100644 --- a/src/Psalm/Internal/PluginManager/PluginList.php +++ b/src/Psalm/Internal/PluginManager/PluginList.php @@ -18,10 +18,10 @@ class PluginList private $composer_lock; /** @var ?array [pluginClass => packageName] */ - private $all_plugins = null; + private $all_plugins; /** @var ?array [pluginClass => ?packageName] */ - private $enabled_plugins = null; + private $enabled_plugins; public function __construct(?ConfigFile $config_file, ComposerLock $composer_lock) { diff --git a/src/Psalm/Internal/Provider/FakeFileProvider.php b/src/Psalm/Internal/Provider/FakeFileProvider.php index 596fecd9d..7d693ec47 100644 --- a/src/Psalm/Internal/Provider/FakeFileProvider.php +++ b/src/Psalm/Internal/Provider/FakeFileProvider.php @@ -29,11 +29,7 @@ class FakeFileProvider extends FileProvider return $this->temp_files[strtolower($file_path)]; } - if (isset($this->fake_files[$file_path])) { - return $this->fake_files[$file_path]; - } - - return parent::getContents($file_path); + return $this->fake_files[$file_path] ?? parent::getContents($file_path); } public function setContents(string $file_path, string $file_contents): void @@ -50,11 +46,7 @@ class FakeFileProvider extends FileProvider public function getModifiedTime(string $file_path): int { - if (isset($this->fake_file_times[$file_path])) { - return $this->fake_file_times[$file_path]; - } - - return parent::getModifiedTime($file_path); + return $this->fake_file_times[$file_path] ?? parent::getModifiedTime($file_path); } /** diff --git a/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php b/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php index 34aff48ae..02b7daa9f 100644 --- a/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php +++ b/src/Psalm/Internal/Provider/FileReferenceCacheProvider.php @@ -818,10 +818,7 @@ class FileReferenceCacheProvider if ($cache_directory && file_exists($config_hash_cache_location) ) { - /** @var string */ - $file_maps_cache = file_get_contents($config_hash_cache_location); - - return $file_maps_cache; + return file_get_contents($config_hash_cache_location); } return false; diff --git a/src/Psalm/Internal/Provider/FileReferenceProvider.php b/src/Psalm/Internal/Provider/FileReferenceProvider.php index 887e6ff32..6bd1c35ef 100644 --- a/src/Psalm/Internal/Provider/FileReferenceProvider.php +++ b/src/Psalm/Internal/Provider/FileReferenceProvider.php @@ -78,7 +78,7 @@ class FileReferenceProvider * * @var array|null */ - private static $deleted_files = null; + private static $deleted_files; /** * A lookup table used for getting all the files referenced by a file @@ -447,7 +447,7 @@ class FileReferenceProvider */ public function getFilesReferencingFile(string $file): array { - return isset(self::$file_references[$file]['a']) ? self::$file_references[$file]['a'] : []; + return self::$file_references[$file]['a'] ?? []; } /** @@ -455,7 +455,7 @@ class FileReferenceProvider */ public function getFilesInheritingFromFile(string $file): array { - return isset(self::$file_references[$file]['i']) ? self::$file_references[$file]['i'] : []; + return self::$file_references[$file]['i'] ?? []; } /** @@ -691,14 +691,14 @@ class FileReferenceProvider foreach ($visited_files as $file => $_) { $all_file_references = array_unique( array_merge( - isset(self::$file_references[$file]['a']) ? self::$file_references[$file]['a'] : [], + self::$file_references[$file]['a'] ?? [], $this->calculateFilesReferencingFile($codebase, $file) ) ); $inheritance_references = array_unique( array_merge( - isset(self::$file_references[$file]['i']) ? self::$file_references[$file]['i'] : [], + self::$file_references[$file]['i'] ?? [], $this->calculateFilesInheritingFile($codebase, $file) ) ); diff --git a/src/Psalm/Internal/Provider/ParserCacheProvider.php b/src/Psalm/Internal/Provider/ParserCacheProvider.php index bde4314e2..8a8973f71 100644 --- a/src/Psalm/Internal/Provider/ParserCacheProvider.php +++ b/src/Psalm/Internal/Provider/ParserCacheProvider.php @@ -45,7 +45,7 @@ class ParserCacheProvider * * @var array|null */ - private $existing_file_content_hashes = null; + private $existing_file_content_hashes; /** * A map of recently-added filename hashes to contents hashes diff --git a/src/Psalm/Internal/Provider/ProjectCacheProvider.php b/src/Psalm/Internal/Provider/ProjectCacheProvider.php index e0d9d7c14..0aa52bf36 100644 --- a/src/Psalm/Internal/Provider/ProjectCacheProvider.php +++ b/src/Psalm/Internal/Provider/ProjectCacheProvider.php @@ -21,12 +21,12 @@ class ProjectCacheProvider /** * @var int|null */ - private $last_run = null; + private $last_run; /** * @var string|null */ - private $composer_lock_hash = null; + private $composer_lock_hash; private $composer_lock_location; diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php index 6c9507517..c87858f12 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayFilterReturnTypeProvider.php @@ -38,7 +38,7 @@ class ArrayFilterReturnTypeProvider implements \Psalm\Plugin\EventHandler\Functi return Type::getMixed(); } - $array_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $array_arg = $call_args[0]->value ?? null; $first_arg_array = $array_arg && ($first_arg_type = $statements_source->node_data->getType($array_arg)) diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php index e4794676f..32d44bd3c 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPointerAdjustmentReturnTypeProvider.php @@ -24,7 +24,7 @@ class ArrayPointerAdjustmentReturnTypeProvider implements \Psalm\Plugin\EventHan return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $first_arg = $call_args[0]->value ?? null; if (!$first_arg) { return Type::getMixed(); diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php index 8b4aa693a..33b9321d5 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayPopReturnTypeProvider.php @@ -23,7 +23,7 @@ class ArrayPopReturnTypeProvider implements \Psalm\Plugin\EventHandler\FunctionR return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $first_arg = $call_args[0]->value ?? null; $first_arg_array = $first_arg && ($first_arg_type = $statements_source->node_data->getType($first_arg)) diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php index 8f22be303..8e61ae121 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayRandReturnTypeProvider.php @@ -23,8 +23,8 @@ class ArrayRandReturnTypeProvider implements \Psalm\Plugin\EventHandler\Function return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; - $second_arg = isset($call_args[1]->value) ? $call_args[1]->value : null; + $first_arg = $call_args[0]->value ?? null; + $second_arg = $call_args[1]->value ?? null; $first_arg_array = $first_arg && ($first_arg_type = $statements_source->node_data->getType($first_arg)) diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php index 3b38a8bf6..3530237f1 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayReduceReturnTypeProvider.php @@ -258,11 +258,6 @@ class ArrayReduceReturnTypeProvider implements \Psalm\Plugin\EventHandler\Functi $method_id, $self_class ) ?: Type::getMixed(); - - $reduce_return_type = Type::combineUnionTypes( - $reduce_return_type, - $return_type - ); } else { if (!$codebase->functions->functionExists( $statements_source, @@ -280,12 +275,9 @@ class ArrayReduceReturnTypeProvider implements \Psalm\Plugin\EventHandler\Functi ); $return_type = $function_storage->return_type ?: Type::getMixed(); - - $reduce_return_type = Type::combineUnionTypes( - $reduce_return_type, - $return_type - ); } + + $reduce_return_type = Type::combineUnionTypes($reduce_return_type, $return_type); } } diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php index cca2571b8..5b8c90276 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArraySliceReturnTypeProvider.php @@ -23,7 +23,7 @@ class ArraySliceReturnTypeProvider implements \Psalm\Plugin\EventHandler\Functio return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $first_arg = $call_args[0]->value ?? null; if (!$first_arg) { return Type::getArray(); diff --git a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php index bbea643ac..a6a16a9fe 100644 --- a/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php +++ b/src/Psalm/Internal/Provider/ReturnTypeProvider/ArrayValuesReturnTypeProvider.php @@ -22,7 +22,7 @@ class ArrayValuesReturnTypeProvider implements \Psalm\Plugin\EventHandler\Functi return Type::getMixed(); } - $first_arg = isset($call_args[0]->value) ? $call_args[0]->value : null; + $first_arg = $call_args[0]->value ?? null; if (!$first_arg) { return Type::getArray(); diff --git a/src/Psalm/Internal/Provider/StatementsProvider.php b/src/Psalm/Internal/Provider/StatementsProvider.php index 47aed3ef8..d6701770e 100644 --- a/src/Psalm/Internal/Provider/StatementsProvider.php +++ b/src/Psalm/Internal/Provider/StatementsProvider.php @@ -14,7 +14,7 @@ use function count; use function filemtime; use function md5; use function strlen; -use function substr; +use function strpos; /** * @internal @@ -227,7 +227,7 @@ class StatementsProvider $changed_members = array_map( function (string $key) use ($file_path_hash) : string { - if (substr($key, 0, 4) === 'use:') { + if (strpos($key, 'use:') === 0) { return $key . ':' . $file_path_hash; } diff --git a/src/Psalm/Internal/Scanner/ClassLikeDocblockComment.php b/src/Psalm/Internal/Scanner/ClassLikeDocblockComment.php index f18f947f5..64f24ad52 100644 --- a/src/Psalm/Internal/Scanner/ClassLikeDocblockComment.php +++ b/src/Psalm/Internal/Scanner/ClassLikeDocblockComment.php @@ -32,7 +32,7 @@ class ClassLikeDocblockComment * * @var null|string */ - public $psalm_internal = null; + public $psalm_internal; /** * @var string[] @@ -57,7 +57,7 @@ class ClassLikeDocblockComment /** * @var ?string */ - public $yield = null; + public $yield; /** * @var array diff --git a/src/Psalm/Internal/Scanner/DocblockParser.php b/src/Psalm/Internal/Scanner/DocblockParser.php index 58e6c8268..aa9a11c30 100644 --- a/src/Psalm/Internal/Scanner/DocblockParser.php +++ b/src/Psalm/Internal/Scanner/DocblockParser.php @@ -31,7 +31,7 @@ class DocblockParser // Strip off comments. $docblock = trim($docblock); - if (substr($docblock, 0, 3) === '/**') { + if (strpos($docblock, '/**') === 0) { $docblock = substr($docblock, 3); } diff --git a/src/Psalm/Internal/Scanner/FunctionDocblockComment.php b/src/Psalm/Internal/Scanner/FunctionDocblockComment.php index f3c8fda0a..d0482c10a 100644 --- a/src/Psalm/Internal/Scanner/FunctionDocblockComment.php +++ b/src/Psalm/Internal/Scanner/FunctionDocblockComment.php @@ -9,22 +9,22 @@ class FunctionDocblockComment /** * @var string|null */ - public $return_type = null; + public $return_type; /** * @var string|null */ - public $return_type_description = null; + public $return_type_description; /** * @var int|null */ - public $return_type_start = null; + public $return_type_start; /** * @var int|null */ - public $return_type_end = null; + public $return_type_end; /** * @var int|null @@ -73,7 +73,7 @@ class FunctionDocblockComment * * @var null|string */ - public $psalm_internal = null; + public $psalm_internal; /** * Whether or not the function is internal diff --git a/src/Psalm/Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php b/src/Psalm/Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php index 0a675617b..f9618f0ff 100644 --- a/src/Psalm/Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php +++ b/src/Psalm/Internal/Scanner/UnresolvedConstant/UnresolvedTernary.php @@ -9,8 +9,11 @@ use Psalm\Internal\Scanner\UnresolvedConstantComponent; */ class UnresolvedTernary extends UnresolvedConstantComponent { + /** @var UnresolvedConstantComponent */ public $cond; + /** @var UnresolvedConstantComponent|null */ public $if; + /** @var UnresolvedConstantComponent */ public $else; public function __construct( diff --git a/src/Psalm/Internal/Scanner/VarDocblockComment.php b/src/Psalm/Internal/Scanner/VarDocblockComment.php index fb55108f5..330848f7c 100644 --- a/src/Psalm/Internal/Scanner/VarDocblockComment.php +++ b/src/Psalm/Internal/Scanner/VarDocblockComment.php @@ -16,7 +16,7 @@ class VarDocblockComment /** * @var string|null */ - public $var_id = null; + public $var_id; /** * @var int|null @@ -52,7 +52,7 @@ class VarDocblockComment * * @var null|string */ - public $psalm_internal = null; + public $psalm_internal; /** * Whether or not the property is readonly diff --git a/src/Psalm/Internal/Scope/IfScope.php b/src/Psalm/Internal/Scope/IfScope.php index 98ee90741..85fdc515e 100644 --- a/src/Psalm/Internal/Scope/IfScope.php +++ b/src/Psalm/Internal/Scope/IfScope.php @@ -12,7 +12,7 @@ class IfScope /** * @var array|null */ - public $new_vars = null; + public $new_vars; /** * @var array @@ -22,12 +22,12 @@ class IfScope /** * @var array|null */ - public $redefined_vars = null; + public $redefined_vars; /** * @var array|null */ - public $assigned_var_ids = null; + public $assigned_var_ids; /** * @var array @@ -57,7 +57,7 @@ class IfScope /** * @var array|null */ - public $negatable_if_types = null; + public $negatable_if_types; /** * @var list @@ -78,7 +78,7 @@ class IfScope * * @var array|null */ - public $possible_param_types = null; + public $possible_param_types; /** * @var string[] diff --git a/src/Psalm/Internal/Scope/LoopScope.php b/src/Psalm/Internal/Scope/LoopScope.php index 2bbfe903b..1e6204100 100644 --- a/src/Psalm/Internal/Scope/LoopScope.php +++ b/src/Psalm/Internal/Scope/LoopScope.php @@ -37,7 +37,7 @@ class LoopScope /** * @var array|null */ - public $possibly_redefined_loop_parent_vars = null; + public $possibly_redefined_loop_parent_vars; /** * @var array diff --git a/src/Psalm/Internal/Scope/SwitchScope.php b/src/Psalm/Internal/Scope/SwitchScope.php index 9025e6557..0697d6fab 100644 --- a/src/Psalm/Internal/Scope/SwitchScope.php +++ b/src/Psalm/Internal/Scope/SwitchScope.php @@ -13,7 +13,7 @@ class SwitchScope /** * @var array|null */ - public $new_vars_in_scope = null; + public $new_vars_in_scope; /** * @var array @@ -23,12 +23,12 @@ class SwitchScope /** * @var array|null */ - public $redefined_vars = null; + public $redefined_vars; /** * @var array|null */ - public $possibly_redefined_vars = null; + public $possibly_redefined_vars; /** * @var array @@ -38,7 +38,7 @@ class SwitchScope /** * @var PhpParser\Node\Expr|null */ - public $leftover_case_equality_expr = null; + public $leftover_case_equality_expr; /** * @var list @@ -48,5 +48,5 @@ class SwitchScope /** * @var array|null */ - public $new_assigned_var_ids = null; + public $new_assigned_var_ids; } diff --git a/src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php b/src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php index a1044f89d..55d19edca 100644 --- a/src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php +++ b/src/Psalm/Internal/Stubs/Generator/ClassLikeStubGenerator.php @@ -16,6 +16,7 @@ use Psalm\Storage\ClassLikeStorage; use Psalm\Internal\Analyzer\ClassLikeAnalyzer; use Psalm\Internal\Scanner\ParsedDocblock; use Psalm\Type; +use function array_slice; class ClassLikeStubGenerator { diff --git a/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php b/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php index e57c180b2..efce50c04 100644 --- a/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php +++ b/src/Psalm/Internal/Stubs/Generator/StubsGenerator.php @@ -22,6 +22,7 @@ use Psalm\Node\VirtualName; use Psalm\Node\VirtualNullableType; use Psalm\Node\VirtualParam; use Psalm\Type; +use function dirname; class StubsGenerator { diff --git a/src/Psalm/Internal/Type/AssertionReconciler.php b/src/Psalm/Internal/Type/AssertionReconciler.php index 9daff509c..e7d47ad1a 100644 --- a/src/Psalm/Internal/Type/AssertionReconciler.php +++ b/src/Psalm/Internal/Type/AssertionReconciler.php @@ -147,7 +147,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler return $simply_reconciled_type; } - if (substr($assertion, 0, 4) === 'isa-') { + if (strpos($assertion, 'isa-') === 0) { $should_return = false; $new_type = self::handleIsA( @@ -164,7 +164,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler if ($should_return) { return $new_type; } - } elseif (substr($assertion, 0, 9) === 'getclass-') { + } elseif (strpos($assertion, 'getclass-') === 0) { $assertion = substr($assertion, 9); $new_type = Type::parseString($assertion, null, $template_type_map); } else { @@ -1003,7 +1003,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler $did_remove_type = false; foreach ($existing_var_atomic_types as $atomic_key => $_) { - if (substr($atomic_key, 0, 6) === 'float(') { + if (strpos($atomic_key, 'float(') === 0) { $atomic_key = 'int(' . substr($atomic_key, 6); } if ($atomic_key !== $assertion) { @@ -1075,7 +1075,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler $existing_var_atomic_type->as = self::handleLiteralEquality( $assertion, $bracket_pos, - $is_loose_equality, + false, $existing_var_atomic_type->as, $old_var_type_string, $var_id, @@ -1211,7 +1211,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler $did_remove_type = false; foreach ($existing_var_atomic_types as $atomic_key => $_) { - if (substr($atomic_key, 0, 4) === 'int(') { + if (strpos($atomic_key, 'int(') === 0) { $atomic_key = 'float(' . substr($atomic_key, 4); } if ($atomic_key !== $assertion) { @@ -1240,7 +1240,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler } } } elseif ($scalar_type === 'enum') { - list($fq_enum_name, $case_name) = explode('::', $value); + [$fq_enum_name, $case_name] = explode('::', $value); if ($existing_var_type->hasMixed()) { if ($is_loose_equality) { @@ -1297,7 +1297,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler Codebase $codebase, Union $existing_var_type, string &$assertion, - array &$template_type_map, + array $template_type_map, ?CodeLocation $code_location, ?string $key, array $suppressed_issues, @@ -1307,7 +1307,7 @@ class AssertionReconciler extends \Psalm\Type\Reconciler $allow_string_comparison = false; - if (substr($assertion, 0, 7) === 'string-') { + if (strpos($assertion, 'string-') === 0) { $assertion = substr($assertion, 7); $allow_string_comparison = true; } diff --git a/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php b/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php index 3a0b6227b..26e65fd21 100644 --- a/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/CallableTypeComparator.php @@ -321,7 +321,7 @@ class CallableTypeComparator $matching_callable->is_pure = $codebase->functions->isCallMapFunctionPure( $codebase, - $statements_analyzer ? $statements_analyzer->node_data : null, + $statements_analyzer->node_data ?? null, $input_type_part->value, null, $must_use diff --git a/src/Psalm/Internal/Type/Comparator/IntegerRangeComparator.php b/src/Psalm/Internal/Type/Comparator/IntegerRangeComparator.php index 4fe35a4f9..33607b97c 100644 --- a/src/Psalm/Internal/Type/Comparator/IntegerRangeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/IntegerRangeComparator.php @@ -81,15 +81,7 @@ class IntegerRangeComparator return false; } - if ($result_reduction === null) { - //inconclusive result, we can't remove atomics anymore. - //container: `int<1, 5>`, input: `int<0, 6>` - //container: `5`, input: `int<4, 6>` - //we assume there's no combinations that makes the input contained - return false; - } - - return $result_reduction; + return $result_reduction ?? false; } /** diff --git a/src/Psalm/Internal/Type/Comparator/ObjectComparator.php b/src/Psalm/Internal/Type/Comparator/ObjectComparator.php index 017ef53e0..22d451e8a 100644 --- a/src/Psalm/Internal/Type/Comparator/ObjectComparator.php +++ b/src/Psalm/Internal/Type/Comparator/ObjectComparator.php @@ -76,11 +76,11 @@ class ObjectComparator foreach ($intersection_input_types as $intersection_input_type) { if ($intersection_input_type instanceof TTemplateParam - && (\substr($intersection_container_type->defining_class, 0, 3) === 'fn-' - || \substr($intersection_input_type->defining_class, 0, 3) === 'fn-') + && (\strpos($intersection_container_type->defining_class, 'fn-') === 0 + || \strpos($intersection_input_type->defining_class, 'fn-') === 0) ) { - if (\substr($intersection_input_type->defining_class, 0, 3) === 'fn-' - && \substr($intersection_container_type->defining_class, 0, 3) === 'fn-' + if (\strpos($intersection_input_type->defining_class, 'fn-') === 0 + && \strpos($intersection_container_type->defining_class, 'fn-') === 0 && $intersection_input_type->defining_class !== $intersection_container_type->defining_class ) { @@ -191,10 +191,10 @@ class ObjectComparator if ($intersection_container_type->param_name !== $intersection_input_type->param_name || ($intersection_container_type->defining_class !== $intersection_input_type->defining_class - && \substr($intersection_input_type->defining_class, 0, 3) !== 'fn-' - && \substr($intersection_container_type->defining_class, 0, 3) !== 'fn-') + && \strpos($intersection_input_type->defining_class, 'fn-') !== 0 + && \strpos($intersection_container_type->defining_class, 'fn-') !== 0) ) { - if (\substr($intersection_input_type->defining_class, 0, 3) !== 'fn-') { + if (\strpos($intersection_input_type->defining_class, 'fn-') !== 0) { $input_class_storage = $codebase->classlike_storage_provider->get( $intersection_input_type->defining_class ); diff --git a/src/Psalm/Internal/Type/Comparator/TypeComparisonResult.php b/src/Psalm/Internal/Type/Comparator/TypeComparisonResult.php index 78f269873..288da07b9 100644 --- a/src/Psalm/Internal/Type/Comparator/TypeComparisonResult.php +++ b/src/Psalm/Internal/Type/Comparator/TypeComparisonResult.php @@ -5,26 +5,26 @@ namespace Psalm\Internal\Type\Comparator; class TypeComparisonResult { /** @var ?bool */ - public $scalar_type_match_found = null; + public $scalar_type_match_found; /** @var ?bool */ - public $type_coerced = null; + public $type_coerced; /** @var ?bool */ - public $type_coerced_from_mixed = null; + public $type_coerced_from_mixed; /** @var ?bool */ - public $type_coerced_from_as_mixed = null; + public $type_coerced_from_as_mixed; /** @var ?bool */ - public $to_string_cast = null; + public $to_string_cast; /** @var ?bool */ - public $type_coerced_from_scalar = null; + public $type_coerced_from_scalar; /** @var ?\Psalm\Type\Union */ - public $replacement_union_type = null; + public $replacement_union_type; /** @var ?\Psalm\Type\Atomic */ - public $replacement_atomic_type = null; + public $replacement_atomic_type; } diff --git a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php index 622047b47..12eb39ea7 100644 --- a/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php +++ b/src/Psalm/Internal/Type/Comparator/UnionTypeComparator.php @@ -381,7 +381,7 @@ class UnionTypeComparator } } - return !!$matching_input_keys; + return (bool)$matching_input_keys; } /** diff --git a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php index 8a0d68787..164d21399 100644 --- a/src/Psalm/Internal/Type/NegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/NegatedAssertionReconciler.php @@ -159,7 +159,7 @@ class NegatedAssertionReconciler extends Reconciler return Type::getEmpty(); } - if (substr($assertion, 0, 9) === 'in-array-') { + if (strpos($assertion, 'in-array-') === 0) { $assertion = substr($assertion, 9); $new_var_type = null; try { @@ -195,7 +195,7 @@ class NegatedAssertionReconciler extends Reconciler return $existing_var_type; } - if (substr($assertion, 0, 14) === 'has-array-key-') { + if (strpos($assertion, 'has-array-key-') === 0) { return $existing_var_type; } } @@ -283,7 +283,7 @@ class NegatedAssertionReconciler extends Reconciler ) { $existing_var_type->removeType('array-key'); $existing_var_type->addType(new TString); - } elseif (substr($assertion, 0, 9) === 'getclass-') { + } elseif (strpos($assertion, 'getclass-') === 0) { $assertion = substr($assertion, 9); } elseif (!$is_equality) { $codebase = $statements_analyzer->getCodebase(); @@ -462,7 +462,7 @@ class NegatedAssertionReconciler extends Reconciler $scalar_var_type = Type::getFloat((float) $scalar_value); } } elseif ($scalar_type === 'enum') { - list($fq_enum_name, $case_name) = explode('::', substr($assertion, $bracket_pos + 1, -1)); + [$fq_enum_name, $case_name] = explode('::', substr($assertion, $bracket_pos + 1, -1)); foreach ($existing_var_type->getAtomicTypes() as $atomic_key => $atomic_type) { if (get_class($atomic_type) === Type\Atomic\TNamedObject::class diff --git a/src/Psalm/Internal/Type/ParseTreeCreator.php b/src/Psalm/Internal/Type/ParseTreeCreator.php index 4c70e4ff3..95b812274 100644 --- a/src/Psalm/Internal/Type/ParseTreeCreator.php +++ b/src/Psalm/Internal/Type/ParseTreeCreator.php @@ -402,10 +402,8 @@ class ParseTreeCreator $this->current_leaf->parent = $new_leaf; array_pop($current_parent->children); - $current_parent->children[] = $new_leaf; - } else { - $current_parent->children[] = $new_leaf; } + $current_parent->children[] = $new_leaf; $this->current_leaf = $new_leaf; } @@ -450,7 +448,7 @@ class ParseTreeCreator return; } - if ($current_parent && $current_parent instanceof ParseTree\KeyedArrayPropertyTree) { + if ($current_parent instanceof ParseTree\KeyedArrayPropertyTree) { return; } @@ -462,7 +460,7 @@ class ParseTreeCreator $current_parent = $this->current_leaf->parent; } - if ($current_parent && $current_parent instanceof ParseTree\ConditionalTree) { + if ($current_parent instanceof ParseTree\ConditionalTree) { if (count($current_parent->children) > 1) { throw new TypeParseTreeException('Cannot process colon in conditional twice'); } @@ -608,12 +606,12 @@ class ParseTreeCreator throw new TypeParseTreeException('Unexpected token |'); } - if ($current_parent && $current_parent instanceof ParseTree\UnionTree) { + if ($current_parent instanceof ParseTree\UnionTree) { $this->current_leaf = $current_parent; return; } - if ($current_parent && $current_parent instanceof ParseTree\IntersectionTree) { + if ($current_parent instanceof ParseTree\IntersectionTree) { $this->current_leaf = $current_parent; $current_parent = $this->current_leaf->parent; } @@ -649,12 +647,12 @@ class ParseTreeCreator $current_parent = $this->current_leaf->parent; - if ($current_parent && $current_parent instanceof ParseTree\MethodTree) { + if ($current_parent instanceof ParseTree\MethodTree) { $this->createMethodParam($this->type_tokens[$this->t], $current_parent); return; } - if ($current_parent && $current_parent instanceof ParseTree\IntersectionTree) { + if ($current_parent instanceof ParseTree\IntersectionTree) { $this->current_leaf = $current_parent; return; } diff --git a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php index d57453eda..d757708d8 100644 --- a/src/Psalm/Internal/Type/SimpleAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleAssertionReconciler.php @@ -87,7 +87,7 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler return $existing_var_type; } - if (substr($assertion, 0, 9) === 'in-array-') { + if (strpos($assertion, 'in-array-') === 0) { return self::reconcileInArray( $codebase, $existing_var_type, @@ -100,7 +100,7 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler ); } - if (substr($assertion, 0, 14) === 'has-array-key-') { + if (strpos($assertion, 'has-array-key-') === 0) { return self::reconcileHasArrayKey( $existing_var_type, substr($assertion, 14) @@ -369,7 +369,7 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler ); } - if (substr($assertion, 0, 13) === 'has-at-least-') { + if (strpos($assertion, 'has-at-least-') === 0) { return self::reconcileNonEmptyCountable( $existing_var_type, $key, @@ -382,7 +382,7 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler ); } - if (substr($assertion, 0, 12) === 'has-exactly-') { + if (strpos($assertion, 'has-exactly-') === 0) { /** @psalm-suppress ArgumentTypeCoercion */ return self::reconcileExactlyCountable( $existing_var_type, @@ -390,7 +390,7 @@ class SimpleAssertionReconciler extends \Psalm\Type\Reconciler ); } - if (substr($assertion, 0, 10) === 'hasmethod-') { + if (strpos($assertion, 'hasmethod-') === 0) { return self::reconcileHasMethod( $codebase, substr($assertion, 10), diff --git a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php index ab6b41e09..9ea23e96c 100644 --- a/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php +++ b/src/Psalm/Internal/Type/SimpleNegatedAssertionReconciler.php @@ -29,6 +29,7 @@ use Psalm\Type\Union; use function get_class; use function max; +use function strpos; use function substr; class SimpleNegatedAssertionReconciler extends Reconciler @@ -217,7 +218,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler ); } - if (substr($assertion, 0, 13) === 'has-at-least-') { + if (strpos($assertion, 'has-at-least-') === 0) { return self::reconcileNonEmptyCountable( $existing_var_type, $key, @@ -230,7 +231,7 @@ class SimpleNegatedAssertionReconciler extends Reconciler ); } - if (substr($assertion, 0, 12) === 'has-exactly-') { + if (strpos($assertion, 'has-exactly-') === 0) { return $existing_var_type; } diff --git a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php index a1cd6fdff..cc92d0430 100644 --- a/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateInferredTypeReplacer.php @@ -14,7 +14,7 @@ use Psalm\Type\Union; use function array_merge; use function array_shift; use function array_values; -use function substr; +use function strpos; class TemplateInferredTypeReplacer { @@ -83,7 +83,7 @@ class TemplateInferredTypeReplacer } elseif ($codebase) { foreach ($inferred_lower_bounds as $template_type_map) { foreach ($template_type_map as $template_class => $_) { - if (substr($template_class, 0, 3) === 'fn-') { + if (strpos($template_class, 'fn-') === 0) { continue; } diff --git a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php index b07073017..5223e1126 100644 --- a/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php +++ b/src/Psalm/Internal/Type/TemplateStandinTypeReplacer.php @@ -179,7 +179,7 @@ class TemplateStandinTypeReplacer $template_result, $codebase, $statements_analyzer, - $replace, + true, $add_lower_bound, $bound_equality_classlike, $depth, @@ -599,7 +599,7 @@ class TemplateStandinTypeReplacer $input_arg_offset, $calling_class, $calling_function, - $replace, + true, $add_lower_bound, $bound_equality_classlike, $depth + 1 @@ -685,7 +685,7 @@ class TemplateStandinTypeReplacer $input_arg_offset, $calling_class, $calling_function, - $replace, + true, $add_lower_bound, $bound_equality_classlike, $depth + 1 @@ -1174,11 +1174,7 @@ class TemplateStandinTypeReplacer \array_keys($input_class_storage->template_types) ); - if (!isset($input_type_params[$old_params_offset])) { - $candidate_param_type = \Psalm\Type::getMixed(); - } else { - $candidate_param_type = $input_type_params[$old_params_offset]; - } + $candidate_param_type = $input_type_params[$old_params_offset] ?? \Psalm\Type::getMixed(); } else { $candidate_param_type = new Union([clone $et]); } diff --git a/src/Psalm/Internal/Type/TypeCombination.php b/src/Psalm/Internal/Type/TypeCombination.php index f2fd1dcc6..5bcb88e95 100644 --- a/src/Psalm/Internal/Type/TypeCombination.php +++ b/src/Psalm/Internal/Type/TypeCombination.php @@ -46,10 +46,10 @@ class TypeCombination public $objectlike_sealed = true; /** @var ?Union */ - public $objectlike_key_type = null; + public $objectlike_key_type; /** @var ?Union */ - public $objectlike_value_type = null; + public $objectlike_value_type; /** @var bool */ public $empty_mixed = false; @@ -58,7 +58,7 @@ class TypeCombination public $non_empty_mixed = false; /** @var ?bool */ - public $mixed_from_loop_isset = null; + public $mixed_from_loop_isset; /** @var array|null */ public $strings = []; diff --git a/src/Psalm/Internal/Type/TypeCombiner.php b/src/Psalm/Internal/Type/TypeCombiner.php index 320ebc0f3..8c86dd9c7 100644 --- a/src/Psalm/Internal/Type/TypeCombiner.php +++ b/src/Psalm/Internal/Type/TypeCombiner.php @@ -684,9 +684,7 @@ class TypeCombiner $has_defined_keys = false; foreach ($type->properties as $candidate_property_name => $candidate_property_type) { - $value_type = isset($combination->objectlike_entries[$candidate_property_name]) - ? $combination->objectlike_entries[$candidate_property_name] - : null; + $value_type = $combination->objectlike_entries[$candidate_property_name] ?? null; if (!$value_type) { $combination->objectlike_entries[$candidate_property_name] = clone $candidate_property_type; diff --git a/src/Psalm/Internal/Type/TypeExpander.php b/src/Psalm/Internal/Type/TypeExpander.php index b61735e05..e7123c461 100644 --- a/src/Psalm/Internal/Type/TypeExpander.php +++ b/src/Psalm/Internal/Type/TypeExpander.php @@ -664,7 +664,7 @@ class TypeExpander bool $evaluate_class_constants = true, bool $evaluate_conditional_types = false, bool $final = false, - bool &$expand_generic = false, + bool $expand_generic = false, bool $expand_templates = false ) { $new_as_type = self::expandUnion( diff --git a/src/Psalm/Internal/Type/TypeParser.php b/src/Psalm/Internal/Type/TypeParser.php index 77100f9fa..ab0da4d45 100644 --- a/src/Psalm/Internal/Type/TypeParser.php +++ b/src/Psalm/Internal/Type/TypeParser.php @@ -406,7 +406,7 @@ class TypeParser return new Atomic\TTemplateParamClass( $t->param_name, - $t_atomic_type ? $t_atomic_type->value : 'object', + $t_atomic_type->value ?? 'object', $t_atomic_type, $t->defining_class ); @@ -1183,7 +1183,7 @@ class TypeParser $array_defining_class = array_keys($template_type_map[$array_param_name])[0]; if ($offset_defining_class !== $array_defining_class - && substr($offset_defining_class, 0, 3) !== 'fn-' + && strpos($offset_defining_class, 'fn-') !== 0 ) { throw new TypeParseTreeException('Template params are defined in different locations'); } diff --git a/src/Psalm/Internal/Type/TypeTokenizer.php b/src/Psalm/Internal/Type/TypeTokenizer.php index bb74404a2..204361bf8 100644 --- a/src/Psalm/Internal/Type/TypeTokenizer.php +++ b/src/Psalm/Internal/Type/TypeTokenizer.php @@ -4,7 +4,6 @@ namespace Psalm\Internal\Type; use Psalm\Aliases; use Psalm\Exception\TypeParseTreeException; -use function array_push; use function array_splice; use function array_unshift; use function count; @@ -479,7 +478,7 @@ class TypeTokenizer $replacement_tokens = $type_alias->replacement_tokens; array_unshift($replacement_tokens, ['(', $i]); - array_push($replacement_tokens, [')', $i]); + $replacement_tokens[] = [')', $i]; $diff = count($replacement_tokens) - 1; diff --git a/src/Psalm/Internal/TypeVisitor/TypeChecker.php b/src/Psalm/Internal/TypeVisitor/TypeChecker.php index 3993d8567..d402cbd01 100644 --- a/src/Psalm/Internal/TypeVisitor/TypeChecker.php +++ b/src/Psalm/Internal/TypeVisitor/TypeChecker.php @@ -355,7 +355,7 @@ class TypeChecker extends NodeVisitor public function checkTemplateParam(\Psalm\Type\Atomic\TTemplateParam $atomic) : void { if ($this->prevent_template_covariance - && \substr($atomic->defining_class, 0, 3) !== 'fn-' + && \strpos($atomic->defining_class, 'fn-') !== 0 ) { $codebase = $this->source->getCodebase(); diff --git a/src/Psalm/Issue/CodeIssue.php b/src/Psalm/Issue/CodeIssue.php index 3d64cfc4d..871b89d47 100644 --- a/src/Psalm/Issue/CodeIssue.php +++ b/src/Psalm/Issue/CodeIssue.php @@ -2,11 +2,9 @@ namespace Psalm\Issue; use Psalm\CodeLocation; -use Psalm\Config; use function array_pop; use function explode; -use function get_called_class; abstract class CodeIssue { @@ -87,13 +85,13 @@ abstract class CodeIssue return $this->message; } - public function toIssueData(string $severity = Config::REPORT_ERROR): \Psalm\Internal\Analyzer\IssueData + public function toIssueData(string $severity): \Psalm\Internal\Analyzer\IssueData { $location = $this->code_location; $selection_bounds = $location->getSelectionBounds(); $snippet_bounds = $location->getSnippetBounds(); - $fqcn_parts = explode('\\', get_called_class()); + $fqcn_parts = explode('\\', static::class); $issue_type = array_pop($fqcn_parts); return new \Psalm\Internal\Analyzer\IssueData( diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index e07d60bab..9b773d485 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -115,7 +115,7 @@ class IssueBuffer public static function addUnusedSuppression(string $file_path, int $offset, string $issue_type) : void { - if (\substr($issue_type, 0, 7) === 'Tainted') { + if (\strpos($issue_type, 'Tainted') === 0) { return; } @@ -215,7 +215,7 @@ class IssueBuffer return false; } - $is_tainted = \substr($issue_type, 0, 7) === 'Tainted'; + $is_tainted = \strpos($issue_type, 'Tainted') === 0; if ($project_analyzer->getCodebase()->taint_flow_graph && !$is_tainted) { return false; @@ -531,12 +531,12 @@ class IssueBuffer if ($position !== false) { $issue_data->severity = Config::REPORT_INFO; array_splice($issue_baseline[$file][$type]['s'], $position, 1); - $issue_baseline[$file][$type]['o'] = $issue_baseline[$file][$type]['o'] - 1; + $issue_baseline[$file][$type]['o']--; } } else { $issue_baseline[$file][$type]['s'] = []; $issue_data->severity = Config::REPORT_INFO; - $issue_baseline[$file][$type]['o'] = $issue_baseline[$file][$type]['o'] - 1; + $issue_baseline[$file][$type]['o']--; } } diff --git a/src/Psalm/Progress/Progress.php b/src/Psalm/Progress/Progress.php index 7bf84b561..06c4efd52 100644 --- a/src/Psalm/Progress/Progress.php +++ b/src/Psalm/Progress/Progress.php @@ -54,7 +54,7 @@ abstract class Progress protected static function doesTerminalSupportUtf8() : bool { - if (\strtoupper(\substr(PHP_OS, 0, 3)) === 'WIN') { + if (\stripos(PHP_OS, 'WIN') === 0) { if (!\function_exists('sapi_windows_cp_is_utf8') || !\sapi_windows_cp_is_utf8()) { return false; } diff --git a/src/Psalm/Report.php b/src/Psalm/Report.php index 68cbc331b..a57b2d304 100644 --- a/src/Psalm/Report.php +++ b/src/Psalm/Report.php @@ -105,7 +105,7 @@ abstract class Report protected function xmlEncode(string $data): string { - return htmlspecialchars($data, ENT_XML1 | ENT_QUOTES, 'UTF-8'); + return htmlspecialchars($data, ENT_XML1 | ENT_QUOTES); } abstract public function create(): string; diff --git a/src/Psalm/Report/PylintReport.php b/src/Psalm/Report/PylintReport.php index 1e1041dd5..d96354c6e 100644 --- a/src/Psalm/Report/PylintReport.php +++ b/src/Psalm/Report/PylintReport.php @@ -36,14 +36,12 @@ class PylintReport extends Report // but it's still useful for users. // E.g. jenkins can't parse %s:%d:%d. $message = sprintf('%s (column %d)', $message, $issue_data->column_from); - $issue_string = sprintf( + return sprintf( '%s:%d: [%s] %s', $issue_data->file_name, $issue_data->line_from, $code, $message ); - - return $issue_string; } } diff --git a/src/Psalm/Report/SarifReport.php b/src/Psalm/Report/SarifReport.php index 6a1e41378..b63e4cb38 100644 --- a/src/Psalm/Report/SarifReport.php +++ b/src/Psalm/Report/SarifReport.php @@ -45,7 +45,7 @@ class SarifReport extends Report ], 'properties' => [ 'tags' => [ - (\substr($issue_data->type, 0, 7) === 'Tainted') ? 'security' : 'maintainability', + (\strpos($issue_data->type, 'Tainted') === 0) ? 'security' : 'maintainability', ], ], 'helpUri' => $issue_data->link, diff --git a/src/Psalm/Storage/ClassConstantStorage.php b/src/Psalm/Storage/ClassConstantStorage.php index 2185f6a80..ac752dc10 100644 --- a/src/Psalm/Storage/ClassConstantStorage.php +++ b/src/Psalm/Storage/ClassConstantStorage.php @@ -30,7 +30,7 @@ class ClassConstantStorage /** * @var ?\Psalm\Internal\Scanner\UnresolvedConstantComponent */ - public $unresolved_node = null; + public $unresolved_node; /** * @var bool diff --git a/src/Psalm/Storage/ClassLikeStorage.php b/src/Psalm/Storage/ClassLikeStorage.php index bf1164115..c7a533e96 100644 --- a/src/Psalm/Storage/ClassLikeStorage.php +++ b/src/Psalm/Storage/ClassLikeStorage.php @@ -54,7 +54,7 @@ class ClassLikeStorage /** * @var ?string */ - public $mixin_declaring_fqcln = null; + public $mixin_declaring_fqcln; /** * @var bool diff --git a/src/Psalm/Storage/FunctionLikeStorage.php b/src/Psalm/Storage/FunctionLikeStorage.php index 5a1fe6abf..fdef5d4ea 100644 --- a/src/Psalm/Storage/FunctionLikeStorage.php +++ b/src/Psalm/Storage/FunctionLikeStorage.php @@ -242,7 +242,7 @@ abstract class FunctionLikeStorage return $this->getSignature(false); } - public function getSignature(bool $allow_newlines = false): string + public function getSignature(bool $allow_newlines): string { $newlines = $allow_newlines && !empty($this->params); diff --git a/src/Psalm/Storage/MethodStorage.php b/src/Psalm/Storage/MethodStorage.php index 7591f18b9..becfc51d4 100644 --- a/src/Psalm/Storage/MethodStorage.php +++ b/src/Psalm/Storage/MethodStorage.php @@ -83,12 +83,12 @@ class MethodStorage extends FunctionLikeStorage /** * @var ?array */ - public $this_property_mutations = null; + public $this_property_mutations; /** * @var Type\Union|null */ - public $self_out_type = null; + public $self_out_type; /** * @var bool diff --git a/src/Psalm/Storage/PropertyStorage.php b/src/Psalm/Storage/PropertyStorage.php index 66917c336..2452f2b0c 100644 --- a/src/Psalm/Storage/PropertyStorage.php +++ b/src/Psalm/Storage/PropertyStorage.php @@ -84,7 +84,7 @@ class PropertyStorage /** * @var ?string */ - public $getter_method = null; + public $getter_method; /** * @var bool diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index 9b6e7c92d..88d9a286c 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -56,7 +56,6 @@ use function get_class; use function is_numeric; use function strpos; use function strtolower; -use function substr; abstract class Atomic implements TypeNode { @@ -289,7 +288,7 @@ abstract class Atomic implements TypeNode return new TNonEmptyMixed(); } - if (strpos($value, '-') && substr($value, 0, 4) !== 'OCI-') { + if (strpos($value, '-') && strpos($value, 'OCI-') !== 0) { throw new \Psalm\Exception\TypeParseTreeException('Unrecognized type ' . $value); } diff --git a/src/Psalm/Type/Atomic/TCallableArray.php b/src/Psalm/Type/Atomic/TCallableArray.php index aa484aa89..6edaa611c 100644 --- a/src/Psalm/Type/Atomic/TCallableArray.php +++ b/src/Psalm/Type/Atomic/TCallableArray.php @@ -10,9 +10,4 @@ class TCallableArray extends TNonEmptyArray * @var string */ public $value = 'callable-array'; - - public function getKey(bool $include_extra = true): string - { - return 'array'; - } } diff --git a/src/Psalm/Type/Atomic/TClassStringMap.php b/src/Psalm/Type/Atomic/TClassStringMap.php index acef988c7..70e3b0546 100644 --- a/src/Psalm/Type/Atomic/TClassStringMap.php +++ b/src/Psalm/Type/Atomic/TClassStringMap.php @@ -92,7 +92,7 @@ class TClassStringMap extends \Psalm\Type\Atomic $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + true ); } @@ -106,7 +106,7 @@ class TClassStringMap extends \Psalm\Type\Atomic $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + false ) . '>'; } @@ -234,7 +234,7 @@ class TClassStringMap extends \Psalm\Type\Atomic return new Type\Union([ new TTemplateParamClass( $this->param_name, - $this->as_type ? $this->as_type->value : 'object', + $this->as_type->value ?? 'object', $this->as_type, 'class-string-map' ) diff --git a/src/Psalm/Type/Atomic/TEnumCase.php b/src/Psalm/Type/Atomic/TEnumCase.php index 9e3815c55..0c0f99a5a 100644 --- a/src/Psalm/Type/Atomic/TEnumCase.php +++ b/src/Psalm/Type/Atomic/TEnumCase.php @@ -13,7 +13,7 @@ class TEnumCase extends TNamedObject public function __construct(string $fq_enum_name, string $case_name) { - parent::__construct($fq_enum_name, false); + parent::__construct($fq_enum_name); $this->case_name = $case_name; } diff --git a/src/Psalm/Type/Atomic/TGenericObject.php b/src/Psalm/Type/Atomic/TGenericObject.php index 4d0b8c755..20e4e31f3 100644 --- a/src/Psalm/Type/Atomic/TGenericObject.php +++ b/src/Psalm/Type/Atomic/TGenericObject.php @@ -69,7 +69,7 @@ class TGenericObject extends TNamedObject int $php_major_version, int $php_minor_version ): ?string { - return parent::toNamespacedString($namespace, $aliased_classes, $this_class, false); + return $this->toNamespacedString($namespace, $aliased_classes, $this_class, false); } public function equals(Atomic $other_type, bool $ensure_source_equality): bool @@ -98,6 +98,6 @@ class TGenericObject extends TNamedObject public function getChildNodes() : array { - return array_merge($this->type_params, $this->extra_types !== null ? $this->extra_types : []); + return array_merge($this->type_params, $this->extra_types ?? []); } } diff --git a/src/Psalm/Type/Atomic/TIntMask.php b/src/Psalm/Type/Atomic/TIntMask.php index c7db8aa42..abb1e0cbf 100644 --- a/src/Psalm/Type/Atomic/TIntMask.php +++ b/src/Psalm/Type/Atomic/TIntMask.php @@ -40,19 +40,6 @@ class TIntMask extends TInt return 'int-mask<' . substr($s, 0, -2) . '>'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'int' : null; - } - /** * @param array $aliased_classes * @@ -70,7 +57,7 @@ class TIntMask extends TInt $s = ''; foreach ($this->values as $value) { - $s .= $value->toNamespacedString($namespace, $aliased_classes, $this_class, $use_phpdoc_format) . ', '; + $s .= $value->toNamespacedString($namespace, $aliased_classes, $this_class, false) . ', '; } return 'int-mask<' . substr($s, 0, -2) . '>'; diff --git a/src/Psalm/Type/Atomic/TIntMaskOf.php b/src/Psalm/Type/Atomic/TIntMaskOf.php index 27e3f80a5..de4f36c29 100644 --- a/src/Psalm/Type/Atomic/TIntMaskOf.php +++ b/src/Psalm/Type/Atomic/TIntMaskOf.php @@ -29,19 +29,6 @@ class TIntMaskOf extends TInt return $this->getKey(); } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'int' : null; - } - /** * @param array $aliased_classes */ diff --git a/src/Psalm/Type/Atomic/TIntRange.php b/src/Psalm/Type/Atomic/TIntRange.php index c8e9cd35d..0f8032e38 100644 --- a/src/Psalm/Type/Atomic/TIntRange.php +++ b/src/Psalm/Type/Atomic/TIntRange.php @@ -9,8 +9,8 @@ use function min; */ class TIntRange extends TInt { - const BOUND_MIN = 'min'; - const BOUND_MAX = 'max'; + public const BOUND_MIN = 'min'; + public const BOUND_MAX = 'max'; /** * @var int|null @@ -42,19 +42,6 @@ class TIntRange extends TInt return false; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'int' : null; - } - /** * @param array $aliased_classes */ diff --git a/src/Psalm/Type/Atomic/TIterable.php b/src/Psalm/Type/Atomic/TIterable.php index c00215c66..9169cee9e 100644 --- a/src/Psalm/Type/Atomic/TIterable.php +++ b/src/Psalm/Type/Atomic/TIterable.php @@ -121,6 +121,6 @@ class TIterable extends Atomic public function getChildNodes() : array { - return array_merge($this->type_params, $this->extra_types !== null ? $this->extra_types : []); + return array_merge($this->type_params, $this->extra_types ?? []); } } diff --git a/src/Psalm/Type/Atomic/TKeyedArray.php b/src/Psalm/Type/Atomic/TKeyedArray.php index 1ec5c0ff3..8563f0944 100644 --- a/src/Psalm/Type/Atomic/TKeyedArray.php +++ b/src/Psalm/Type/Atomic/TKeyedArray.php @@ -32,7 +32,7 @@ class TKeyedArray extends \Psalm\Type\Atomic /** * @var array|null */ - public $class_strings = null; + public $class_strings; /** * @var bool - whether or not the objectlike has been created from an explicit array @@ -44,14 +44,14 @@ class TKeyedArray extends \Psalm\Type\Atomic * * @var ?Union */ - public $previous_key_type = null; + public $previous_key_type; /** * Whether or not to allow new properties to be asserted on the given array * * @var ?Union */ - public $previous_value_type = null; + public $previous_value_type; /** * @var bool - if this is a list of sequential elements @@ -147,7 +147,7 @@ class TKeyedArray extends \Psalm\Type\Atomic $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + true ); } diff --git a/src/Psalm/Type/Atomic/TList.php b/src/Psalm/Type/Atomic/TList.php index 50a319aa8..05781ad09 100644 --- a/src/Psalm/Type/Atomic/TList.php +++ b/src/Psalm/Type/Atomic/TList.php @@ -68,7 +68,7 @@ class TList extends \Psalm\Type\Atomic $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + true ); } @@ -79,7 +79,7 @@ class TList extends \Psalm\Type\Atomic $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + false ) . '>'; } diff --git a/src/Psalm/Type/Atomic/TLiteralFloat.php b/src/Psalm/Type/Atomic/TLiteralFloat.php index 062603803..7b2ce34a8 100644 --- a/src/Psalm/Type/Atomic/TLiteralFloat.php +++ b/src/Psalm/Type/Atomic/TLiteralFloat.php @@ -24,19 +24,6 @@ class TLiteralFloat extends TFloat return 'float(' . $this->value . ')'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'float' : null; - } - /** * @param array $aliased_classes * diff --git a/src/Psalm/Type/Atomic/TLiteralInt.php b/src/Psalm/Type/Atomic/TLiteralInt.php index 1666ca85c..1b0abec1b 100644 --- a/src/Psalm/Type/Atomic/TLiteralInt.php +++ b/src/Psalm/Type/Atomic/TLiteralInt.php @@ -29,19 +29,6 @@ class TLiteralInt extends TInt return 'int(' . $this->value . ')'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'int' : null; - } - /** * @param array $aliased_classes * diff --git a/src/Psalm/Type/Atomic/TLiteralString.php b/src/Psalm/Type/Atomic/TLiteralString.php index e16aa54c4..e59c92e41 100644 --- a/src/Psalm/Type/Atomic/TLiteralString.php +++ b/src/Psalm/Type/Atomic/TLiteralString.php @@ -23,11 +23,6 @@ class TLiteralString extends TString return 'string(' . $this->value . ')'; } - public function __toString(): string - { - return 'string'; - } - public function getId(bool $nested = false): string { // quote control characters, backslashes and double quote @@ -44,19 +39,6 @@ class TLiteralString extends TString return 'string(' . $this->value . ')'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return $php_major_version >= 7 ? 'string' : null; - } - /** * @param array $aliased_classes * diff --git a/src/Psalm/Type/Atomic/TLowercaseString.php b/src/Psalm/Type/Atomic/TLowercaseString.php index cb78b5200..b8414be8c 100644 --- a/src/Psalm/Type/Atomic/TLowercaseString.php +++ b/src/Psalm/Type/Atomic/TLowercaseString.php @@ -3,11 +3,6 @@ namespace Psalm\Type\Atomic; class TLowercaseString extends TString { - public function getKey(bool $include_extra = true): string - { - return 'string'; - } - public function getId(bool $nested = false): string { return 'lowercase-string'; diff --git a/src/Psalm/Type/Atomic/TNamedObject.php b/src/Psalm/Type/Atomic/TNamedObject.php index feb7de18d..f9bac8935 100644 --- a/src/Psalm/Type/Atomic/TNamedObject.php +++ b/src/Psalm/Type/Atomic/TNamedObject.php @@ -144,6 +144,6 @@ class TNamedObject extends Atomic public function getChildNodes() : array { - return $this->extra_types !== null ? $this->extra_types : []; + return $this->extra_types ?? []; } } diff --git a/src/Psalm/Type/Atomic/TNonEmptyLowercaseString.php b/src/Psalm/Type/Atomic/TNonEmptyLowercaseString.php index d01324013..3ab6ab6bf 100644 --- a/src/Psalm/Type/Atomic/TNonEmptyLowercaseString.php +++ b/src/Psalm/Type/Atomic/TNonEmptyLowercaseString.php @@ -6,11 +6,6 @@ namespace Psalm\Type\Atomic; */ class TNonEmptyLowercaseString extends TNonEmptyString { - public function getKey(bool $include_extra = true): string - { - return 'string'; - } - public function getId(bool $nested = false): string { return 'non-empty-lowercase-string'; diff --git a/src/Psalm/Type/Atomic/TNonEmptyNonspecificLiteralString.php b/src/Psalm/Type/Atomic/TNonEmptyNonspecificLiteralString.php index 4b6f5657a..9eee2fd1f 100644 --- a/src/Psalm/Type/Atomic/TNonEmptyNonspecificLiteralString.php +++ b/src/Psalm/Type/Atomic/TNonEmptyNonspecificLiteralString.php @@ -7,11 +7,6 @@ namespace Psalm\Type\Atomic; */ class TNonEmptyNonspecificLiteralString extends TNonspecificLiteralString { - public function getKey(bool $include_extra = true): string - { - return 'string'; - } - public function getId(bool $nested = false): string { return 'non-empty-literal-string'; diff --git a/src/Psalm/Type/Atomic/TNonspecificLiteralInt.php b/src/Psalm/Type/Atomic/TNonspecificLiteralInt.php index 99e20ef04..09481333a 100644 --- a/src/Psalm/Type/Atomic/TNonspecificLiteralInt.php +++ b/src/Psalm/Type/Atomic/TNonspecificLiteralInt.php @@ -12,11 +12,6 @@ class TNonspecificLiteralInt extends TInt return 'literal-int'; } - public function getKey(bool $include_extra = true) : string - { - return 'int'; - } - public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_version): bool { return false; diff --git a/src/Psalm/Type/Atomic/TNonspecificLiteralString.php b/src/Psalm/Type/Atomic/TNonspecificLiteralString.php index 5a688b596..4d57f6378 100644 --- a/src/Psalm/Type/Atomic/TNonspecificLiteralString.php +++ b/src/Psalm/Type/Atomic/TNonspecificLiteralString.php @@ -12,11 +12,6 @@ class TNonspecificLiteralString extends TString return 'literal-string'; } - public function getKey(bool $include_extra = true) : string - { - return 'string'; - } - public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_version): bool { return false; diff --git a/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php b/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php index 517e12ff5..4af9887df 100644 --- a/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php +++ b/src/Psalm/Type/Atomic/TTemplateIndexedAccess.php @@ -60,17 +60,4 @@ class TTemplateIndexedAccess extends \Psalm\Type\Atomic { return false; } - - /** - * @param array $aliased_classes - * - */ - public function toNamespacedString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - bool $use_phpdoc_format - ): string { - return $this->getKey(); - } } diff --git a/src/Psalm/Type/Atomic/TTemplateKeyOf.php b/src/Psalm/Type/Atomic/TTemplateKeyOf.php index 09958050b..f0982d039 100644 --- a/src/Psalm/Type/Atomic/TTemplateKeyOf.php +++ b/src/Psalm/Type/Atomic/TTemplateKeyOf.php @@ -48,27 +48,6 @@ class TTemplateKeyOf extends TArrayKey return 'key-of<' . $this->param_name . ':' . $this->defining_class . ' as ' . $this->as->getId() . '>'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return null; - } - - /** - * @return false - */ - public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_version): bool - { - return false; - } - /** * @param array $aliased_classes */ diff --git a/src/Psalm/Type/Atomic/TTemplateParam.php b/src/Psalm/Type/Atomic/TTemplateParam.php index 1ef9d2eec..b9e5ebc21 100644 --- a/src/Psalm/Type/Atomic/TTemplateParam.php +++ b/src/Psalm/Type/Atomic/TTemplateParam.php @@ -100,7 +100,7 @@ class TTemplateParam extends \Psalm\Type\Atomic $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + true ); } @@ -108,7 +108,7 @@ class TTemplateParam extends \Psalm\Type\Atomic $namespace, $aliased_classes, $this_class, - $use_phpdoc_format + false ); return $this->param_name . $intersection_types; diff --git a/src/Psalm/Type/Atomic/TTemplateParamClass.php b/src/Psalm/Type/Atomic/TTemplateParamClass.php index 6dca3507d..9e50cceba 100644 --- a/src/Psalm/Type/Atomic/TTemplateParamClass.php +++ b/src/Psalm/Type/Atomic/TTemplateParamClass.php @@ -49,24 +49,6 @@ class TTemplateParamClass extends TClassString return 'class-string<' . $this->param_name . '>'; } - /** - * @param array $aliased_classes - */ - public function toPhpString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - int $php_major_version, - int $php_minor_version - ): ?string { - return 'string'; - } - - public function canBeFullyExpressedInPhp(int $php_major_version, int $php_minor_version): bool - { - return false; - } - /** * @param array $aliased_classes * @@ -79,9 +61,4 @@ class TTemplateParamClass extends TClassString ): string { return $this->param_name . '::class'; } - - public function getChildNodes() : array - { - return $this->as_type ? [$this->as_type] : []; - } } diff --git a/src/Psalm/Type/Atomic/TTypeAlias.php b/src/Psalm/Type/Atomic/TTypeAlias.php index 197afd0a1..1003c288c 100644 --- a/src/Psalm/Type/Atomic/TTypeAlias.php +++ b/src/Psalm/Type/Atomic/TTypeAlias.php @@ -78,19 +78,6 @@ class TTypeAlias extends \Psalm\Type\Atomic return false; } - /** - * @param array $aliased_classes - * - */ - public function toNamespacedString( - ?string $namespace, - array $aliased_classes, - ?string $this_class, - bool $use_phpdoc_format - ): string { - return $this->getKey(); - } - public function getAssertionString(bool $exact = false): string { return 'mixed'; diff --git a/src/Psalm/Type/Reconciler.php b/src/Psalm/Type/Reconciler.php index cfec9f321..0f9334af6 100644 --- a/src/Psalm/Type/Reconciler.php +++ b/src/Psalm/Type/Reconciler.php @@ -102,10 +102,8 @@ class Reconciler foreach ($new_type_parts as $new_type_part_parts) { foreach ($new_type_part_parts as $new_type_part_part) { - switch ($new_type_part_part[0]) { - case '!': - $has_negation = true; - break; + if ($new_type_part_part[0] === '!') { + $has_negation = true; } $has_isset = $has_isset diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 00c0ca9e4..1f19e8f0b 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -26,7 +26,6 @@ use function implode; use function reset; use function sort; use function strpos; -use function strval; class Union implements TypeNode { @@ -80,7 +79,7 @@ class Union implements TypeNode * * @var ?string */ - public $initialized_class = null; + public $initialized_class; /** * Whether or not the type has been checked yet @@ -336,7 +335,7 @@ class Union implements TypeNode $printed_int = true; } - $types[] = strval($type); + $types[] = (string)$type; } sort($types); @@ -374,7 +373,7 @@ class Union implements TypeNode $types[] = 'int'; $printed_int = true; } else { - $types[] = strval($type->getKey()); + $types[] = $type->getKey(); } } @@ -390,7 +389,7 @@ class Union implements TypeNode $types = []; foreach ($this->types as $type) { - $types[] = strval($type->getId()); + $types[] = $type->getId(); } sort($types); @@ -637,7 +636,7 @@ class Union implements TypeNode public function hasArrayAccessInterface(Codebase $codebase) : bool { - return !!array_filter( + return (bool)array_filter( $this->types, function ($type) use ($codebase) { return $type->hasArrayAccessInterface($codebase);