1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 04:45:20 +01:00
psalm/bin/improve_class_alias.php
2019-06-08 20:03:46 -04:00

36 lines
1022 B
PHP

<?php
$vendor_path = 'vendor-bin/box/vendor/humbug/php-scoper/src/PhpParser/NodeVisitor/ClassAliasStmtAppender.php';
if (!file_exists($vendor_path)) {
die('Vendor file does not exist' . PHP_EOL);
}
$search = '/* @var FullyQualified $originalName */
$stmts[] = $this->createAliasStmt($originalName, $stmt);';
$replace = '/* @var FullyQualified $originalName */
$aliasStmt = $this->createAliasStmt($originalName, $stmt);
$stmts[] = new If_(
new FuncCall(
new FullyQualified(\'class_exists\'),
[
new Node\Arg(
new Node\Expr\ClassConstFetch(
$originalName,
\'class\'
)
)
]
),
[\'stmts\' => [$aliasStmt]]
);';
$contents = file_get_contents($vendor_path);
$contents = str_replace($search, $replace, $contents);
file_put_contents($vendor_path, $contents);