diff --git a/src/Psalm/Checker/ClassLikeChecker.php b/src/Psalm/Checker/ClassLikeChecker.php index d2f6d30e4..67a087125 100644 --- a/src/Psalm/Checker/ClassLikeChecker.php +++ b/src/Psalm/Checker/ClassLikeChecker.php @@ -65,7 +65,7 @@ abstract class ClassLikeChecker implements StatementsSource /** * The parent class * - * @var string + * @var string|null */ protected $parent_class; diff --git a/src/Psalm/Checker/FunctionLikeChecker.php b/src/Psalm/Checker/FunctionLikeChecker.php index a7eb49359..de5d72074 100644 --- a/src/Psalm/Checker/FunctionLikeChecker.php +++ b/src/Psalm/Checker/FunctionLikeChecker.php @@ -55,6 +55,8 @@ abstract class FunctionLikeChecker implements StatementsSource $statements_checker = new StatementsChecker($this, $has_context, $check_methods); + $hash = null; + if ($this instanceof MethodChecker) { if (ClassLikeChecker::getThisClass()) { $hash = $this->getMethodId() . json_encode([$context->vars_in_scope, $context->vars_possibly_in_scope]); @@ -87,6 +89,8 @@ abstract class FunctionLikeChecker implements StatementsSource $param_type = null; if ($param->type) { + $param_type_string = ''; + if (is_string($param->type)) { $param_type_string = $param->type; } @@ -167,7 +171,7 @@ abstract class FunctionLikeChecker implements StatementsSource } } - if (ClassLikeChecker::getThisClass() && $this instanceof MethodChecker) { + if ($hash && ClassLikeChecker::getThisClass() && $this instanceof MethodChecker) { self::$no_effects_hashes[$hash] = [$context->vars_in_scope, $context->vars_possibly_in_scope]; } } diff --git a/src/Psalm/Checker/TypeChecker.php b/src/Psalm/Checker/TypeChecker.php index 154483f0c..e7d03f875 100644 --- a/src/Psalm/Checker/TypeChecker.php +++ b/src/Psalm/Checker/TypeChecker.php @@ -922,8 +922,8 @@ class TypeChecker /** * Takes two arrays of types and merges them * - * @param array $new_types - * @param array $existing_types + * @param array $new_types + * @param array $existing_types * @return array */ public static function combineKeyedTypes(array $new_types, array $existing_types) @@ -1079,7 +1079,7 @@ class TypeChecker continue; } - if (!($inferred_atomic_type instanceof Type\Generic) && $declared_atomic_type instanceof Type\Generic) { + if (!($inferred_atomic_type instanceof Type\Generic)) { // @todo handle this better continue; } diff --git a/src/Psalm/Config.php b/src/Psalm/Config.php index 0eab91a15..fc7ebc3fa 100644 --- a/src/Psalm/Config.php +++ b/src/Psalm/Config.php @@ -58,7 +58,7 @@ class Config protected $filetype_handlers = []; /** - * @var array + * @var array */ protected $issue_handlers = []; diff --git a/src/Psalm/Context.php b/src/Psalm/Context.php index 060549cd0..115fe7641 100644 --- a/src/Psalm/Context.php +++ b/src/Psalm/Context.php @@ -7,9 +7,10 @@ use Psalm\Checker\StatementsChecker; class Context { - /** @var array */ + /** @var array */ public $vars_in_scope = []; + /** @var array */ public $vars_possibly_in_scope = []; /** @var boolean */ diff --git a/src/Psalm/Type.php b/src/Psalm/Type.php index dd7a1c213..ceb1256d8 100644 --- a/src/Psalm/Type.php +++ b/src/Psalm/Type.php @@ -134,7 +134,7 @@ abstract class Type } /** - * @return array + * @return array */ public static function tokenize($return_type) { @@ -411,6 +411,8 @@ abstract class Type } $key_types = []; + + /** @var array> */ $value_types = []; foreach ($types as $type) { diff --git a/src/Psalm/Type/Generic.php b/src/Psalm/Type/Generic.php index 89adbdd67..4e58fe096 100644 --- a/src/Psalm/Type/Generic.php +++ b/src/Psalm/Type/Generic.php @@ -12,7 +12,7 @@ class Generic extends Atomic /** * Constructs a new instance of a generic type * @param string $value - * @param array $type_params + * @param array $type_params */ public function __construct($value, array $type_params) { diff --git a/src/Psalm/Type/GenericArray.php b/src/Psalm/Type/GenericArray.php index de8675fd1..09c7c177a 100644 --- a/src/Psalm/Type/GenericArray.php +++ b/src/Psalm/Type/GenericArray.php @@ -11,7 +11,7 @@ class GenericArray extends Generic /** * Constructs a new instance of a generic type * @param string $value - * @param array $type_params + * @param array $type_params */ public function __construct($value, array $type_params) { diff --git a/src/Psalm/Type/ObjectLike.php b/src/Psalm/Type/ObjectLike.php index 8e43ebdc1..a17c15129 100644 --- a/src/Psalm/Type/ObjectLike.php +++ b/src/Psalm/Type/ObjectLike.php @@ -8,13 +8,13 @@ class ObjectLike extends Atomic { public $value = 'object-like'; - /** @var array */ + /** @var array */ public $properties; /** * Constructs a new instance of a generic type * @param string $value - * @param array $type_params + * @param array $type_params */ public function __construct($value, array $properties) { diff --git a/src/Psalm/Type/ParseTree.php b/src/Psalm/Type/ParseTree.php index bb94cdeb2..9e2989a24 100644 --- a/src/Psalm/Type/ParseTree.php +++ b/src/Psalm/Type/ParseTree.php @@ -10,7 +10,7 @@ class ParseTree const UNION = '|'; /** @var array */ - public $children; + public $children = []; /** @var string|null */ public $value; @@ -26,7 +26,6 @@ class ParseTree { $this->value = $value; $this->parent = $parent; - $this->children = []; } /** @@ -123,6 +122,10 @@ class ParseTree continue; } + if (!$current_parent) { + throw new \InvalidArgumentException('Cannot process colon without parent'); + } + $new_parent_leaf = new self(self::OBJECT_PROPERTY, $current_parent); $new_parent_leaf->children = [$current_leaf]; $current_leaf->parent = $new_parent_leaf; diff --git a/src/Psalm/Type/Union.php b/src/Psalm/Type/Union.php index c37c78afb..f926ca63a 100644 --- a/src/Psalm/Type/Union.php +++ b/src/Psalm/Type/Union.php @@ -8,12 +8,12 @@ use Psalm\Checker\ClassChecker; class Union extends Type { - /** @var array */ + /** @var array */ public $types = []; /** * Constructs an Union instance - * @param array $types + * @param array $types */ public function __construct(array $types) {