Skip to content
This repository was archived by the owner on Mar 20, 2025. It is now read-only.

Commit b8b9f14

Browse files
committed
Qualify global functions to avoid collisions
1 parent abd9f09 commit b8b9f14

24 files changed

+192
-168
lines changed

build.sh

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
mv composer-dev.json composer.json
1010
rm -rf vendor composer.lock
1111
composer update --no-dev
12+
rm vendor/shift-tasks.php
1213
sed -i '' -e "s/Shift CLI', '.*'/Shift CLI', '$1'/" shift-cli
1314
box compile --no-parallel
1415
git add builds/shift-cli shift-cli

pint.json

+5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
"rules": {
44
"concat_space": {
55
"spacing": "one"
6+
},
7+
"native_function_invocation": {
8+
"include": [
9+
"@all"
10+
]
611
}
712
},
813
"exclude": [

scoper.inc.php

+22-4
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,30 @@
33
declare(strict_types=1);
44

55
return [
6+
'expose-global-functions' => false,
7+
// 'exclude-functions' => ['app'],
68
'patchers' => [
79
function (string $filePath, string $prefix, string $content): string {
8-
if (str_starts_with($filePath, 'src/Tasks/')) {
9-
$content = str_replace(
10+
if (\str_contains($content, $prefix . '\\app')) {
11+
$content = \preg_replace(
12+
'/' . $prefix . '[\\\\]+app' . '/',
13+
'app',
14+
$content
15+
);
16+
}
17+
18+
if (\str_starts_with($filePath, 'src/Tasks/')) {
19+
$content = \str_replace(
1020
$prefix . '\\\\Illuminate\\\\',
1121
'Illuminate\\\\',
1222
$content
1323
);
14-
$content = str_replace(
24+
$content = \str_replace(
1525
$prefix . '\\\\App\\\\',
1626
'App\\\\',
1727
$content
1828
);
19-
$content = str_replace(
29+
$content = \str_replace(
2030
$prefix . '\\\\PHPUnit\\\\Framework\\\\',
2131
'PHPUnit\\\\Framework\\\\',
2232
$content
@@ -28,6 +38,14 @@ function (string $filePath, string $prefix, string $content): string {
2838
],
2939
'exclude-files' => [
3040
'vendor/symfony/polyfill-php80/bootstrap.php',
41+
'vendor/symfony/polyfill-ctype/bootstrap80.php',
42+
'vendor/symfony/polyfill-ctype/bootstrap.php',
43+
'vendor/symfony/polyfill-intl-normalizer/bootstrap80.php',
44+
'vendor/symfony/polyfill-intl-normalizer/bootstrap.php',
45+
'vendor/symfony/polyfill-mbstring/bootstrap80.php',
46+
'vendor/symfony/polyfill-mbstring/bootstrap.php',
47+
'vendor/symfony/polyfill-intl-grapheme/bootstrap80.php',
48+
'vendor/symfony/polyfill-intl-grapheme/bootstrap.php',
3149
],
3250
'exclude-namespaces' => [
3351
'Symfony\Polyfill\*',

src/Commands/DiscoverCommand.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
2929

3030
$this->taskManifest->build();
3131

32-
collect($this->taskManifest->list())
32+
\collect($this->taskManifest->list())
3333
->keys()
3434
->each(fn ($task) => $output->writeln($task))
3535
->whenNotEmpty(fn () => $output->writeln(''));

src/Commands/PublishCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ protected function configure(): void
2222

2323
protected function execute(InputInterface $input, OutputInterface $output): int
2424
{
25-
if (file_exists('shift-cli.json') && ! $input->getOption('force')) {
25+
if (\file_exists('shift-cli.json') && ! $input->getOption('force')) {
2626
$output->writeln('<comment>A configuration file already exists.</comment> Use the `--force` option to overwrite yours.');
2727

2828
return 1;
2929
}
3030

31-
file_put_contents('shift-cli.json', json_encode(Configuration::defaults(), JSON_PRETTY_PRINT));
31+
\file_put_contents('shift-cli.json', \json_encode(Configuration::defaults(), JSON_PRETTY_PRINT));
3232

3333
return 0;
3434
}

src/Commands/RunCommand.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private function createTask(string $name, InputInterface $input): Task
6868
{
6969
$task = new $name;
7070

71-
if (in_array(FindsFiles::class, class_uses_recursive($task))) {
71+
if (\in_array(FindsFiles::class, \class_uses_recursive($task))) {
7272
if (! empty($input->getOption('path'))) {
7373
$task->setPaths($input->getOption('path'));
7474
}
@@ -113,7 +113,7 @@ private function listTasks(OutputInterface $output)
113113
{
114114
$output->writeln('<comment>Available tasks:</comment>');
115115

116-
$tasks = collect($this->taskManifest->list())
116+
$tasks = \collect($this->taskManifest->list())
117117
->map(fn ($fqcn) => [' <info>' . $fqcn::$name . '</info> ', $fqcn::$description])
118118
->all();
119119

src/Support/TaskManifest.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function list(): array
2727
return $this->tasks;
2828
}
2929

30-
if (! is_file($this->manifestPath)) {
30+
if (! \is_file($this->manifestPath)) {
3131
$this->build();
3232
}
3333

@@ -48,18 +48,18 @@ public function build(): void
4848
$packages = [];
4949
$path = $this->vendorPath . DIRECTORY_SEPARATOR . 'composer' . DIRECTORY_SEPARATOR . 'installed.json';
5050

51-
if (file_exists($path)) {
52-
$installed = json_decode(file_get_contents($path), true);
51+
if (\file_exists($path)) {
52+
$installed = \json_decode(\file_get_contents($path), true);
5353

5454
$packages = $installed['packages'] ?? $installed;
5555
}
5656

57-
$this->write(collect($packages)
57+
$this->write(\collect($packages)
5858
->mapWithKeys(function ($package) {
59-
return collect($package['extra']['shift']['tasks'] ?? [])->mapWithKeys(fn ($task) => [$task::$name => $task]);
59+
return \collect($package['extra']['shift']['tasks'] ?? [])->mapWithKeys(fn ($task) => [$task::$name => $task]);
6060
})
6161
->filter()
62-
->merge(collect($this->defaultTasks)->mapWithKeys(fn ($task) => [$task::$name => $task]))
62+
->merge(\collect($this->defaultTasks)->mapWithKeys(fn ($task) => [$task::$name => $task]))
6363
->all());
6464
}
6565

@@ -75,7 +75,7 @@ private function isStale(array $manifest): bool
7575

7676
protected function write(array $tasks): void
7777
{
78-
if (! is_writable($dirname = dirname($this->manifestPath))) {
78+
if (! \is_writable($dirname = \dirname($this->manifestPath))) {
7979
throw new \Exception("The {$dirname} directory must be present and writable.");
8080
}
8181

@@ -84,8 +84,8 @@ protected function write(array $tasks): void
8484
'tasks' => $tasks,
8585
];
8686

87-
file_put_contents(
88-
$this->manifestPath, '<?php return ' . var_export($manifest, true) . ';'
87+
\file_put_contents(
88+
$this->manifestPath, '<?php return ' . \var_export($manifest, true) . ';'
8989
);
9090
}
9191
}

src/Tasks/AnonymousMigrations.php

+15-15
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ public function perform(): int
2525
private function updateMigrations(): void
2626
{
2727
foreach ($this->findFilesContaining('/\bclass\s+\S+\s+extends\s+Migration\s/') as $path) {
28-
if (str_starts_with($path, 'stubs/')) {
28+
if (\str_starts_with($path, 'stubs/')) {
2929
continue;
3030
}
3131

32-
$contents = $this->convertClassDefinition(file_get_contents($path));
33-
if (is_null($contents)) {
32+
$contents = $this->convertClassDefinition(\file_get_contents($path));
33+
if (\is_null($contents)) {
3434
continue;
3535
}
3636

37-
file_put_contents($path, $contents);
37+
\file_put_contents($path, $contents);
3838
}
3939
}
4040

@@ -47,43 +47,43 @@ private function updateStubs(): void
4747
];
4848

4949
foreach ($stubs as $stub) {
50-
if (! file_exists('stubs/' . $stub)) {
50+
if (! \file_exists('stubs/' . $stub)) {
5151
continue;
5252
}
5353

54-
$contents = file_get_contents('stubs/' . $stub);
55-
$contents = str_replace(
54+
$contents = \file_get_contents('stubs/' . $stub);
55+
$contents = \str_replace(
5656
['DummyClass', '{{ class }}', '{{class}}'],
5757
'ShiftTemporaryClassNamePlaceholder',
5858
$contents
5959
);
60-
$contents = str_replace(
60+
$contents = \str_replace(
6161
['DummyTable', '{{ table }}', '{{table}}'],
6262
'ShiftTemporaryTableNamePlaceholder',
6363
$contents
6464
);
6565

6666
$contents = $this->convertClassDefinition($contents);
67-
if (is_null($contents)) {
67+
if (\is_null($contents)) {
6868
continue;
6969
}
7070

71-
$contents = str_replace('ShiftTemporaryClassNamePlaceholder', '{{ class }}', $contents);
72-
$contents = str_replace('ShiftTemporaryTableNamePlaceholder', '{{ table }}', $contents);
71+
$contents = \str_replace('ShiftTemporaryClassNamePlaceholder', '{{ class }}', $contents);
72+
$contents = \str_replace('ShiftTemporaryTableNamePlaceholder', '{{ table }}', $contents);
7373

74-
file_put_contents('stubs/' . $stub, $contents);
74+
\file_put_contents('stubs/' . $stub, $contents);
7575
}
7676
}
7777

7878
private function convertClassDefinition($contents): ?string
7979
{
80-
$found = preg_match('/^class\s+(\S+)\s+extends\s+Migration(\s+)/m', $contents, $matches);
80+
$found = \preg_match('/^class\s+(\S+)\s+extends\s+Migration(\s+)/m', $contents, $matches);
8181
if (! $found) {
8282
return null;
8383
}
8484

85-
$contents = str_replace(rtrim($matches[0]), 'return new class extends Migration', $contents);
86-
$contents = preg_replace('/\b' . preg_quote($matches[1], '/') . '::/', 'self::', $contents);
85+
$contents = \str_replace(\rtrim($matches[0]), 'return new class extends Migration', $contents);
86+
$contents = \preg_replace('/\b' . \preg_quote($matches[1], '/') . '::/', 'self::', $contents);
8787

8888
return Str::replaceLast('}', '};', $contents);
8989
}

src/Tasks/CheckLint.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function perform(): int
2525
foreach ($files as $file) {
2626
$output = [];
2727
$exit_code = 0;
28-
exec('php -l ' . $file . ' 2>&1', $output, $exit_code);
28+
\exec('php -l ' . $file . ' 2>&1', $output, $exit_code);
2929

3030
if ($exit_code !== 0) {
3131
[$line, $error] = $this->parseError($output);
@@ -39,7 +39,7 @@ public function perform(): int
3939

4040
private function parseError(array $lines): array
4141
{
42-
preg_match('/PHP (?:Fatal|Parse) error:\s+(?:syntax error, )?(.+?)\s+in\s+.+?\.php\s+on\s+line\s+(\d+)/', $lines[0], $matches);
42+
\preg_match('/PHP (?:Fatal|Parse) error:\s+(?:syntax error, )?(.+?)\s+in\s+.+?\.php\s+on\s+line\s+(\d+)/', $lines[0], $matches);
4343

4444
return [$matches[2], $matches[1]];
4545
}

src/Tasks/ClassStrings.php

+12-12
Original file line numberDiff line numberDiff line change
@@ -21,28 +21,28 @@ public function perform(): int
2121
return 0;
2222
}
2323

24-
$pattern = '/[\'"]' . $this->patternForNamespaces(array_keys($namespaces)) . '/';
24+
$pattern = '/[\'"]' . $this->patternForNamespaces(\array_keys($namespaces)) . '/';
2525
$files = $this->findFilesContaining($pattern);
2626

2727
if (empty($files)) {
2828
return 0;
2929
}
3030

31-
$pattern = '/([\'"])' . $this->patternForNamespaces(array_keys($namespaces)) . '([\w\\\\]+)\1/';
31+
$pattern = '/([\'"])' . $this->patternForNamespaces(\array_keys($namespaces)) . '([\w\\\\]+)\1/';
3232

3333
foreach ($files as $file) {
34-
$contents = preg_replace_callback(
34+
$contents = \preg_replace_callback(
3535
$pattern,
3636
function ($matches) use ($namespaces) {
37-
if (! $this->classExists($namespaces, $matches[2], preg_replace('/\\\\+/', '\\', $matches[3]))) {
37+
if (! $this->classExists($namespaces, $matches[2], \preg_replace('/\\\\+/', '\\', $matches[3]))) {
3838
return $matches[0];
3939
}
4040

41-
return sprintf('\\%s\\%s::class', $matches[2], preg_replace('/\\\\+/', '\\', $matches[3]));
41+
return \sprintf('\\%s\\%s::class', $matches[2], \preg_replace('/\\\\+/', '\\', $matches[3]));
4242
},
43-
file_get_contents($file));
43+
\file_get_contents($file));
4444

45-
file_put_contents($file, $contents);
45+
\file_put_contents($file, $contents);
4646
}
4747

4848
return 0;
@@ -51,14 +51,14 @@ function ($matches) use ($namespaces) {
5151
private function classExists(mixed $namespaces, mixed $namespace, mixed $class): bool
5252
{
5353
$key = $namespace . '\\';
54-
if (! array_key_exists($key, $namespaces)) {
54+
if (! \array_key_exists($key, $namespaces)) {
5555
return false;
5656
}
5757

5858
foreach (Arr::wrap($namespaces[$key]) as $path) {
59-
$file = str_replace([$key, '\\'], [$path, DIRECTORY_SEPARATOR], $key . $class . '.php');
59+
$file = \str_replace([$key, '\\'], [$path, DIRECTORY_SEPARATOR], $key . $class . '.php');
6060

61-
if (file_exists($file)) {
61+
if (\file_exists($file)) {
6262
return true;
6363
}
6464
}
@@ -68,12 +68,12 @@ private function classExists(mixed $namespaces, mixed $namespace, mixed $class):
6868

6969
private function patternForNamespaces(array $namespaces): string
7070
{
71-
return '(?:[\\\\]+)?(' . implode('|', array_map(fn ($namespace) => preg_quote(rtrim($namespace, '\\'), '/'), $namespaces)) . ')\\\\+';
71+
return '(?:[\\\\]+)?(' . \implode('|', \array_map(fn ($namespace) => \preg_quote(\rtrim($namespace, '\\'), '/'), $namespaces)) . ')\\\\+';
7272
}
7373

7474
private function psr4Namespaces(): array
7575
{
76-
$composer = json_decode(file_get_contents('composer.json'), true);
76+
$composer = \json_decode(\file_get_contents('composer.json'), true);
7777

7878
return $composer['autoload']['psr-4'] ?? [];
7979
}

src/Tasks/DebugCalls.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public function perform(): int
2626
$failure = false;
2727

2828
foreach ($files as $file) {
29-
$contents = file_get_contents($file);
29+
$contents = \file_get_contents($file);
3030

31-
if (! preg_match('/\b(print_r|var_dump|var_export|dd)\(/', $contents)) {
31+
if (! \preg_match('/\b(print_r|var_dump|var_export|dd)\(/', $contents)) {
3232
continue;
3333
}
3434

@@ -40,25 +40,25 @@ public function perform(): int
4040
$failure = true;
4141
$this->leaveComment($file, $instances);
4242

43-
foreach (array_reverse($instances) as $instance) {
44-
$contents = substr_replace(
43+
foreach (\array_reverse($instances) as $instance) {
44+
$contents = \substr_replace(
4545
$contents,
4646
'',
4747
$instance['offset']['start'],
4848
$instance['offset']['end'] - $instance['offset']['start'] + 1
4949
);
5050
}
5151

52-
file_put_contents($file, $contents);
52+
\file_put_contents($file, $contents);
5353
}
5454

5555
return $failure ? 1 : 0;
5656
}
5757

5858
private function leaveComment(string $path, array $calls): void
5959
{
60-
$instances = array_map(
61-
fn ($call) => sprintf('Line %d: contains call to `%s`', $call['line']['start'], $call['function']),
60+
$instances = \array_map(
61+
fn ($call) => \sprintf('Line %d: contains call to `%s`', $call['line']['start'], $call['function']),
6262
$calls
6363
);
6464

0 commit comments

Comments
 (0)