1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Fix #116 - be more lenient with static vars

This commit is contained in:
Matt Brown 2017-03-15 15:21:00 -04:00
parent 7fad81edac
commit 04363237c5
2 changed files with 42 additions and 21 deletions

View File

@ -473,10 +473,7 @@ class StatementsChecker extends SourceChecker implements StatementsSource
}
if ($context->check_variables) {
$context->vars_in_scope['$' . $var->name] = $var->default && isset($var->default->inferredType)
? $var->default->inferredType
: Type::getMixed();
$context->vars_in_scope['$' . $var->name] = Type::getMixed();
$context->vars_possibly_in_scope['$' . $var->name] = true;
$this->registerVariable('$' . $var->name, new CodeLocation($this, $stmt));
}

View File

@ -377,23 +377,6 @@ class ScopeTest extends PHPUnit_Framework_TestCase
$file_checker->visitAndAnalyzeMethods();
}
/**
* @return void
*/
public function testStatic()
{
$stmts = self::$parser->parse('<?php
function a() : string {
static $foo = "foo";
return $foo;
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$file_checker->visitAndAnalyzeMethods();
}
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage InvalidGlobal
@ -633,4 +616,45 @@ class ScopeTest extends PHPUnit_Framework_TestCase
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$file_checker->visitAndAnalyzeMethods();
}
/**
* @expectedException \Psalm\Exception\CodeException
* @expectedExceptionMessage MixedInferredReturnType
* @return void
*/
public function testStatic()
{
$stmts = self::$parser->parse('<?php
function a() : string {
static $foo = "foo";
return $foo;
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$file_checker->visitAndAnalyzeMethods();
}
/**
* @return void
*/
public function testStaticNullRef()
{
$stmts = self::$parser->parse('<?php
/** @return void */
function foo() {
static $bar = null;
if ($bar !== null) {
// do something
}
$bar = 5;
}
');
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
$file_checker->visitAndAnalyzeMethods();
}
}