mirror of
https://github.com/danog/psalm.git
synced 2025-01-21 21:31:13 +01:00
Fix #42 - detect false and null defaults
This commit is contained in:
parent
c181f47364
commit
c104736ead
@ -347,7 +347,11 @@ class StatementsChecker extends SourceChecker implements StatementsSource
|
||||
public static function getSimpleType(PhpParser\Node\Expr $stmt)
|
||||
{
|
||||
if ($stmt instanceof PhpParser\Node\Expr\ConstFetch) {
|
||||
// @todo support this
|
||||
if (strtolower($stmt->name->parts[0]) === 'false' || strtolower($stmt->name->parts[0]) === 'true') {
|
||||
return Type::getBool();
|
||||
} elseif (strtolower($stmt->name->parts[0]) === 'null') {
|
||||
return Type::getNull();
|
||||
}
|
||||
} elseif ($stmt instanceof PhpParser\Node\Expr\ClassConstFetch) {
|
||||
// @todo support this as well
|
||||
} elseif ($stmt instanceof PhpParser\Node\Scalar\String_) {
|
||||
|
@ -107,7 +107,7 @@ class MethodSignatureTest extends PHPUnit_Framework_TestCase
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidParamDefault
|
||||
*/
|
||||
public function testInvalidDefault()
|
||||
public function testInvalidStringDefault()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
class A {
|
||||
@ -121,4 +121,23 @@ class MethodSignatureTest extends PHPUnit_Framework_TestCase
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Psalm\Exception\CodeException
|
||||
* @expectedExceptionMessage InvalidParamDefault
|
||||
*/
|
||||
public function testInvalidFalseDefault()
|
||||
{
|
||||
$stmts = self::$parser->parse('<?php
|
||||
class A {
|
||||
public function fooFoo(int $a = false) : void {
|
||||
|
||||
}
|
||||
}
|
||||
');
|
||||
|
||||
$file_checker = new FileChecker('somefile.php', $this->project_checker, $stmts);
|
||||
$context = new Context('somefile.php');
|
||||
$file_checker->visitAndAnalyzeMethods($context);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user