mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
Fix #2891 - treat autoloaded constants better
This commit is contained in:
parent
42c3a703b5
commit
209d17c868
@ -1924,9 +1924,6 @@ class Config
|
||||
throw new LogicException("IncludeCollector should be set at this point");
|
||||
}
|
||||
|
||||
$this->collectPredefinedConstants();
|
||||
$this->collectPredefinedFunctions();
|
||||
|
||||
$vendor_autoload_files_path
|
||||
= $this->base_dir . DIRECTORY_SEPARATOR . 'vendor'
|
||||
. DIRECTORY_SEPARATOR . 'composer' . DIRECTORY_SEPARATOR . 'autoload_files.php';
|
||||
@ -1945,6 +1942,8 @@ class Config
|
||||
|
||||
$codebase = $project_analyzer->getCodebase();
|
||||
|
||||
$this->collectPredefinedFunctions();
|
||||
|
||||
if ($this->autoloader) {
|
||||
// somee classes that we think are missing may not actually be missing
|
||||
// as they might be autoloadable once we require the autoloader below
|
||||
@ -1959,6 +1958,8 @@ class Config
|
||||
);
|
||||
}
|
||||
|
||||
$this->collectPredefinedConstants();
|
||||
|
||||
$autoload_included_files = $this->include_collector->getFilteredIncludedFiles();
|
||||
|
||||
if ($autoload_included_files) {
|
||||
|
@ -860,7 +860,9 @@ class ReflectorVisitor extends PhpParser\NodeVisitorAbstract implements PhpParse
|
||||
$this->file_storage->declaring_constants[$const_name] = $this->file_path;
|
||||
}
|
||||
|
||||
if ($this->codebase->register_stub_files || $this->codebase->register_autoload_files) {
|
||||
if (($this->codebase->register_stub_files || $this->codebase->register_autoload_files)
|
||||
&& !\defined($const_name)
|
||||
) {
|
||||
$this->codebase->addGlobalConstantType($const_name, $const_type);
|
||||
}
|
||||
}
|
||||
|
@ -509,6 +509,7 @@ class StubTest extends TestCase
|
||||
dirname(__DIR__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm
|
||||
errorLevel="1"
|
||||
autoloader="tests/fixtures/stubs/polyfill.php"
|
||||
>
|
||||
<projectFiles>
|
||||
@ -530,6 +531,37 @@ class StubTest extends TestCase
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function testConditionalConstantDefined()
|
||||
{
|
||||
$this->project_analyzer = $this->getProjectAnalyzerWithConfig(
|
||||
TestConfig::loadFromXML(
|
||||
dirname(__DIR__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm
|
||||
errorLevel="1"
|
||||
autoloader="tests/fixtures/stubs/conditional_constant_define_inferred.php"
|
||||
>
|
||||
<projectFiles>
|
||||
<directory name="src" />
|
||||
</projectFiles>
|
||||
</psalm>'
|
||||
)
|
||||
);
|
||||
|
||||
$file_path = getcwd() . '/src/somefile.php';
|
||||
|
||||
$this->addFile(
|
||||
$file_path,
|
||||
'<?php
|
||||
echo CODE_DIR;'
|
||||
);
|
||||
|
||||
$this->analyzeFile($file_path, new Context());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
@ -540,6 +572,7 @@ class StubTest extends TestCase
|
||||
dirname(__DIR__),
|
||||
'<?xml version="1.0"?>
|
||||
<psalm
|
||||
errorLevel="1"
|
||||
autoloader="tests/fixtures/stubs/class_alias.php"
|
||||
>
|
||||
<projectFiles>
|
||||
|
6
tests/fixtures/stubs/conditional_constant_define_inferred.php
vendored
Normal file
6
tests/fixtures/stubs/conditional_constant_define_inferred.php
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
if (!defined('CODE_DIR')) {
|
||||
$codeDir = 1;
|
||||
define('CODE_DIR', $codeDir);
|
||||
}
|
Loading…
Reference in New Issue
Block a user