mirror of
https://github.com/danog/psalm.git
synced 2024-11-26 12:24:49 +01:00
Make Phar more robust to object namespace changes
This commit is contained in:
parent
0828d5e3b3
commit
73fadab0b5
@ -15,22 +15,16 @@ ulimit -Sn 4096
|
||||
rm -f bin/psalm.phar
|
||||
|
||||
# Prefixes the code to be bundled
|
||||
php -d memory_limit=-1 `which php-scoper` add-prefix --output-dir=build/psalm --force
|
||||
|
||||
[ -d build/psalm/src/Psalm/Stubs ] || mkdir build/psalm/src/Psalm/Stubs
|
||||
|
||||
cp src/Psalm/Stubs/CoreGenericFunctions.php build/psalm/src/Psalm/Stubs
|
||||
cp src/Psalm/Stubs/CoreGenericClasses.php build/psalm/src/Psalm/Stubs
|
||||
php -d memory_limit=-1 `which php-scoper` add-prefix --prefix='PsalmPhar' --output-dir=build/psalm --force
|
||||
|
||||
# Re-dump the loader to account for the prefixing
|
||||
# and optimize the loader
|
||||
composer dump-autoload --working-dir=build/psalm --classmap-authoritative --no-dev
|
||||
|
||||
php -d memory_limit=-1 -d phar.readonly=0 `which box` --debug --dev compile
|
||||
php -d memory_limit=-1 -d phar.readonly=0 `which box` compile
|
||||
|
||||
# clean up build
|
||||
rm -Rf build/psalm
|
||||
rm -Rf .box
|
||||
|
||||
# reinstall deps (to regenerate autoloader and bring back dev deps)
|
||||
rm -Rf vendor/*
|
||||
|
@ -4,7 +4,7 @@ use Isolated\Symfony\Component\Finder\Finder;
|
||||
|
||||
return [
|
||||
'finders' => [
|
||||
Finder::create()->files()->exclude(['Psalm/Stubs'])->in('src'),
|
||||
Finder::create()->files()->in('src'),
|
||||
Finder::create()->files()->in('assets'),
|
||||
Finder::create()
|
||||
->files()
|
||||
@ -58,9 +58,13 @@ return [
|
||||
return $contents;
|
||||
},
|
||||
function ($filePath, $prefix, $contents) {
|
||||
if ($filePath === realpath(__DIR__ . '/src/Psalm/PropertyMap.php')) {
|
||||
if ($filePath === realpath(__DIR__ . '/src/Psalm/PropertyMap.php')
|
||||
|| $filePath === realpath(__DIR__ . '/src/Psalm/CallMap.php')
|
||||
|| $filePath === realpath(__DIR__ . '/src/Psalm/Stubs/CoreGenericFunctions.php')
|
||||
|| $filePath === realpath(__DIR__ . '/src/Psalm/Stubs/CoreGenericClasses.php')
|
||||
) {
|
||||
return str_replace(
|
||||
[$prefix . '\\\\', $prefix . '\\'],
|
||||
['namespace ' . $prefix . ';', $prefix . '\\\\', $prefix . '\\'],
|
||||
'',
|
||||
$contents
|
||||
);
|
||||
|
@ -178,7 +178,8 @@ class ProjectChecker
|
||||
|
||||
$statements_provider = new StatementsProvider(
|
||||
$file_provider,
|
||||
$cache_provider
|
||||
$cache_provider,
|
||||
$file_storage_cache_provider
|
||||
);
|
||||
|
||||
$this->codebase = new Codebase(
|
||||
|
@ -77,7 +77,9 @@ class ClassLikeStorageCacheProvider
|
||||
|
||||
$cache_hash = $this->getCacheHash($file_path, $file_contents);
|
||||
|
||||
if ($cache_hash !== $cached_value->hash) {
|
||||
if (@get_class($cached_value) === '__PHP_Incomplete_Class'
|
||||
|| $cache_hash !== $cached_value->hash
|
||||
) {
|
||||
unlink($this->getCacheLocationForClass($fq_classlike_name_lc, $file_path));
|
||||
|
||||
throw new \UnexpectedValueException('Should not be outdated');
|
||||
|
@ -75,8 +75,10 @@ class FileStorageCacheProvider
|
||||
|
||||
$cache_hash = $this->getCacheHash($file_path, $file_contents);
|
||||
|
||||
if ($cache_hash !== $cached_value->hash) {
|
||||
unlink($this->getCacheLocationForPath($file_path));
|
||||
if (@get_class($cached_value) === '__PHP_Incomplete_Class'
|
||||
|| $cache_hash !== $cached_value->hash
|
||||
) {
|
||||
$this->removeCacheForFile($file_path);
|
||||
|
||||
return null;
|
||||
}
|
||||
@ -84,6 +86,20 @@ class FileStorageCacheProvider
|
||||
return $cached_value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file_path
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function removeCacheForFile($file_path)
|
||||
{
|
||||
$cache_path = $this->getCacheLocationForPath($file_path);
|
||||
|
||||
if (file_exists($cache_path)) {
|
||||
unlink($cache_path);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $file_path
|
||||
* @param string $file_contents
|
||||
|
@ -28,4 +28,8 @@ class NoFileStorageCacheProvider extends \Psalm\Provider\FileStorageCacheProvide
|
||||
public function getLatestFromCache($file_path, $file_contents)
|
||||
{
|
||||
}
|
||||
|
||||
public function removeCacheForFile($file_path)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
@ -15,15 +15,30 @@ class StatementsProvider
|
||||
*/
|
||||
private $cache_provider;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
private $this_modified_time;
|
||||
|
||||
/**
|
||||
* @var FileStorageCacheProvider
|
||||
*/
|
||||
private $file_storage_cache_provider;
|
||||
|
||||
/**
|
||||
* @var PhpParser\Parser|null
|
||||
*/
|
||||
protected static $parser;
|
||||
|
||||
public function __construct(FileProvider $file_provider, ParserCacheProvider $cache_provider)
|
||||
{
|
||||
public function __construct(
|
||||
FileProvider $file_provider,
|
||||
ParserCacheProvider $cache_provider,
|
||||
FileStorageCacheProvider $file_storage_cache_provider
|
||||
) {
|
||||
$this->file_provider = $file_provider;
|
||||
$this->cache_provider = $cache_provider;
|
||||
$this->this_modified_time = filemtime(__FILE__);
|
||||
$this->file_storage_cache_provider = $file_storage_cache_provider;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -36,7 +51,7 @@ class StatementsProvider
|
||||
{
|
||||
$from_cache = false;
|
||||
|
||||
$version = 'parsercache5';
|
||||
$version = 'parsercache' . $this->this_modified_time;
|
||||
|
||||
$file_contents = $this->file_provider->getContents($file_path);
|
||||
$modified_time = $this->file_provider->getModifiedTime($file_path);
|
||||
@ -56,6 +71,7 @@ class StatementsProvider
|
||||
}
|
||||
|
||||
$stmts = self::parseStatementsInFile($file_contents);
|
||||
$this->file_storage_cache_provider->removeCacheForFile($file_path);
|
||||
} else {
|
||||
$from_cache = true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user