forked from vimeo/psalm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimprove_class_alias.php
42 lines (33 loc) · 1.31 KB
/
improve_class_alias.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?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 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\')
)
)
]
)
),
[\'stmts\' => [$aliasStmt]]
);';
$contents = file_get_contents($vendor_path);
$contents = str_replace($search, $replace, $contents);
file_put_contents($vendor_path, $contents);