From 4fd46e1752382691eb0965809b36ac8b9bb55680 Mon Sep 17 00:00:00 2001 From: Matthew Brown Date: Wed, 24 May 2017 22:07:49 -0400 Subject: [PATCH] Improve formatting --- src/Psalm/Checker/ClassChecker.php | 2 +- src/Psalm/Checker/ClassLikeChecker.php | 6 +-- src/Psalm/Checker/CommentChecker.php | 2 +- src/Psalm/Checker/FileChecker.php | 6 +-- src/Psalm/Checker/FunctionChecker.php | 11 +++-- src/Psalm/Checker/FunctionLikeChecker.php | 20 ++++----- src/Psalm/Checker/InterfaceChecker.php | 6 +-- src/Psalm/Checker/MethodChecker.php | 5 +-- src/Psalm/Checker/ProjectChecker.php | 27 ++++++------ .../Statements/Block/ForeachChecker.php | 3 +- .../Statements/Block/SwitchChecker.php | 1 + .../Statements/Expression/AssertionFinder.php | 4 +- .../Expression/AssignmentChecker.php | 1 + .../Statements/Expression/CallChecker.php | 1 - .../Statements/Expression/FetchChecker.php | 6 +++ .../Checker/Statements/ExpressionChecker.php | 14 +++++- src/Psalm/Checker/StatementsChecker.php | 6 +-- src/Psalm/Checker/TraitChecker.php | 4 +- src/Psalm/Checker/TypeChecker.php | 4 +- src/Psalm/Config.php | 1 - src/Psalm/Config/ErrorLevelFileFilter.php | 2 +- src/Psalm/Config/FileFilter.php | 6 +-- src/Psalm/Config/ProjectFileFilter.php | 4 +- src/Psalm/Context.php | 3 +- src/Psalm/IssueBuffer.php | 5 ++- src/Psalm/Provider/FileProvider.php | 2 +- src/Psalm/Provider/FileReferenceProvider.php | 1 + src/Psalm/Stubs/CoreGenericClasses.php | 4 +- src/Psalm/Type.php | 2 + src/Psalm/Type/Atomic.php | 6 +-- src/Psalm/Type/Atomic/GenericTrait.php | 1 + src/Psalm/Type/Atomic/TNamedObject.php | 3 +- src/Psalm/Type/Union.php | 43 ++++++++++--------- tests/FunctionCallTest.php | 4 +- tests/MethodSignatureTest.php | 2 + tests/Php56Test.php | 2 +- tests/Php70Test.php | 2 +- tests/Php71Test.php | 2 +- tests/TemplateTest.php | 2 +- .../FileCheckerValidCodeParseTestTrait.php | 1 + 40 files changed, 128 insertions(+), 99 deletions(-) diff --git a/src/Psalm/Checker/ClassChecker.php b/src/Psalm/Checker/ClassChecker.php index e97d8c736..22c1486b8 100644 --- a/src/Psalm/Checker/ClassChecker.php +++ b/src/Psalm/Checker/ClassChecker.php @@ -7,7 +7,7 @@ use Psalm\StatementsSource; class ClassChecker extends ClassLikeChecker { /** - * @var integer + * @var int */ protected static $anonymous_class_count = 0; diff --git a/src/Psalm/Checker/ClassLikeChecker.php b/src/Psalm/Checker/ClassLikeChecker.php index d91efb4c7..5cbc3482b 100644 --- a/src/Psalm/Checker/ClassLikeChecker.php +++ b/src/Psalm/Checker/ClassLikeChecker.php @@ -743,7 +743,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc * @param StatementsSource $source * @param Context $class_context * @param Context|null $global_context - * @param boolean $update_docblocks + * @param bool $update_docblocks * @return MethodChecker|null */ private function analyzeClassMethod( @@ -1979,7 +1979,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc /** * @param string $fq_class_name - * @return boolean + * @return bool */ public static function isUserDefined($fq_class_name) { @@ -2000,7 +2000,7 @@ abstract class ClassLikeChecker extends SourceChecker implements StatementsSourc } /** @var array> */ - $property_map = require_once(__DIR__.'/../PropertyMap.php'); + $property_map = require_once(__DIR__ . '/../PropertyMap.php'); self::$property_map = []; diff --git a/src/Psalm/Checker/CommentChecker.php b/src/Psalm/Checker/CommentChecker.php index 893ac33f6..670c0c2e9 100644 --- a/src/Psalm/Checker/CommentChecker.php +++ b/src/Psalm/Checker/CommentChecker.php @@ -399,7 +399,7 @@ class CommentChecker $last = false; } elseif ($last !== false) { $old_last_line = $lines[$last]; - $lines[$last] = rtrim($old_last_line) .' '. trim($line); + $lines[$last] = rtrim($old_last_line) . ' ' . trim($line); if ($line_number) { $old_line_number = $line_map[$old_last_line]; diff --git a/src/Psalm/Checker/FileChecker.php b/src/Psalm/Checker/FileChecker.php index 9cda6139d..21c853211 100644 --- a/src/Psalm/Checker/FileChecker.php +++ b/src/Psalm/Checker/FileChecker.php @@ -247,8 +247,8 @@ class FileChecker extends SourceChecker implements StatementsSource } /** - * @param boolean $update_docblocks - * @param boolean $preserve_checkers + * @param bool $update_docblocks + * @param bool $preserve_checkers * @return void */ public function analyze($update_docblocks = false, $preserve_checkers = false) @@ -378,7 +378,7 @@ class FileChecker extends SourceChecker implements StatementsSource /** * @param Context|null $file_context - * @param boolean $update_docblocks + * @param bool $update_docblocks * @return void */ public function visitAndAnalyzeMethods(Context $file_context = null, $update_docblocks = false) diff --git a/src/Psalm/Checker/FunctionChecker.php b/src/Psalm/Checker/FunctionChecker.php index 5fb614a0a..c20b15f1f 100644 --- a/src/Psalm/Checker/FunctionChecker.php +++ b/src/Psalm/Checker/FunctionChecker.php @@ -48,7 +48,7 @@ class FunctionChecker extends FunctionLikeChecker /** * @param string $function_id * @param string $file_path - * @return boolean + * @return bool */ public static function functionExists($function_id, $file_path) { @@ -104,7 +104,7 @@ class FunctionChecker extends FunctionLikeChecker /** * @param string $function_id * @param string $file_path - * @return boolean + * @return bool */ public static function isVariadic($function_id, $file_path) { @@ -459,7 +459,7 @@ class FunctionChecker extends FunctionLikeChecker $inner_type = $first_arg_array->type_params[1]; $key_type = clone $first_arg_array->type_params[0]; } else { - $inner_type = $first_arg_array->getGenericTypeParam(); + $inner_type = $first_arg_array->getGenericTypeParam(); $key_type = Type::getString(); } @@ -529,6 +529,7 @@ class FunctionChecker extends FunctionLikeChecker if ($call_map_key === 'array_map') { $inner_type = clone $closure_return_type; + return new Type\Union([ new Type\Atomic\TArray([ $key_type, @@ -539,6 +540,7 @@ class FunctionChecker extends FunctionLikeChecker if ($array_arg_type) { $inner_type = clone $array_arg_type->type_params[1]; + return new Type\Union([ new Type\Atomic\TArray([ $key_type, @@ -554,6 +556,7 @@ class FunctionChecker extends FunctionLikeChecker if (isset($call_map[$mapped_function_id][0])) { if ($call_map[$mapped_function_id][0]) { $mapped_function_return = Type::parseString($call_map[$mapped_function_id][0]); + return new Type\Union([ new Type\Atomic\TArray([ Type::getInt(), @@ -585,7 +588,7 @@ class FunctionChecker extends FunctionLikeChecker } /** @var array> */ - $call_map = require_once(__DIR__.'/../CallMap.php'); + $call_map = require_once(__DIR__ . '/../CallMap.php'); self::$call_map = []; diff --git a/src/Psalm/Checker/FunctionLikeChecker.php b/src/Psalm/Checker/FunctionLikeChecker.php index e9b238c4e..2cb27dcd1 100644 --- a/src/Psalm/Checker/FunctionLikeChecker.php +++ b/src/Psalm/Checker/FunctionLikeChecker.php @@ -176,7 +176,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo $parent_method_id = MethodChecker::getCasedMethodId($implemented_method_id); if (IssueBuffer::accepts( new OverriddenMethodAccess( - 'Method ' . $cased_method_id .' has different access level than ' . $parent_method_id, + 'Method ' . $cased_method_id . ' has different access level than ' . $parent_method_id, new CodeLocation($this, $this->function, true) ) )) { @@ -194,7 +194,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo if (IssueBuffer::accepts( new MethodSignatureMismatch( - 'Method ' . $cased_method_id .' has fewer arguments than parent method ' . + 'Method ' . $cased_method_id . ' has fewer arguments than parent method ' . $parent_method_id, new CodeLocation($this, $this->function, true) ) @@ -214,7 +214,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo if (IssueBuffer::accepts( new MethodSignatureMismatch( - 'Argument ' . ($i + 1) . ' of ' . $cased_method_id .' has wrong type \'' . + 'Argument ' . ($i + 1) . ' of ' . $cased_method_id . ' has wrong type \'' . $storage->params[$i]->signature_type . '\', expecting \'' . $implemented_param->signature_type . '\' as defined by ' . $parent_method_id, @@ -237,7 +237,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo if (IssueBuffer::accepts( new MethodSignatureMismatch( - 'Argument ' . ($i + 1) . ' of ' . $cased_method_id .' has wrong type \'' . + 'Argument ' . ($i + 1) . ' of ' . $cased_method_id . ' has wrong type \'' . $storage->params[$i]->type . '\', expecting \'' . $implemented_param->type . '\' as defined by ' . $parent_method_id, @@ -259,7 +259,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo if (IssueBuffer::accepts( new MethodSignatureMismatch( - 'Method ' . $cased_method_id .' has more arguments than parent method ' . + 'Method ' . $cased_method_id . ' has more arguments than parent method ' . $parent_method_id, new CodeLocation($this, $this->function, true) ) @@ -1268,7 +1268,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo if (IssueBuffer::accepts( new InvalidDocblock( - 'Parameter $' . $param_name .' does not appear in the argument list for ' . + 'Parameter $' . $param_name . ' does not appear in the argument list for ' . $cased_method_id, $code_location ) @@ -1325,7 +1325,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo $code_location->setCommentLine($line_number); if (IssueBuffer::accepts( new InvalidDocblock( - 'Parameter $' . $param_name .' has wrong type \'' . $new_param_type . '\', should be \'' . + 'Parameter $' . $param_name . ' has wrong type \'' . $new_param_type . '\', should be \'' . $storage_param_type . '\'', $code_location ) @@ -1361,7 +1361,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo ) { if (IssueBuffer::accepts( new InvalidDocblock( - 'Parameter $' . $function_signature_param->name .' does not appear in the docbock for ' . + 'Parameter $' . $function_signature_param->name . ' does not appear in the docbock for ' . $cased_method_id, $function_signature_param->location ) @@ -1606,7 +1606,7 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo return self::getMatchingParamsFromCallMapOptions($function_param_options, $args, $file_checker); } - /** + /** * @param array> $function_param_options * @param array $args * @param FileChecker $file_checker @@ -1698,8 +1698,6 @@ abstract class FunctionLikeChecker extends SourceChecker implements StatementsSo $this->suppressed_issues = array_merge($this->suppressed_issues, $suppressed_issues); } - - /** * @return void */ diff --git a/src/Psalm/Checker/InterfaceChecker.php b/src/Psalm/Checker/InterfaceChecker.php index 66aec6433..c499ce774 100644 --- a/src/Psalm/Checker/InterfaceChecker.php +++ b/src/Psalm/Checker/InterfaceChecker.php @@ -41,7 +41,7 @@ class InterfaceChecker extends ClassLikeChecker /** * @param string $fq_interface_name * @param FileChecker $file_checker - * @return boolean + * @return bool */ public static function interfaceExists($fq_interface_name, FileChecker $file_checker) { @@ -59,7 +59,7 @@ class InterfaceChecker extends ClassLikeChecker /** * @param string $fq_interface_name * @param FileChecker $file_checker - * @return boolean + * @return bool */ public static function hasCorrectCasing($fq_interface_name, FileChecker $file_checker) { @@ -70,7 +70,7 @@ class InterfaceChecker extends ClassLikeChecker * @param string $interface_name * @param string $possible_parent * @param FileChecker $file_checker - * @return boolean + * @return bool */ public static function interfaceExtends($interface_name, $possible_parent, FileChecker $file_checker) { diff --git a/src/Psalm/Checker/MethodChecker.php b/src/Psalm/Checker/MethodChecker.php index 36b927c4e..3f1bcce69 100644 --- a/src/Psalm/Checker/MethodChecker.php +++ b/src/Psalm/Checker/MethodChecker.php @@ -48,7 +48,7 @@ class MethodChecker extends FunctionLikeChecker /** * @param string $method_id - * @return boolean + * @return bool */ public static function isVariadic($method_id) { @@ -183,7 +183,6 @@ class MethodChecker extends FunctionLikeChecker ? ClassLikeChecker::VISIBILITY_PRIVATE : ($method->isProtected() ? ClassLikeChecker::VISIBILITY_PROTECTED : ClassLikeChecker::VISIBILITY_PUBLIC); - $possible_params = FunctionChecker::getParamsFromCallMap($method_id); if ($possible_params === null) { @@ -637,6 +636,6 @@ class MethodChecker extends FunctionLikeChecker list($fq_class_name) = explode('::', $method_id); - return $fq_class_name . '::' .$storage->cased_name; + return $fq_class_name . '::' . $storage->cased_name; } } diff --git a/src/Psalm/Checker/ProjectChecker.php b/src/Psalm/Checker/ProjectChecker.php index 2fc5e1fd2..e55159542 100644 --- a/src/Psalm/Checker/ProjectChecker.php +++ b/src/Psalm/Checker/ProjectChecker.php @@ -33,14 +33,14 @@ class ProjectChecker /** * Whether or not to use colors in error output * - * @var boolean + * @var bool */ public $use_color; /** * Whether or not to show informational messages * - * @var boolean + * @var bool */ public $show_info; @@ -65,12 +65,12 @@ class ProjectChecker public $debug_output = false; /** - * @var boolean + * @var bool */ public $update_docblocks = false; /** - * @var boolean + * @var bool */ public $cache = false; @@ -176,14 +176,14 @@ class ProjectChecker public $fake_files = []; /** - * @var boolean + * @var bool */ public $server_mode = false; /** * Whether to log functions just at the file level or globally (for stubs) * - * @var boolean + * @var bool */ public $register_global_functions = false; @@ -192,9 +192,9 @@ class ProjectChecker const TYPE_EMACS = 'emacs'; /** - * @param boolean $use_color - * @param boolean $show_info - * @param boolean $debug_output + * @param bool $use_color + * @param bool $show_info + * @param bool $debug_output * @param string $output_format * @param bool $update_docblocks * @param bool $collect_references @@ -234,7 +234,7 @@ class ProjectChecker /** * @param string $base_dir - * @param boolean $is_diff + * @param bool $is_diff * @return void */ public function check($base_dir, $is_diff = false) @@ -709,7 +709,7 @@ class ProjectChecker } if ($this->debug_output) { - echo (isset($this->visited_files[$file_path]) ? 'Rev' : 'V') . 'isiting ' . $file_path . PHP_EOL; + echo(isset($this->visited_files[$file_path]) ? 'Rev' : 'V') . 'isiting ' . $file_path . PHP_EOL; } $this->visited_files[$file_path] = true; @@ -724,7 +724,7 @@ class ProjectChecker * for later checking * * @param string $fq_class_name - * @return boolean + * @return bool * @psalm-suppress MixedMethodCall due to Reflection class weirdness */ public function fileExistsForClassLike($fq_class_name) @@ -745,6 +745,7 @@ class ProjectChecker $this->visited_classes[$fq_class_name_ci] = true; $reflected_class = new \ReflectionClass($fq_class_name); ClassLikeChecker::registerReflectedClass($reflected_class->name, $reflected_class, $this); + return true; } @@ -787,7 +788,7 @@ class ProjectChecker /** * @param string $fq_class_name - * @return boolean + * @return bool * @psalm-suppress MixedMethodCall due to Reflection class weirdness */ public function visitFileForClassLike($fq_class_name) diff --git a/src/Psalm/Checker/Statements/Block/ForeachChecker.php b/src/Psalm/Checker/Statements/Block/ForeachChecker.php index aac0a9e66..ef41032fc 100644 --- a/src/Psalm/Checker/Statements/Block/ForeachChecker.php +++ b/src/Psalm/Checker/Statements/Block/ForeachChecker.php @@ -12,10 +12,9 @@ use Psalm\Checker\StatementsChecker; use Psalm\CodeLocation; use Psalm\Context; use Psalm\Issue\InvalidIterator; -use Psalm\IssueBuffer; use Psalm\Issue\NullIterator; -use Psalm\Issue\NullReference; use Psalm\Issue\PossiblyNullIterator; +use Psalm\IssueBuffer; use Psalm\Type; class ForeachChecker diff --git a/src/Psalm/Checker/Statements/Block/SwitchChecker.php b/src/Psalm/Checker/Statements/Block/SwitchChecker.php index a6be6c9ac..90cfb2f2b 100644 --- a/src/Psalm/Checker/Statements/Block/SwitchChecker.php +++ b/src/Psalm/Checker/Statements/Block/SwitchChecker.php @@ -232,6 +232,7 @@ class SwitchChecker } $context->vars_possibly_in_scope = array_merge($context->vars_possibly_in_scope, $new_vars_possibly_in_scope); + return null; } } diff --git a/src/Psalm/Checker/Statements/Expression/AssertionFinder.php b/src/Psalm/Checker/Statements/Expression/AssertionFinder.php index c520a2416..d2237314c 100644 --- a/src/Psalm/Checker/Statements/Expression/AssertionFinder.php +++ b/src/Psalm/Checker/Statements/Expression/AssertionFinder.php @@ -515,7 +515,7 @@ class AssertionFinder * @param array &$if_types * @param string|null $this_class_name * @param StatementsSource $source - * @param boolean $negate + * @param bool $negate * @return void */ protected static function processFunctionCall( @@ -822,7 +822,7 @@ class AssertionFinder { if ($stmt->name instanceof PhpParser\Node\Name && ($stmt->name->parts === ['is_int'] || - $stmt->name->parts === ['is_integer']|| + $stmt->name->parts === ['is_integer'] || $stmt->name->parts === ['is_long']) ) { return true; diff --git a/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php b/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php index 39a11c172..25f3a24cc 100644 --- a/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php +++ b/src/Psalm/Checker/Statements/Expression/AssignmentChecker.php @@ -708,6 +708,7 @@ class AssignmentChecker if ($var_id && count($class_property_types) === 1 && isset($class_property_types[0]->types['stdClass'])) { $context->vars_in_scope[$var_id] = Type::getMixed(); + return null; } diff --git a/src/Psalm/Checker/Statements/Expression/CallChecker.php b/src/Psalm/Checker/Statements/Expression/CallChecker.php index 7a685a4c9..1e23e3d68 100644 --- a/src/Psalm/Checker/Statements/Expression/CallChecker.php +++ b/src/Psalm/Checker/Statements/Expression/CallChecker.php @@ -1130,7 +1130,6 @@ class CallChecker ); } - if (!$does_class_exist) { return $does_class_exist; } diff --git a/src/Psalm/Checker/Statements/Expression/FetchChecker.php b/src/Psalm/Checker/Statements/Expression/FetchChecker.php index 3aea0e6dd..57365abaf 100644 --- a/src/Psalm/Checker/Statements/Expression/FetchChecker.php +++ b/src/Psalm/Checker/Statements/Expression/FetchChecker.php @@ -88,6 +88,7 @@ class FetchChecker if ($var_id && $context->hasVariable($var_id)) { // we don't need to check anything $stmt->inferredType = $context->vars_in_scope[$var_id]; + return null; } @@ -447,6 +448,7 @@ class FetchChecker $statements_checker->getFileChecker()->containsUnEvaluatedClassLike($fq_class_name) ) { $stmt->inferredType = Type::getString(); + return null; } @@ -462,12 +464,14 @@ class FetchChecker if ($stmt->name === 'class') { $stmt->inferredType = Type::getString(); + return null; } // if we're ignoring that the class doesn't exist, exit anyway if (!ClassLikeChecker::classOrInterfaceExists($fq_class_name, $statements_checker->getFileChecker())) { $stmt->inferredType = Type::getMixed(); + return null; } @@ -618,6 +622,7 @@ class FetchChecker if ($var_id && $context->hasVariable($var_id)) { // we don't need to check anything $stmt->inferredType = $context->vars_in_scope[$var_id]; + return null; } @@ -1234,6 +1239,7 @@ class FetchChecker if ($type->type_params[1]->isEmpty()) { $type->type_params[0] = $assignment_key_type; $type->type_params[1] = $assignment_value_type; + return $type; } diff --git a/src/Psalm/Checker/Statements/ExpressionChecker.php b/src/Psalm/Checker/Statements/ExpressionChecker.php index 8649f1b2a..491e900ad 100644 --- a/src/Psalm/Checker/Statements/ExpressionChecker.php +++ b/src/Psalm/Checker/Statements/ExpressionChecker.php @@ -526,6 +526,7 @@ class ExpressionChecker ) ) { $stmt->inferredType = Type::getArray(); + return null; } @@ -535,6 +536,7 @@ class ExpressionChecker if ($passed_by_reference && $by_ref_type) { self::assignByRefParam($statements_checker, $stmt, $by_ref_type, $context); + return null; } @@ -575,7 +577,7 @@ class ExpressionChecker if ($first_appearance) { if (IssueBuffer::accepts( new PossiblyUndefinedVariable( - 'Possibly undefined variable ' . $var_name .', first seen on line ' . + 'Possibly undefined variable ' . $var_name . ', first seen on line ' . $first_appearance->getLineNumber(), new CodeLocation($statements_checker->getSource(), $stmt) ), @@ -635,6 +637,7 @@ class ExpressionChecker if ((string)$existing_type !== 'array') { $context->vars_in_scope[$var_id] = $by_ref_type; $stmt->inferredType = $context->vars_in_scope[$var_id]; + return; } } @@ -659,6 +662,7 @@ class ExpressionChecker // if the array is empty, this special type allows us to match any other array type against it if (empty($stmt->items)) { $stmt->inferredType = Type::getEmptyArray(); + return null; } @@ -727,6 +731,7 @@ class ExpressionChecker $can_create_objectlike ) { $stmt->inferredType = new Type\Union([new Type\Atomic\ObjectLike($property_types)]); + return null; } @@ -1113,6 +1118,7 @@ class ExpressionChecker } $result_type = Type::getMixed(); + return; } @@ -1142,6 +1148,7 @@ class ExpressionChecker } $result_type = Type::getArray(); + return; } @@ -1431,6 +1438,7 @@ class ExpressionChecker if ($stmt instanceof PhpParser\Node\Expr\ArrayDimFetch && $nesting !== null) { $nesting++; + return self::getVarId($stmt->var, $this_class_name, $source, $nesting); } @@ -1552,6 +1560,7 @@ class ExpressionChecker if (!$statements_checker->hasVariable($use_var_id)) { $statements_checker->registerVariable($use_var_id, new CodeLocation($statements_checker, $use)); } + return; } @@ -1860,6 +1869,7 @@ class ExpressionChecker } $stmt->inferredType = Type::getString(); + return null; } @@ -1959,7 +1969,7 @@ class ExpressionChecker /** * @param string $fq_class_name - * @return boolean + * @return bool */ public static function isMock($fq_class_name) { diff --git a/src/Psalm/Checker/StatementsChecker.php b/src/Psalm/Checker/StatementsChecker.php index bf363a901..5b176af73 100644 --- a/src/Psalm/Checker/StatementsChecker.php +++ b/src/Psalm/Checker/StatementsChecker.php @@ -95,7 +95,6 @@ class StatementsChecker extends SourceChecker implements StatementsSource } } - if ($has_returned && !($stmt instanceof PhpParser\Node\Stmt\Nop) && !($stmt instanceof PhpParser\Node\Stmt\InlineHTML) ) { @@ -700,8 +699,6 @@ class StatementsChecker extends SourceChecker implements StatementsSource $stmt->inferredType = Type::getVoid(); } - - if ($this->source instanceof FunctionLikeChecker) { $this->source->addReturnTypes($stmt->expr ? (string) $stmt->inferredType : '', $context); } @@ -813,6 +810,7 @@ class StatementsChecker extends SourceChecker implements StatementsSource $context->check_classes = false; $context->check_variables = false; $context->check_functions = false; + return null; } @@ -871,6 +869,8 @@ class StatementsChecker extends SourceChecker implements StatementsSource /** * @return string|null + * @param mixed $file_name + * @param mixed $current_directory */ /** diff --git a/src/Psalm/Checker/TraitChecker.php b/src/Psalm/Checker/TraitChecker.php index 316d2ff6a..97d614b96 100644 --- a/src/Psalm/Checker/TraitChecker.php +++ b/src/Psalm/Checker/TraitChecker.php @@ -87,7 +87,7 @@ class TraitChecker extends ClassLikeChecker /** * @param string $fq_trait_name * @param FileChecker $file_checker - * @return boolean + * @return bool */ public static function traitExists($fq_trait_name, FileChecker $file_checker) { @@ -101,7 +101,7 @@ class TraitChecker extends ClassLikeChecker /** * @param string $fq_trait_name * @param FileChecker $file_checker - * @return boolean + * @return bool */ public static function hasCorrectCase($fq_trait_name, FileChecker $file_checker) { diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index d3ca32112..5a1b45ab8 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -685,6 +685,7 @@ class TypeChecker if ($all_types_contain) { $to_string_cast = false; + return true; } @@ -748,6 +749,7 @@ class TypeChecker MethodChecker::methodExists($input_type_part->value . '::__toString', $file_checker) ) { $to_string_cast = true; + return true; } } @@ -1041,7 +1043,7 @@ class TypeChecker * @param Type\Union $declared_type * @param Type\Union $inferred_type * @param FileChecker $file_checker - * @return boolean + * @return bool */ public static function hasIdenticalTypes( Type\Union $declared_type, diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index a94c8d619..5247226e5 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -397,7 +397,6 @@ class Config ); } - $config->plugins[] = $loaded_plugin; } } diff --git a/src/Psalm/Config/ErrorLevelFileFilter.php b/src/Psalm/Config/ErrorLevelFileFilter.php index 6a470079f..99bb15251 100644 --- a/src/Psalm/Config/ErrorLevelFileFilter.php +++ b/src/Psalm/Config/ErrorLevelFileFilter.php @@ -8,7 +8,7 @@ class ErrorLevelFileFilter extends FileFilter /** * @var string */ - private $error_level = ""; + private $error_level = ''; /** * @param SimpleXMLElement $e diff --git a/src/Psalm/Config/FileFilter.php b/src/Psalm/Config/FileFilter.php index 68ae2c9a7..b2ba41058 100644 --- a/src/Psalm/Config/FileFilter.php +++ b/src/Psalm/Config/FileFilter.php @@ -73,7 +73,7 @@ class FileFilter foreach ($globs as $glob_index => $directory_path) { if (!$directory_path) { die('Could not resolve config path to ' . $base_dir . DIRECTORY_SEPARATOR . - (string)$directory['name']. ':' . $glob_index); + (string)$directory['name'] . ':' . $glob_index); } $filter->addDirectory($directory_path); } @@ -118,8 +118,8 @@ class FileFilter /** * @param string $file_name - * @param boolean $case_sensitive - * @return boolean + * @param bool $case_sensitive + * @return bool */ public function allows($file_name, $case_sensitive = false) { diff --git a/src/Psalm/Config/ProjectFileFilter.php b/src/Psalm/Config/ProjectFileFilter.php index cabc06b3c..3ed11c7d5 100644 --- a/src/Psalm/Config/ProjectFileFilter.php +++ b/src/Psalm/Config/ProjectFileFilter.php @@ -37,8 +37,8 @@ class ProjectFileFilter extends FileFilter /** * @param string $file_name - * @param boolean $case_sensitive - * @return boolean + * @param bool $case_sensitive + * @return bool */ public function allows($file_name, $case_sensitive = false) { diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index b92d46dc7..559bb2666 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -248,8 +248,7 @@ class Context */ public function remove($remove_var_id) { - unset($this->referenced_vars[$remove_var_id]); - unset($this->vars_possibly_in_scope[$remove_var_id]); + unset($this->referenced_vars[$remove_var_id], $this->vars_possibly_in_scope[$remove_var_id]); if (isset($this->vars_in_scope[$remove_var_id])) { $existing_type = $this->vars_in_scope[$remove_var_id]; diff --git a/src/Psalm/IssueBuffer.php b/src/Psalm/IssueBuffer.php index b44f1b160..fc7b71ead 100644 --- a/src/Psalm/IssueBuffer.php +++ b/src/Psalm/IssueBuffer.php @@ -54,6 +54,7 @@ class IssueBuffer if (self::$recording_level > 0) { self::$recorded_issues[self::$recording_level][] = $e; + return false; } @@ -97,6 +98,7 @@ class IssueBuffer break; } } + return false; } @@ -107,7 +109,7 @@ class IssueBuffer if (!self::alreadyEmitted($error_message)) { switch ($project_checker->output_format) { case ProjectChecker::TYPE_CONSOLE: - echo ($project_checker->use_color ? "\e[0;31mERROR\e[0m" : 'ERROR') . + echo($project_checker->use_color ? "\e[0;31mERROR\e[0m" : 'ERROR') . ': ' . $error_message . PHP_EOL; echo self::getSnippet($e, $project_checker->use_color) . PHP_EOL . PHP_EOL; @@ -312,6 +314,7 @@ class IssueBuffer { if (self::$recording_level === 0) { self::add($e); + return; } diff --git a/src/Psalm/Provider/FileProvider.php b/src/Psalm/Provider/FileProvider.php index 692aab849..07a8aaed4 100644 --- a/src/Psalm/Provider/FileProvider.php +++ b/src/Psalm/Provider/FileProvider.php @@ -8,7 +8,7 @@ class FileProvider { /** * @param string $file_path - * @return boolean + * @return bool */ public static function hasFileChanged($file_path) { diff --git a/src/Psalm/Provider/FileReferenceProvider.php b/src/Psalm/Provider/FileReferenceProvider.php index 7dcddc1f2..f8afd4476 100644 --- a/src/Psalm/Provider/FileReferenceProvider.php +++ b/src/Psalm/Provider/FileReferenceProvider.php @@ -190,6 +190,7 @@ class FileReferenceProvider } self::$file_references = $reference_cache; + return true; } } diff --git a/src/Psalm/Stubs/CoreGenericClasses.php b/src/Psalm/Stubs/CoreGenericClasses.php index af315a2f5..77b2534d7 100644 --- a/src/Psalm/Stubs/CoreGenericClasses.php +++ b/src/Psalm/Stubs/CoreGenericClasses.php @@ -70,7 +70,7 @@ interface Iterator extends Traversable { /** * Checks if current position is valid * @link http://php.net/manual/en/iterator.valid.php - * @return boolean The return value will be casted to boolean and then evaluated. + * @return bool The return value will be casted to boolean and then evaluated. * Returns true on success or false on failure. * @since 5.0.0 */ @@ -100,7 +100,7 @@ interface ArrayAccess { * @param TKey $offset

* An offset to check for. *

- * @return boolean true on success or false on failure. + * @return bool true on success or false on failure. *

*

* The return value will be casted to boolean if non-boolean was returned. diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index 3c44e6d6f..d03039a5a 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -121,6 +121,7 @@ abstract class Type */ function (ParseTree $child_tree) { $tree_type = self::getTypeFromTree($child_tree); + return $tree_type instanceof Union ? $tree_type : new Union([$tree_type]); }, $parse_tree->children @@ -243,6 +244,7 @@ abstract class Type public static function convertSquareBrackets($type) { $class_chars = '[a-zA-Z0-9\<\>\\\\_]+'; + return preg_replace_callback( '/(' . $class_chars . '|' . '\((' . $class_chars . '(\|' . $class_chars . ')*' . ')\))((\[\])+)/', /** diff --git a/src/Psalm/Type/Atomic.php b/src/Psalm/Type/Atomic.php index 20fdd3bc0..a1d9ca334 100644 --- a/src/Psalm/Type/Atomic.php +++ b/src/Psalm/Type/Atomic.php @@ -5,8 +5,8 @@ use Psalm\Checker\ClassChecker; use Psalm\Checker\ClassLikeChecker; use Psalm\Checker\FileChecker; use Psalm\CodeLocation; -use Psalm\IssueBuffer; use Psalm\Issue\ReservedWord; +use Psalm\IssueBuffer; use Psalm\StatementsSource; use Psalm\Type; use Psalm\Type\Atomic\ObjectLike; @@ -36,14 +36,14 @@ abstract class Atomic /** * Whether or not the type has been checked yet * - * @var boolean + * @var bool */ protected $checked = false; /** * Whether or not the type comes from a docblock * - * @var boolean + * @var bool */ protected $from_docblock = false; diff --git a/src/Psalm/Type/Atomic/GenericTrait.php b/src/Psalm/Type/Atomic/GenericTrait.php index d6202ca6d..158fc8b16 100644 --- a/src/Psalm/Type/Atomic/GenericTrait.php +++ b/src/Psalm/Type/Atomic/GenericTrait.php @@ -20,6 +20,7 @@ trait GenericTrait foreach ($this->type_params as $type_param) { $s .= $type_param . ', '; } + return $this->value . '<' . substr($s, 0, -2) . '>'; } diff --git a/src/Psalm/Type/Atomic/TNamedObject.php b/src/Psalm/Type/Atomic/TNamedObject.php index 731ebd2d4..e53f8ecad 100644 --- a/src/Psalm/Type/Atomic/TNamedObject.php +++ b/src/Psalm/Type/Atomic/TNamedObject.php @@ -1,7 +1,7 @@ value === $this_class) { $class_parts = explode('\\', $this_class); + return array_pop($class_parts); } diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index 19c651996..3d7bf2f4d 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -15,33 +15,33 @@ class Union /** * Whether the type originated in a docblock * - * @var boolean + * @var bool */ public $from_docblock = false; /** * Whether the property that this type has been derived from has been initialized in a constructor * - * @var boolean + * @var bool */ public $initialized = true; /** * Whether or not the type has been checked yet * - * @var boolean + * @var bool */ protected $checked = false; /** - * @var boolean + * @var bool */ public $failed_reconciliation = false; /** * Whether or not to ignore issues with possibly-null values * - * @var boolean + * @var bool */ public $ignore_nullable_issues = false; @@ -72,6 +72,7 @@ class Union foreach ($this->types as $type) { $s .= $type . '|'; } + return substr($s, 0, -1); } @@ -120,7 +121,7 @@ class Union /** * @param string $type_string - * @return boolean + * @return bool */ public function hasType($type_string) { @@ -128,7 +129,7 @@ class Union } /** - * @return boolean + * @return bool */ public function hasGeneric() { @@ -142,7 +143,7 @@ class Union } /** - * @return boolean + * @return bool */ public function hasArray() { @@ -150,7 +151,7 @@ class Union } /** - * @return boolean + * @return bool */ public function hasObjectLike() { @@ -158,7 +159,7 @@ class Union } /** - * @return boolean + * @return bool */ public function hasObjectType() { @@ -172,7 +173,7 @@ class Union } /** - * @return boolean + * @return bool */ public function isNullable() { @@ -180,7 +181,7 @@ class Union } /** - * @return boolean + * @return bool */ public function hasString() { @@ -188,15 +189,15 @@ class Union } /** - * @return boolean + * @return bool */ public function hasInt() { return isset($this->types['int']); } - /** - * @return boolean + /** + * @return bool */ public function hasFloat() { @@ -204,7 +205,7 @@ class Union } /** - * @return boolean + * @return bool */ public function hasNumericType() { @@ -228,7 +229,7 @@ class Union } /** - * @return boolean + * @return bool */ public function isMixed() { @@ -236,7 +237,7 @@ class Union } /** - * @return boolean + * @return bool */ public function isNull() { @@ -244,7 +245,7 @@ class Union } /** - * @return boolean + * @return bool */ public function isVoid() { @@ -252,7 +253,7 @@ class Union } /** - * @return boolean + * @return bool */ public function isEmpty() { @@ -330,7 +331,7 @@ class Union } /** - * @return boolean + * @return bool */ public function isSingle() { diff --git a/tests/FunctionCallTest.php b/tests/FunctionCallTest.php index 6e2d8e4ce..3327f396e 100644 --- a/tests/FunctionCallTest.php +++ b/tests/FunctionCallTest.php @@ -25,7 +25,7 @@ class FunctionCallTest extends TestCase $this->assertEquals('array', (string) $context->vars_in_scope['$d']); $this->assertEquals('array', (string) $context->vars_in_scope['$e']); - if (version_compare((string)phpversion(), '5.6.0', '>=')) { + if (version_compare((string)PHP_VERSION, '5.6.0', '>=')) { $stmts = self::$parser->parse(' 5, "b" => 12, "c" => null], function(?int $val, string $key) : bool { return true; @@ -64,7 +64,7 @@ class FunctionCallTest extends TestCase */ public function testArrayFilterUseKey() { - if (version_compare((string)phpversion(), '5.6.0', '>=')) { + if (version_compare((string)PHP_VERSION, '5.6.0', '>=')) { $stmts = self::$parser->parse('markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); + return; } @@ -55,6 +56,7 @@ class MethodSignatureTest extends TestCase { if (class_exists('SoapClient') === false) { $this->markTestSkipped('Cannot run test, base class "SoapClient" does not exist!'); + return; } diff --git a/tests/Php56Test.php b/tests/Php56Test.php index ec1eb0d1b..ff96cabb0 100644 --- a/tests/Php56Test.php +++ b/tests/Php56Test.php @@ -16,7 +16,7 @@ class Php56Test extends TestCase const ARR = ["a", "b"]; $a = ARR[0];', 'assertions' => [ - ['string' =>'$a'] + ['string' => '$a'] ] ], 'constFeatures' => [ diff --git a/tests/Php70Test.php b/tests/Php70Test.php index 478e97d79..708c74346 100644 --- a/tests/Php70Test.php +++ b/tests/Php70Test.php @@ -75,7 +75,7 @@ class Php70Test extends TestCase $a = ANIMALS[1];', 'assertions' => [ - ['string' =>'$a'] + ['string' => '$a'] ] ], 'anonymousClassLogger' => [ diff --git a/tests/Php71Test.php b/tests/Php71Test.php index e0cfd0525..0d921c4e6 100644 --- a/tests/Php71Test.php +++ b/tests/Php71Test.php @@ -33,7 +33,7 @@ class Php71Test extends TestCase $a = a();', 'assertions' => [ - ['null|string' =>'$a'] + ['null|string' => '$a'] ] ], 'nullableArgument' => [ diff --git a/tests/TemplateTest.php b/tests/TemplateTest.php index 0eaec3272..f598201eb 100644 --- a/tests/TemplateTest.php +++ b/tests/TemplateTest.php @@ -61,7 +61,7 @@ class TemplateTest extends TestCase ['Foo' => '$afoo'], ['A' => '$afoo_bar'], - ['Foo' =>'$bfoo'], + ['Foo' => '$bfoo'], ['B' => '$bfoo_bar'], ['Foo' => '$cfoo'], diff --git a/tests/Traits/FileCheckerValidCodeParseTestTrait.php b/tests/Traits/FileCheckerValidCodeParseTestTrait.php index ce32087d4..8aae158df 100644 --- a/tests/Traits/FileCheckerValidCodeParseTestTrait.php +++ b/tests/Traits/FileCheckerValidCodeParseTestTrait.php @@ -26,6 +26,7 @@ trait FileCheckerValidCodeParseTestTrait if (strpos($test_name, 'PHP7-') !== false) { if (version_compare(PHP_VERSION, '7.0.0dev', '<')) { $this->markTestSkipped('Test case requires PHP 7.'); + return; } } elseif (strpos($test_name, 'SKIPPED-') !== false) {