forked from humbug/php-scoper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
scoper.inc.php
74 lines (65 loc) · 2.24 KB
/
scoper.inc.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
declare(strict_types=1);
/*
* This file is part of the humbug/php-scoper package.
*
* Copyright (c) 2017 Théo FIDRY <theo.fidry@gmail.com>,
* Pádraic Brady <padraic.brady@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Isolated\Symfony\Component\Finder\Finder;
return [
'finders' => [
Finder::create()->files()->in('src'),
Finder::create()
->files()
->ignoreVCS(true)
->notName('/LICENSE|.*\\.md|.*\\.dist|Makefile|composer\\.json|composer\\.lock/')
->exclude([
'doc',
'test',
'test_old',
'tests',
'Tests',
'vendor-bin',
])
->in('vendor'),
Finder::create()->append([
'bin/php-scoper',
'composer.json',
'box.json',
]),
],
'whitelist' => [
Finder::class,
],
'patchers' => [
function (string $filePath, string $prefix, string $contents): string {
//
// PHP-Parser patch
//
if ($filePath === __DIR__.'/vendor/nikic/php-parser/lib/PhpParser/Lexer.php') {
return preg_replace(
'%if \(defined\(\$name = \'PhpParser\\\\\\\\Parser\\\\\\\\Tokens%',
'if (defined($name = \''.$prefix.'\\\\\\\\PhpParser\\\\\\\\Parser\\\\\\\\Tokens',
$contents
);
}
if ($filePath === realpath(__DIR__.'/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php')) {
$length = 15 + strlen($prefix) + 1;
return preg_replace(
'%rtrim\(get_class\(\$this\), \'_\'\), 15\)%',
sprintf('rtrim(get_class($this), \'_\'), %d)', $length),
$contents
);
}
return $contents;
},
function (string $filePath, string $prefix, string $contents): string {
$finderClass = sprintf('\%s\%s', $prefix, Finder::class);
return str_replace($finderClass, '\\'.Finder::class, $contents);
},
],
];