diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index 7531fcbd4a8..97c5564b33b 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -741,7 +741,7 @@ public function isPhantomClass(string $class_name): bool return isset($this->phantom_classes[strtolower($class_name)]); } - public function hasVariable(?string $var_name): bool + public function hasVariable(string $var_name): bool { if (!$var_name) { return false; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php index 8834b73a5f8..8a9ec5c5846 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfConditionalAnalyzer.php @@ -34,7 +34,7 @@ public static function analyze( Context $outer_context, Codebase $codebase, IfScope $if_scope, - ?int $branch_point + int $branch_point ): IfConditionalScope { $entry_clauses = []; diff --git a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php index 55e99db67ca..de9a0169021 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Block/IfElse/ElseIfAnalyzer.php @@ -44,7 +44,7 @@ public static function analyze( Context $else_context, Context $outer_context, Codebase $codebase, - ?int $branch_point + int $branch_point ): ?bool { $pre_conditional_context = clone $else_context; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php index 1261f421007..5cfba7e5ea4 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/ArgumentsAnalyzer.php @@ -908,7 +908,7 @@ public static function checkArgumentsMatch( private static function handlePossiblyMatchingByRefParam( StatementsAnalyzer $statements_analyzer, Codebase $codebase, - ?string $method_id, + string $method_id, ?string $cased_method_id, ?FunctionLikeParameter $last_param, array $function_params, 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 999c0e2e026..ac0f5d241e2 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/AtomicMethodCallAnalyzer.php @@ -443,7 +443,6 @@ public static function analyze( $result, $return_type_candidate, $all_intersection_return_type, - $method_name_lc, $codebase ); } @@ -518,28 +517,19 @@ private static function getIntersectionReturnType( private static function updateResultReturnType( AtomicMethodCallAnalysisResult $result, - ?Type\Union $return_type_candidate, + Type\Union $return_type_candidate, ?Type\Union $all_intersection_return_type, - string $method_name, Codebase $codebase ) : void { - if ($return_type_candidate) { - if ($all_intersection_return_type) { - $return_type_candidate = Type::intersectUnionTypes( - $all_intersection_return_type, - $return_type_candidate, - $codebase - ) ?: Type::getMixed(); - } - - $result->return_type = Type::combineUnionTypes($return_type_candidate, $result->return_type); - } elseif ($all_intersection_return_type) { - $result->return_type = Type::combineUnionTypes($all_intersection_return_type, $result->return_type); - } elseif ($method_name === '__tostring') { - $result->return_type = Type::getString(); - } else { - $result->return_type = Type::getMixed(); + if ($all_intersection_return_type) { + $return_type_candidate = Type::intersectUnionTypes( + $all_intersection_return_type, + $return_type_candidate, + $codebase + ) ?: Type::getMixed(); } + + $result->return_type = Type::combineUnionTypes($return_type_candidate, $result->return_type); } private static function handleInvalidClass( diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php index 2ff025c092d..d0005b161c8 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/Method/MethodCallPurityAnalyzer.php @@ -20,7 +20,7 @@ public static function analyze( Codebase $codebase, PhpParser\Node\Expr\MethodCall $stmt, ?string $lhs_var_id, - ?string $cased_method_id, + string $cased_method_id, MethodIdentifier $method_id, \Psalm\Storage\MethodStorage $method_storage, \Psalm\Storage\ClassLikeStorage $class_storage, diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php index 12c55403a1a..af3fd3be909 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Call/NamedFunctionCallHandler.php @@ -439,7 +439,7 @@ private static function handleDependentTypeFunction( StatementsAnalyzer $statements_analyzer, PhpParser\Node\Expr\FuncCall $stmt, PhpParser\Node\Expr\FuncCall $real_stmt, - ?string $function_id, + string $function_id, Context $context ) : void { $first_arg = isset($stmt->args[0]) ? $stmt->args[0] : null; diff --git a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php index e6264d77bd4..3fd4a4ab2df 100644 --- a/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php +++ b/src/Psalm/Internal/Analyzer/Statements/Expression/Fetch/ConstFetchAnalyzer.php @@ -100,7 +100,7 @@ public static function analyze( public static function getGlobalConstType( Codebase $codebase, - ?string $fq_const_name, + string $fq_const_name, string $const_name ): ?Type\Union { if ($const_name === 'STDERR' diff --git a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php index 3ad11746392..178f359fcc9 100644 --- a/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php +++ b/src/Psalm/Internal/Provider/ClassLikeStorageCacheProvider.php @@ -68,7 +68,7 @@ public function __construct(Config $config) $this->modified_timestamps .= $this->config->computeHash(); } - public function writeToCache(ClassLikeStorage $storage, ?string $file_path, ?string $file_contents): void + public function writeToCache(ClassLikeStorage $storage, string $file_path, string $file_contents): void { $fq_classlike_name_lc = strtolower($storage->name); diff --git a/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php b/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php index 41ec69f733f..d1c2c4a700e 100644 --- a/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php +++ b/src/Psalm/Internal/Provider/ClassLikeStorageProvider.php @@ -53,7 +53,7 @@ public function has(string $fq_classlike_name): bool return isset(self::$storage[$fq_classlike_name_lc]); } - public function exhume(string $fq_classlike_name, ?string $file_path, ?string $file_contents): ClassLikeStorage + public function exhume(string $fq_classlike_name, string $file_path, string $file_contents): ClassLikeStorage { $fq_classlike_name_lc = strtolower($fq_classlike_name);