mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
parent
52fc81e4ab
commit
59b50bdcdd
@ -109,7 +109,21 @@ class ExpressionChecker
|
||||
} elseif ($stmt instanceof PhpParser\Node\Scalar\EncapsedStringPart) {
|
||||
// do nothing
|
||||
} elseif ($stmt instanceof PhpParser\Node\Scalar\MagicConst) {
|
||||
// do nothing
|
||||
switch (strtolower($stmt->getName())) {
|
||||
case '__line__':
|
||||
$stmt->inferredType = Type::getInt();
|
||||
break;
|
||||
|
||||
case '__file__':
|
||||
case '__dir__':
|
||||
case '__function__':
|
||||
case '__class__':
|
||||
case '__trait__':
|
||||
case '__method__':
|
||||
case '__namespace__':
|
||||
$stmt->inferredType = Type::getString();
|
||||
break;
|
||||
}
|
||||
} elseif ($stmt instanceof PhpParser\Node\Scalar\LNumber) {
|
||||
$stmt->inferredType = Type::getInt();
|
||||
} elseif ($stmt instanceof PhpParser\Node\Scalar\DNumber) {
|
||||
|
@ -3,7 +3,6 @@ namespace Psalm\Checker;
|
||||
|
||||
use Psalm\Checker\Statements\ExpressionChecker;
|
||||
use Psalm\CodeLocation;
|
||||
use Psalm\Issue\PossiblyUndefinedVariable;
|
||||
use Psalm\Issue\RedundantCondition;
|
||||
use Psalm\Issue\TypeDoesNotContainNull;
|
||||
use Psalm\Issue\TypeDoesNotContainType;
|
||||
|
@ -16,7 +16,7 @@ class ConstantTest extends TestCase
|
||||
'<?php
|
||||
useTest();
|
||||
const TEST = 2;
|
||||
|
||||
|
||||
function useTest() : int {
|
||||
return TEST;
|
||||
}',
|
||||
@ -24,7 +24,7 @@ class ConstantTest extends TestCase
|
||||
'constantInClosure' => [
|
||||
'<?php
|
||||
const TEST = 2;
|
||||
|
||||
|
||||
$useTest = function() : int {
|
||||
return TEST;
|
||||
};
|
||||
@ -38,11 +38,20 @@ class ConstantTest extends TestCase
|
||||
function defineConstant() {
|
||||
define("CONSTANT", 1);
|
||||
}
|
||||
|
||||
|
||||
defineConstant();
|
||||
|
||||
|
||||
echo CONSTANT;',
|
||||
],
|
||||
'magicConstant' => [
|
||||
'<?php
|
||||
$a = __LINE__;
|
||||
$b = __file__;',
|
||||
'assertions' => [
|
||||
'$a' => 'int',
|
||||
'$b' => 'string',
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -60,7 +69,7 @@ class ConstantTest extends TestCase
|
||||
function defineConstant() {
|
||||
define("CONSTANT", 1);
|
||||
}
|
||||
|
||||
|
||||
echo CONSTANT;',
|
||||
'error_message' => 'UndefinedConstant',
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user