addFile( 'somefile.php', 'project_checker); $context = new Context(); $file_checker->visitAndAnalyzeMethods($context); $this->assertSame('int', (string) $context->vars_in_scope['$a']); } /** * @return array */ public function providerFileCheckerValidCodeParse() { return [ 'deprecatedMethod' => [ ' [ ' */ function foo2() : array { return ["hello"]; } /** * @return array */ function foo3() : array { return ["hello"]; }', ], 'reassertWithIs' => [ ' [ ' [ '> $data */ function foo($data) : void { foreach ($data as $key => $val) { if (!\is_array($data)) { $data = [$key => null]; } else { $data[$key] = !empty($val); } } }', ], 'goodDocblock' => [ ' [ ' [ 'foo = "hello";', ], 'ignoreNullableReturn' => [ 'foo(); $a->bar = 7; takeA($a);', ], 'invalidDocblockParamSuppress' => [ ' [ ' [ ' */ $a = []; $a[0]->getMessage();', ], 'mixedDocblockParamTypeDefinedInParent' => [ ' [ ' [ 'foo(); } }', ], 'psalmVar' => [ ' */ public $foo = []; public function updateFoo() : void { $this->foo[5] = "hello"; } }', ], 'psalmParam' => [ ' $a * @param string[] $a */ function foo(array $a) : void { foreach ($a as $key => $value) { takesInt($key); } }', ], ]; } /** * @return array */ public function providerFileCheckerInvalidCodeParse() { return [ 'invalidReturn' => [ ' 'InvalidDocblock', ], 'invalidReturnClass' => [ ' 'InvalidDocblock', ], 'invalidReturnClassWithComma' => [ ' 'InvalidDocblock', ], 'returnClassWithComma' => [ ' 'InvalidDocblock', ], 'deprecatedMethodWithCall' => [ ' 'DeprecatedMethod', ], 'deprecatedClassWithStaticCall' => [ ' 'DeprecatedClass', ], 'deprecatedClassWithNew' => [ ' 'DeprecatedClass', ], 'deprecatedPropertyGet' => [ 'foo;', 'error_message' => 'DeprecatedProperty', ], 'deprecatedPropertySet' => [ 'foo = 5;', 'error_message' => 'DeprecatedProperty', ], 'missingParamType' => [ ' 'TooManyArguments', ], 'missingParamVar' => [ ' 'InvalidDocblock - src/somefile.php:5 - Badly-formatted @param', ], 'invalidDocblockReturn' => [ ' 'InvalidDocblock', ], 'propertyDocblockInvalidAssignment' => [ 'foo = 5;', 'error_message' => 'InvalidPropertyAssignment', ], 'noStringParamType' => [ ' 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,' . ' should be string', 'error_levels' => ['MixedArgument'], ], 'noParamTypeButConcat' => [ ' 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,' . ' should be string', 'error_levels' => ['MixedOperand'], ], 'noParamTypeButAddition' => [ ' 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,' . ' should be int|float', 'error_levels' => ['MixedOperand', 'MixedArgument'], ], 'noParamTypeButDivision' => [ ' 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,' . ' should be int|float', 'error_levels' => ['MixedOperand', 'MixedArgument'], ], 'noParamTypeButTemplatedString' => [ ' 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,' . ' should be string', 'error_levels' => ['MixedOperand'], ], 'noStringIntParamType' => [ ' 'UntypedParam - src/somefile.php:2 - Parameter $a has no provided type,' . ' should be int|string', 'error_levels' => ['MixedArgument'], ], 'intParamTypeDefinedInParent' => [ ' 'UntypedParam', 'error_levels' => ['MethodSignatureMismatch'], ], 'alreadyHasCheck' => [ ' 'UntypedParam - src/somefile.php:4 - Parameter $s has no provided type,' . ' could not infer', 'error_levels' => ['MixedArgument'], ], 'isSetBeforeInferrence' => [ 'input' => ' 'UntypedParam - src/somefile.php:7 - Parameter $s has no provided type,' . ' could not infer', 'error_levels' => ['MixedArgument', 'InvalidReturnType', 'MixedAssignment'], ], 'psalmInvalidVar' => [ ' */ public $foo = []; public function updateFoo() : void { $this->foo["boof"] = "hello"; } }', 'error_message' => 'InvalidPropertyAssignment', ], ]; } }