1
0
mirror of https://github.com/danog/psalm.git synced 2024-12-15 02:47:02 +01:00
psalm/bin/improve_class_alias.php

43 lines
1.3 KiB
PHP
Raw Normal View History

2019-06-09 01:51:40 +02:00
<?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);
2019-06-09 02:27:49 +02:00
$stmts[] = new Node\Stmt\If_(
new Node\Expr\BooleanNot(
new Node\Expr\FuncCall(
new FullyQualified(\'class_exists\'),
[
new Node\Arg(
new Node\Expr\ClassConstFetch(
$originalName,
\'class\'
)
),
new Node\Arg(
new Node\Expr\ConstFetch(
new Node\Name(\'false\')
)
2019-06-09 01:51:40 +02:00
)
2019-06-09 02:27:49 +02:00
]
)
2019-06-09 01:51:40 +02:00
),
[\'stmts\' => [$aliasStmt]]
);';
$contents = file_get_contents($vendor_path);
$contents = str_replace($search, $replace, $contents);
file_put_contents($vendor_path, $contents);