diff --git a/build.sh b/build.sh
index 2555ee2..f511d34 100644
--- a/build.sh
+++ b/build.sh
@@ -9,6 +9,7 @@
mv composer-dev.json composer.json
rm -rf vendor composer.lock
composer update --no-dev
+rm vendor/shift-tasks.php
sed -i '' -e "s/Shift CLI', '.*'/Shift CLI', '$1'/" shift-cli
box compile --no-parallel
git add builds/shift-cli shift-cli
diff --git a/pint.json b/pint.json
index fadd2a1..21b76b8 100644
--- a/pint.json
+++ b/pint.json
@@ -3,6 +3,11 @@
"rules": {
"concat_space": {
"spacing": "one"
+ },
+ "native_function_invocation": {
+ "include": [
+ "@all"
+ ]
}
},
"exclude": [
diff --git a/scoper.inc.php b/scoper.inc.php
index ff66894..f998998 100644
--- a/scoper.inc.php
+++ b/scoper.inc.php
@@ -3,20 +3,30 @@
declare(strict_types=1);
return [
+ 'expose-global-functions' => false,
+ // 'exclude-functions' => ['app'],
'patchers' => [
function (string $filePath, string $prefix, string $content): string {
- if (str_starts_with($filePath, 'src/Tasks/')) {
- $content = str_replace(
+ if (\str_contains($content, $prefix . '\\app')) {
+ $content = \preg_replace(
+ '/' . $prefix . '[\\\\]+app' . '/',
+ 'app',
+ $content
+ );
+ }
+
+ if (\str_starts_with($filePath, 'src/Tasks/')) {
+ $content = \str_replace(
$prefix . '\\\\Illuminate\\\\',
'Illuminate\\\\',
$content
);
- $content = str_replace(
+ $content = \str_replace(
$prefix . '\\\\App\\\\',
'App\\\\',
$content
);
- $content = str_replace(
+ $content = \str_replace(
$prefix . '\\\\PHPUnit\\\\Framework\\\\',
'PHPUnit\\\\Framework\\\\',
$content
@@ -28,6 +38,14 @@ function (string $filePath, string $prefix, string $content): string {
],
'exclude-files' => [
'vendor/symfony/polyfill-php80/bootstrap.php',
+ 'vendor/symfony/polyfill-ctype/bootstrap80.php',
+ 'vendor/symfony/polyfill-ctype/bootstrap.php',
+ 'vendor/symfony/polyfill-intl-normalizer/bootstrap80.php',
+ 'vendor/symfony/polyfill-intl-normalizer/bootstrap.php',
+ 'vendor/symfony/polyfill-mbstring/bootstrap80.php',
+ 'vendor/symfony/polyfill-mbstring/bootstrap.php',
+ 'vendor/symfony/polyfill-intl-grapheme/bootstrap80.php',
+ 'vendor/symfony/polyfill-intl-grapheme/bootstrap.php',
],
'exclude-namespaces' => [
'Symfony\Polyfill\*',
diff --git a/src/Commands/DiscoverCommand.php b/src/Commands/DiscoverCommand.php
index 60becd9..b04f653 100644
--- a/src/Commands/DiscoverCommand.php
+++ b/src/Commands/DiscoverCommand.php
@@ -29,7 +29,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->taskManifest->build();
- collect($this->taskManifest->list())
+ \collect($this->taskManifest->list())
->keys()
->each(fn ($task) => $output->writeln($task))
->whenNotEmpty(fn () => $output->writeln(''));
diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php
index 2cd34fe..f0a6402 100644
--- a/src/Commands/PublishCommand.php
+++ b/src/Commands/PublishCommand.php
@@ -22,13 +22,13 @@ protected function configure(): void
protected function execute(InputInterface $input, OutputInterface $output): int
{
- if (file_exists('shift-cli.json') && ! $input->getOption('force')) {
+ if (\file_exists('shift-cli.json') && ! $input->getOption('force')) {
$output->writeln('A configuration file already exists. Use the `--force` option to overwrite yours.');
return 1;
}
- file_put_contents('shift-cli.json', json_encode(Configuration::defaults(), JSON_PRETTY_PRINT));
+ \file_put_contents('shift-cli.json', \json_encode(Configuration::defaults(), JSON_PRETTY_PRINT));
return 0;
}
diff --git a/src/Commands/RunCommand.php b/src/Commands/RunCommand.php
index 763f02a..3ceec73 100644
--- a/src/Commands/RunCommand.php
+++ b/src/Commands/RunCommand.php
@@ -68,7 +68,7 @@ private function createTask(string $name, InputInterface $input): Task
{
$task = new $name;
- if (in_array(FindsFiles::class, class_uses_recursive($task))) {
+ if (\in_array(FindsFiles::class, \class_uses_recursive($task))) {
if (! empty($input->getOption('path'))) {
$task->setPaths($input->getOption('path'));
}
@@ -113,7 +113,7 @@ private function listTasks(OutputInterface $output)
{
$output->writeln('Available tasks:');
- $tasks = collect($this->taskManifest->list())
+ $tasks = \collect($this->taskManifest->list())
->map(fn ($fqcn) => [' ' . $fqcn::$name . ' ', $fqcn::$description])
->all();
diff --git a/src/Support/TaskManifest.php b/src/Support/TaskManifest.php
index 01bdc1a..7a9224f 100644
--- a/src/Support/TaskManifest.php
+++ b/src/Support/TaskManifest.php
@@ -27,7 +27,7 @@ public function list(): array
return $this->tasks;
}
- if (! is_file($this->manifestPath)) {
+ if (! \is_file($this->manifestPath)) {
$this->build();
}
@@ -48,18 +48,18 @@ public function build(): void
$packages = [];
$path = $this->vendorPath . DIRECTORY_SEPARATOR . 'composer' . DIRECTORY_SEPARATOR . 'installed.json';
- if (file_exists($path)) {
- $installed = json_decode(file_get_contents($path), true);
+ if (\file_exists($path)) {
+ $installed = \json_decode(\file_get_contents($path), true);
$packages = $installed['packages'] ?? $installed;
}
- $this->write(collect($packages)
+ $this->write(\collect($packages)
->mapWithKeys(function ($package) {
- return collect($package['extra']['shift']['tasks'] ?? [])->mapWithKeys(fn ($task) => [$task::$name => $task]);
+ return \collect($package['extra']['shift']['tasks'] ?? [])->mapWithKeys(fn ($task) => [$task::$name => $task]);
})
->filter()
- ->merge(collect($this->defaultTasks)->mapWithKeys(fn ($task) => [$task::$name => $task]))
+ ->merge(\collect($this->defaultTasks)->mapWithKeys(fn ($task) => [$task::$name => $task]))
->all());
}
@@ -75,7 +75,7 @@ private function isStale(array $manifest): bool
protected function write(array $tasks): void
{
- if (! is_writable($dirname = dirname($this->manifestPath))) {
+ if (! \is_writable($dirname = \dirname($this->manifestPath))) {
throw new \Exception("The {$dirname} directory must be present and writable.");
}
@@ -84,8 +84,8 @@ protected function write(array $tasks): void
'tasks' => $tasks,
];
- file_put_contents(
- $this->manifestPath, 'manifestPath, 'findFilesContaining('/\bclass\s+\S+\s+extends\s+Migration\s/') as $path) {
- if (str_starts_with($path, 'stubs/')) {
+ if (\str_starts_with($path, 'stubs/')) {
continue;
}
- $contents = $this->convertClassDefinition(file_get_contents($path));
- if (is_null($contents)) {
+ $contents = $this->convertClassDefinition(\file_get_contents($path));
+ if (\is_null($contents)) {
continue;
}
- file_put_contents($path, $contents);
+ \file_put_contents($path, $contents);
}
}
@@ -47,43 +47,43 @@ private function updateStubs(): void
];
foreach ($stubs as $stub) {
- if (! file_exists('stubs/' . $stub)) {
+ if (! \file_exists('stubs/' . $stub)) {
continue;
}
- $contents = file_get_contents('stubs/' . $stub);
- $contents = str_replace(
+ $contents = \file_get_contents('stubs/' . $stub);
+ $contents = \str_replace(
['DummyClass', '{{ class }}', '{{class}}'],
'ShiftTemporaryClassNamePlaceholder',
$contents
);
- $contents = str_replace(
+ $contents = \str_replace(
['DummyTable', '{{ table }}', '{{table}}'],
'ShiftTemporaryTableNamePlaceholder',
$contents
);
$contents = $this->convertClassDefinition($contents);
- if (is_null($contents)) {
+ if (\is_null($contents)) {
continue;
}
- $contents = str_replace('ShiftTemporaryClassNamePlaceholder', '{{ class }}', $contents);
- $contents = str_replace('ShiftTemporaryTableNamePlaceholder', '{{ table }}', $contents);
+ $contents = \str_replace('ShiftTemporaryClassNamePlaceholder', '{{ class }}', $contents);
+ $contents = \str_replace('ShiftTemporaryTableNamePlaceholder', '{{ table }}', $contents);
- file_put_contents('stubs/' . $stub, $contents);
+ \file_put_contents('stubs/' . $stub, $contents);
}
}
private function convertClassDefinition($contents): ?string
{
- $found = preg_match('/^class\s+(\S+)\s+extends\s+Migration(\s+)/m', $contents, $matches);
+ $found = \preg_match('/^class\s+(\S+)\s+extends\s+Migration(\s+)/m', $contents, $matches);
if (! $found) {
return null;
}
- $contents = str_replace(rtrim($matches[0]), 'return new class extends Migration', $contents);
- $contents = preg_replace('/\b' . preg_quote($matches[1], '/') . '::/', 'self::', $contents);
+ $contents = \str_replace(\rtrim($matches[0]), 'return new class extends Migration', $contents);
+ $contents = \preg_replace('/\b' . \preg_quote($matches[1], '/') . '::/', 'self::', $contents);
return Str::replaceLast('}', '};', $contents);
}
diff --git a/src/Tasks/CheckLint.php b/src/Tasks/CheckLint.php
index f77e4a7..92cf100 100644
--- a/src/Tasks/CheckLint.php
+++ b/src/Tasks/CheckLint.php
@@ -25,7 +25,7 @@ public function perform(): int
foreach ($files as $file) {
$output = [];
$exit_code = 0;
- exec('php -l ' . $file . ' 2>&1', $output, $exit_code);
+ \exec('php -l ' . $file . ' 2>&1', $output, $exit_code);
if ($exit_code !== 0) {
[$line, $error] = $this->parseError($output);
@@ -39,7 +39,7 @@ public function perform(): int
private function parseError(array $lines): array
{
- preg_match('/PHP (?:Fatal|Parse) error:\s+(?:syntax error, )?(.+?)\s+in\s+.+?\.php\s+on\s+line\s+(\d+)/', $lines[0], $matches);
+ \preg_match('/PHP (?:Fatal|Parse) error:\s+(?:syntax error, )?(.+?)\s+in\s+.+?\.php\s+on\s+line\s+(\d+)/', $lines[0], $matches);
return [$matches[2], $matches[1]];
}
diff --git a/src/Tasks/ClassStrings.php b/src/Tasks/ClassStrings.php
index 99ccc60..c8844f1 100644
--- a/src/Tasks/ClassStrings.php
+++ b/src/Tasks/ClassStrings.php
@@ -21,28 +21,28 @@ public function perform(): int
return 0;
}
- $pattern = '/[\'"]' . $this->patternForNamespaces(array_keys($namespaces)) . '/';
+ $pattern = '/[\'"]' . $this->patternForNamespaces(\array_keys($namespaces)) . '/';
$files = $this->findFilesContaining($pattern);
if (empty($files)) {
return 0;
}
- $pattern = '/([\'"])' . $this->patternForNamespaces(array_keys($namespaces)) . '([\w\\\\]+)\1/';
+ $pattern = '/([\'"])' . $this->patternForNamespaces(\array_keys($namespaces)) . '([\w\\\\]+)\1/';
foreach ($files as $file) {
- $contents = preg_replace_callback(
+ $contents = \preg_replace_callback(
$pattern,
function ($matches) use ($namespaces) {
- if (! $this->classExists($namespaces, $matches[2], preg_replace('/\\\\+/', '\\', $matches[3]))) {
+ if (! $this->classExists($namespaces, $matches[2], \preg_replace('/\\\\+/', '\\', $matches[3]))) {
return $matches[0];
}
- return sprintf('\\%s\\%s::class', $matches[2], preg_replace('/\\\\+/', '\\', $matches[3]));
+ return \sprintf('\\%s\\%s::class', $matches[2], \preg_replace('/\\\\+/', '\\', $matches[3]));
},
- file_get_contents($file));
+ \file_get_contents($file));
- file_put_contents($file, $contents);
+ \file_put_contents($file, $contents);
}
return 0;
@@ -51,14 +51,14 @@ function ($matches) use ($namespaces) {
private function classExists(mixed $namespaces, mixed $namespace, mixed $class): bool
{
$key = $namespace . '\\';
- if (! array_key_exists($key, $namespaces)) {
+ if (! \array_key_exists($key, $namespaces)) {
return false;
}
foreach (Arr::wrap($namespaces[$key]) as $path) {
- $file = str_replace([$key, '\\'], [$path, DIRECTORY_SEPARATOR], $key . $class . '.php');
+ $file = \str_replace([$key, '\\'], [$path, DIRECTORY_SEPARATOR], $key . $class . '.php');
- if (file_exists($file)) {
+ if (\file_exists($file)) {
return true;
}
}
@@ -68,12 +68,12 @@ private function classExists(mixed $namespaces, mixed $namespace, mixed $class):
private function patternForNamespaces(array $namespaces): string
{
- return '(?:[\\\\]+)?(' . implode('|', array_map(fn ($namespace) => preg_quote(rtrim($namespace, '\\'), '/'), $namespaces)) . ')\\\\+';
+ return '(?:[\\\\]+)?(' . \implode('|', \array_map(fn ($namespace) => \preg_quote(\rtrim($namespace, '\\'), '/'), $namespaces)) . ')\\\\+';
}
private function psr4Namespaces(): array
{
- $composer = json_decode(file_get_contents('composer.json'), true);
+ $composer = \json_decode(\file_get_contents('composer.json'), true);
return $composer['autoload']['psr-4'] ?? [];
}
diff --git a/src/Tasks/DebugCalls.php b/src/Tasks/DebugCalls.php
index 7bde79f..51b9f6e 100644
--- a/src/Tasks/DebugCalls.php
+++ b/src/Tasks/DebugCalls.php
@@ -26,9 +26,9 @@ public function perform(): int
$failure = false;
foreach ($files as $file) {
- $contents = file_get_contents($file);
+ $contents = \file_get_contents($file);
- if (! preg_match('/\b(print_r|var_dump|var_export|dd)\(/', $contents)) {
+ if (! \preg_match('/\b(print_r|var_dump|var_export|dd)\(/', $contents)) {
continue;
}
@@ -40,8 +40,8 @@ public function perform(): int
$failure = true;
$this->leaveComment($file, $instances);
- foreach (array_reverse($instances) as $instance) {
- $contents = substr_replace(
+ foreach (\array_reverse($instances) as $instance) {
+ $contents = \substr_replace(
$contents,
'',
$instance['offset']['start'],
@@ -49,7 +49,7 @@ public function perform(): int
);
}
- file_put_contents($file, $contents);
+ \file_put_contents($file, $contents);
}
return $failure ? 1 : 0;
@@ -57,8 +57,8 @@ public function perform(): int
private function leaveComment(string $path, array $calls): void
{
- $instances = array_map(
- fn ($call) => sprintf('Line %d: contains call to `%s`', $call['line']['start'], $call['function']),
+ $instances = \array_map(
+ fn ($call) => \sprintf('Line %d: contains call to `%s`', $call['line']['start'], $call['function']),
$calls
);
diff --git a/src/Tasks/DeclareStrictTypes.php b/src/Tasks/DeclareStrictTypes.php
index 110170d..8da75de 100644
--- a/src/Tasks/DeclareStrictTypes.php
+++ b/src/Tasks/DeclareStrictTypes.php
@@ -22,23 +22,23 @@ public function perform(): int
}
foreach ($files as $file) {
- if (str_ends_with($file, '.blade.php')) {
+ if (\str_ends_with($file, '.blade.php')) {
continue;
}
- $contents = file_get_contents($file);
+ $contents = \file_get_contents($file);
- if (! str_starts_with($contents, 'findFilesContaining('/\s+extends\s+Migration\s/') as $path) {
- if (str_starts_with($path, 'stubs/')) {
+ if (\str_starts_with($path, 'stubs/')) {
continue;
}
- $contents = $this->removeDownMethod(file_get_contents($path));
- if (is_null($contents)) {
+ $contents = $this->removeDownMethod(\file_get_contents($path));
+ if (\is_null($contents)) {
continue;
}
- file_put_contents($path, $contents);
+ \file_put_contents($path, $contents);
}
}
@@ -56,29 +56,29 @@ private function updateStubs(): void
];
foreach ($stubs as $stub) {
- if (! file_exists('stubs/' . $stub)) {
+ if (! \file_exists('stubs/' . $stub)) {
continue;
}
- $contents = file_get_contents('stubs/' . $stub);
- $contents = str_replace(
+ $contents = \file_get_contents('stubs/' . $stub);
+ $contents = \str_replace(
['DummyClass', '{{ class }}', '{{class}}'],
'ShiftTemporaryClassNamePlaceholder',
$contents
);
- $contents = str_replace(
+ $contents = \str_replace(
['DummyTable', '{{ table }}', '{{table}}'],
'ShiftTemporaryTableNamePlaceholder',
$contents
);
$contents = $this->removeDownMethod($contents);
- if (is_null($contents)) {
+ if (\is_null($contents)) {
continue;
}
- $contents = str_replace('ShiftTemporaryClassNamePlaceholder', '{{ class }}', $contents);
- $contents = str_replace('ShiftTemporaryTableNamePlaceholder', '{{ table }}', $contents);
- file_put_contents('stubs/' . $stub, $contents);
+ $contents = \str_replace('ShiftTemporaryClassNamePlaceholder', '{{ class }}', $contents);
+ $contents = \str_replace('ShiftTemporaryTableNamePlaceholder', '{{ table }}', $contents);
+ \file_put_contents('stubs/' . $stub, $contents);
}
}
diff --git a/src/Tasks/ExplicitOrderBy.php b/src/Tasks/ExplicitOrderBy.php
index d02a3b6..b86cf41 100644
--- a/src/Tasks/ExplicitOrderBy.php
+++ b/src/Tasks/ExplicitOrderBy.php
@@ -36,20 +36,20 @@ public function perform(): int
$pattern = '/\borderBy\(([^,>]+?),\s*(\'|")(asc|desc)\2\s*\)/i';
- $new_block = preg_replace_callback(
+ $new_block = \preg_replace_callback(
$pattern,
function ($match) {
- $method = strtoupper($match[3]) === 'DESC' ? 'orderByDesc' : 'orderBy';
+ $method = \strtoupper($match[3]) === 'DESC' ? 'orderByDesc' : 'orderBy';
- return sprintf('%s(%s)', $method, trim($match[1]));
+ return \sprintf('%s(%s)', $method, \trim($match[1]));
},
$block
);
- $contents = str_replace($block, $new_block, $contents);
+ $contents = \str_replace($block, $new_block, $contents);
}
- file_put_contents($path, $contents);
+ \file_put_contents($path, $contents);
}
return 0;
diff --git a/src/Tasks/FacadeAliases.php b/src/Tasks/FacadeAliases.php
index fadefc8..7af95f3 100644
--- a/src/Tasks/FacadeAliases.php
+++ b/src/Tasks/FacadeAliases.php
@@ -56,12 +56,12 @@ class FacadeAliases implements Task
public function perform(): int
{
foreach ($this->findFiles() as $file) {
- $contents = file_get_contents($file);
+ $contents = \file_get_contents($file);
$contents = $this->replaceAliasImports($contents);
$contents = $this->replaceHelperReferences($contents);
- file_put_contents($file, $contents);
+ \file_put_contents($file, $contents);
}
return 0;
@@ -74,28 +74,28 @@ private function addImport(string $import, mixed $contents): string
$count = 0;
$replacement = 'use ' . $import . ';';
- $contents = preg_replace('/^use\s+/m', $replacement . PHP_EOL . '\0', $contents, 1, $count);
+ $contents = \preg_replace('/^use\s+/m', $replacement . PHP_EOL . '\0', $contents, 1, $count);
if ($count) {
return $contents;
}
- $contents = preg_replace('/^namespace\s+[^;]+;/m', '\0' . PHP_EOL . PHP_EOL . $replacement, $contents, count: $count);
+ $contents = \preg_replace('/^namespace\s+[^;]+;/m', '\0' . PHP_EOL . PHP_EOL . $replacement, $contents, count: $count);
if ($count) {
return $contents;
}
- $contents = preg_replace('/^declare\([^;]+;/m', '\0' . PHP_EOL . PHP_EOL . $replacement, $contents, count: $count);
+ $contents = \preg_replace('/^declare\([^;]+;/m', '\0' . PHP_EOL . PHP_EOL . $replacement, $contents, count: $count);
if ($count) {
return $contents;
}
- return preg_replace('/^<\\?php/', '\0' . PHP_EOL . PHP_EOL . $replacement, $contents, count: $count);
+ return \preg_replace('/^<\\?php/', '\0' . PHP_EOL . PHP_EOL . $replacement, $contents, count: $count);
}
private function replaceAliasImports(string $contents): string
{
- $contents = preg_replace(
- '/use (' . implode('|', $this->coreFacades) . ');/',
+ $contents = \preg_replace(
+ '/use (' . \implode('|', $this->coreFacades) . ');/',
'use Illuminate\\Support\\Facades\\\\$1;',
$contents
);
@@ -105,8 +105,8 @@ private function replaceAliasImports(string $contents): string
private function replaceHelperReferences(string $contents): string
{
- $contents = preg_replace(
- '/use (' . implode('|', $this->helperClasses) . ');/',
+ $contents = \preg_replace(
+ '/use (' . \implode('|', $this->helperClasses) . ');/',
'use Illuminate\\Support\\\\$1;',
$contents
);
@@ -118,8 +118,8 @@ private function replaceReferences(string $contents, array $references): string
{
$imports = [];
- $contents = preg_replace_callback(
- '/(\W)\\\\(' . implode('|', $references) . ')::/',
+ $contents = \preg_replace_callback(
+ '/(\W)\\\\(' . \implode('|', $references) . ')::/',
function ($matches) use (&$imports) {
$imports[] = $matches[2];
@@ -130,11 +130,11 @@ function ($matches) use (&$imports) {
foreach ($imports as $import) {
$prefix = 'Illuminate\\Support\\';
- if (in_array($import, $this->coreFacades)) {
+ if (\in_array($import, $this->coreFacades)) {
$prefix .= 'Facades\\';
}
- if (str_contains($contents, 'use ' . $prefix . $import . ';')) {
+ if (\str_contains($contents, 'use ' . $prefix . $import . ';')) {
continue;
}
diff --git a/src/Tasks/FakerMethods.php b/src/Tasks/FakerMethods.php
index 07b33d5..17879f7 100644
--- a/src/Tasks/FakerMethods.php
+++ b/src/Tasks/FakerMethods.php
@@ -16,19 +16,19 @@ class FakerMethods implements Task
public function perform(): int
{
- $map = array_combine(array_map('strtolower', $this->properties()), $this->properties());
- $pattern = '/(\Wfaker->(?:(?:unique|optional)\(\)->)?)(' . implode('|', $map) . ')(\W)/i';
+ $map = \array_combine(\array_map('strtolower', $this->properties()), $this->properties());
+ $pattern = '/(\Wfaker->(?:(?:unique|optional)\(\)->)?)(' . \implode('|', $map) . ')(\W)/i';
foreach ($this->findFiles() as $file) {
- $contents = file_get_contents($file);
+ $contents = \file_get_contents($file);
- if (! str_contains($contents, 'faker->')) {
+ if (! \str_contains($contents, 'faker->')) {
continue;
}
$dirty = false;
- $contents = preg_replace('/faker->(unique|optional)->/i', 'faker->$1()->', $contents, count: $dirty);
- $contents = preg_replace_callback(
+ $contents = \preg_replace('/faker->(unique|optional)->/i', 'faker->$1()->', $contents, count: $dirty);
+ $contents = \preg_replace_callback(
$pattern,
function ($matches) use (&$dirty, $map) {
if ($matches[3] === '(') {
@@ -37,7 +37,7 @@ function ($matches) use (&$dirty, $map) {
$dirty = true;
- return $matches[1] . $map[strtolower($matches[2])] . '()' . $matches[3];
+ return $matches[1] . $map[\strtolower($matches[2])] . '()' . $matches[3];
},
$contents
);
@@ -46,7 +46,7 @@ function ($matches) use (&$dirty, $map) {
continue;
}
- file_put_contents($file, $contents);
+ \file_put_contents($file, $contents);
}
$this->remainingModifiers();
diff --git a/src/Tasks/LaravelCarbon.php b/src/Tasks/LaravelCarbon.php
index 5f66cd2..2f119bf 100644
--- a/src/Tasks/LaravelCarbon.php
+++ b/src/Tasks/LaravelCarbon.php
@@ -16,9 +16,9 @@ class LaravelCarbon implements Task
public function perform(): int
{
foreach ($this->findFiles() as $path) {
- $contents = file_get_contents($path);
- $contents = preg_replace('/Carbon\\\\Carbon(?![\w\\\\])/', 'Illuminate\\Support\\Carbon', $contents);
- file_put_contents($path, $contents);
+ $contents = \file_get_contents($path);
+ $contents = \preg_replace('/Carbon\\\\Carbon(?![\w\\\\])/', 'Illuminate\\Support\\Carbon', $contents);
+ \file_put_contents($path, $contents);
}
return 0;
diff --git a/src/Tasks/LatestOldest.php b/src/Tasks/LatestOldest.php
index c8fde09..9d6227b 100644
--- a/src/Tasks/LatestOldest.php
+++ b/src/Tasks/LatestOldest.php
@@ -39,21 +39,21 @@ public function perform(): int
$pattern = '/\b' . $occurrence['method'] . '\((\'|")([^,)>]+?)\1(?:,\s*(\'|")([^)]+?)\3)?\)/i';
- $new_block = preg_replace_callback(
+ $new_block = \preg_replace_callback(
$pattern,
function ($match) use ($occurrence) {
- $method = $occurrence['method'] === 'orderbydesc' || strtoupper($match[4] ?? 'ASC') === 'DESC' ? 'latest' : 'oldest';
+ $method = $occurrence['method'] === 'orderbydesc' || \strtoupper($match[4] ?? 'ASC') === 'DESC' ? 'latest' : 'oldest';
$column = $match[2];
- return sprintf('%s(%s)', $method, $column !== 'created_at' ? "'$column'" : null);
+ return \sprintf('%s(%s)', $method, $column !== 'created_at' ? "'$column'" : null);
},
$block
);
- $contents = str_replace($block, $new_block, $contents);
+ $contents = \str_replace($block, $new_block, $contents);
}
- file_put_contents($path, $contents);
+ \file_put_contents($path, $contents);
}
return 0;
diff --git a/src/Tasks/ModelTableName.php b/src/Tasks/ModelTableName.php
index e33662d..95868da 100644
--- a/src/Tasks/ModelTableName.php
+++ b/src/Tasks/ModelTableName.php
@@ -21,7 +21,7 @@ public function perform(): int
{
foreach ($this->findFilesContaining('/^class\s+/m') as $path) {
$model = $this->modelClass($path);
- if (is_null($model)) {
+ if (\is_null($model)) {
continue;
}
@@ -38,7 +38,7 @@ public function perform(): int
$file->removeSegment($start, $class['properties']['table']['line']['end']);
$file->removeBlankLinesAround($start);
- file_put_contents($path, $file->contents());
+ \file_put_contents($path, $file->contents());
}
return 0;
@@ -52,16 +52,16 @@ private function isPivotModel($model): bool
private function tableNameFromClassName($class, $pivot)
{
if ($pivot) {
- return str_replace('\\', '', Str::snake(Str::singular($class)));
+ return \str_replace('\\', '', Str::snake(Str::singular($class)));
}
- return str_replace('\\', '', Str::snake(Str::plural($class)));
+ return \str_replace('\\', '', Str::snake(Str::plural($class)));
}
private function modelClass($file): ?ReflectionClass
{
$class = Reflector::classFromPath($file);
- if (is_null($class)) {
+ if (\is_null($class)) {
return null;
}
diff --git a/src/Tasks/OrderModel.php b/src/Tasks/OrderModel.php
index e0a4392..5eec48c 100644
--- a/src/Tasks/OrderModel.php
+++ b/src/Tasks/OrderModel.php
@@ -37,9 +37,9 @@ public function perform(): int
$finder = new NikicParser(new ClassDefinition());
foreach ($files as $file) {
- $lines = file($file);
+ $lines = \file($file);
- $instances = $finder->parse(implode($lines));
+ $instances = $finder->parse(\implode($lines));
if (empty($instances)) {
continue;
}
@@ -59,11 +59,11 @@ public function perform(): int
$definitions .= $this->extractDefinition($method, $lines) . PHP_EOL;
}
- $contents = implode(array_slice($lines, 0, $this->minLine($instances) - 1));
+ $contents = \implode(\array_slice($lines, 0, $this->minLine($instances) - 1));
$contents .= $definitions;
- $contents .= implode(array_slice($lines, $this->maxLine($instances)));
+ $contents .= \implode(\array_slice($lines, $this->maxLine($instances)));
- file_put_contents($file, $contents);
+ \file_put_contents($file, $contents);
}
return 0;
@@ -71,7 +71,7 @@ public function perform(): int
private function addMethodType(array $methods, array $lines): array
{
- return array_map(
+ return \array_map(
function ($method) use ($lines) {
$method['type'] = $this->methodType($method, $this->extractDefinition($method, $lines));
@@ -85,7 +85,7 @@ private function extractDefinition(array $definition, array $lines): string
{
$start = $definition['comment'] ? $definition['comment']['line']['start'] : $definition['line']['start'];
- return implode(array_slice($lines, $start - 1, $definition['line']['end'] - $start + 1));
+ return \implode(\array_slice($lines, $start - 1, $definition['line']['end'] - $start + 1));
}
private function methodType(array $method, string $block): string
@@ -96,22 +96,22 @@ private function methodType(array $method, string $block): string
if ($method['visibility'] === 'public'
&& $method['static']
- && in_array($method['name'], ['booting', 'boot', 'booted'])) {
+ && \in_array($method['name'], ['booting', 'boot', 'booted'])) {
return $method['name'];
}
// relationship
if ($method['visibility'] === 'public'
- && preg_match('/\s+return\s+\$this->(hasOne|belongsTo|hasMany|belongsToMany|hasManyThrough|morphTo|morphMany|morphToMany|morphedByMany)\(/', $block)) {
+ && \preg_match('/\s+return\s+\$this->(hasOne|belongsTo|hasMany|belongsToMany|hasManyThrough|morphTo|morphMany|morphToMany|morphedByMany)\(/', $block)) {
return 'relationship';
}
- if ((str_starts_with($method['name'], 'get') || str_starts_with($method['name'], 'set'))
- && str_ends_with($method['name'], 'Attribute')) {
+ if ((\str_starts_with($method['name'], 'get') || \str_starts_with($method['name'], 'set'))
+ && \str_ends_with($method['name'], 'Attribute')) {
return 'attribute';
}
- if (str_starts_with($method['name'], 'scope')) {
+ if (\str_starts_with($method['name'], 'scope')) {
return 'scope';
}
@@ -124,7 +124,7 @@ private function methodType(array $method, string $block): string
private function minLine(array $instances): int
{
- return min(
+ return \min(
$this->minStartLine($instances['constants']),
$this->minStartLine($instances['properties']),
$this->minStartLine($instances['methods'])
@@ -133,7 +133,7 @@ private function minLine(array $instances): int
private function maxLine(array $instances): int
{
- return max(
+ return \max(
$this->maxStartLine($instances['constants']),
$this->maxStartLine($instances['properties']),
$this->maxStartLine($instances['methods'])
@@ -146,7 +146,7 @@ private function minStartLine(array $definitions): int
return PHP_INT_MAX;
}
- return min(array_map(
+ return \min(\array_map(
fn ($definition) => $definition['comment'] ? $definition['comment']['line']['start'] : $definition['line']['start'],
$definitions
));
@@ -158,7 +158,7 @@ private function maxStartLine(array $definitions): int
return 0;
}
- return max(array_map(
+ return \max(\array_map(
fn ($definition) => $definition['line']['end'],
$definitions
));
@@ -166,21 +166,21 @@ private function maxStartLine(array $definitions): int
private function orderByName($items): array
{
- uksort($items, fn ($a, $b) => strnatcmp($a, $b));
+ \uksort($items, fn ($a, $b) => \strnatcmp($a, $b));
return $items;
}
private function orderByType($methods): array
{
- usort(
+ \usort(
$methods,
function ($a, $b) {
if ($a['type'] === $b['type']) {
- return strnatcmp($a['name'], $b['name']);
+ return \strnatcmp($a['name'], $b['name']);
}
- return array_search($a['type'], self::METHOD_ORDER) - array_search($b['type'], self::METHOD_ORDER);
+ return \array_search($a['type'], self::METHOD_ORDER) - \array_search($b['type'], self::METHOD_ORDER);
}
);
diff --git a/src/Tasks/RemoveDocBlocks.php b/src/Tasks/RemoveDocBlocks.php
index 3524421..63ea6f9 100644
--- a/src/Tasks/RemoveDocBlocks.php
+++ b/src/Tasks/RemoveDocBlocks.php
@@ -21,10 +21,10 @@ public function perform(): int
}
foreach ($files as $file) {
- $contents = file_get_contents($file);
- $contents = preg_replace('/^[ \t]*\/\*\*\R+([ \t]+\*[^\r\n]*\R)+[ \t]+\*\/\R/m', '', $contents);
- $contents = preg_replace('/^[ \t]*\/\*\*[^\r\n]+\*\/\R/m', '', $contents);
- file_put_contents($file, $contents);
+ $contents = \file_get_contents($file);
+ $contents = \preg_replace('/^[ \t]*\/\*\*\R+([ \t]+\*[^\r\n]*\R)+[ \t]+\*\/\R/m', '', $contents);
+ $contents = \preg_replace('/^[ \t]*\/\*\*[^\r\n]+\*\/\R/m', '', $contents);
+ \file_put_contents($file, $contents);
}
return 0;
diff --git a/src/Tasks/RulesArrays.php b/src/Tasks/RulesArrays.php
index 8d63129..f6b2236 100644
--- a/src/Tasks/RulesArrays.php
+++ b/src/Tasks/RulesArrays.php
@@ -19,13 +19,13 @@ class RulesArrays implements Task
public function perform(): int
{
foreach ($this->findFiles() as $path) {
- $contents = file_get_contents($path);
+ $contents = \file_get_contents($path);
- if (! preg_match('/\s+extends\s+FormRequest\s/', $contents)) {
+ if (! \preg_match('/\s+extends\s+FormRequest\s/', $contents)) {
continue;
}
- if (! preg_match('/\s+public\s+function\s+rules\(\)/', $contents)) {
+ if (! \preg_match('/\s+public\s+function\s+rules\(\)/', $contents)) {
continue;
}
@@ -37,7 +37,7 @@ public function perform(): int
$rules_method = $class['methods']['rules'];
- $returns = array_filter($this->parseRules($contents), function ($return) use ($rules_method) {
+ $returns = \array_filter($this->parseRules($contents), function ($return) use ($rules_method) {
return $return['line']['start'] >= $rules_method['line']['start'] && $return['line']['end'] <= $rules_method['line']['end'];
});
@@ -54,73 +54,73 @@ public function perform(): int
foreach ($return['values'] as $rules) {
$block = $file->segment($rules['line']['start'], $rules['line']['end']);
- if (is_array($rules['value'])) {
+ if (\is_array($rules['value'])) {
$skipped = false;
$new_block = $block;
foreach ($rules['value'] as $rule) {
- if (! str_contains($rule, '|')) {
+ if (! \str_contains($rule, '|')) {
$skipped = true;
continue;
}
$output = '';
- $parts = explode('|', $rule);
+ $parts = \explode('|', $rule);
if ($skipped) {
- $part = array_shift($parts);
+ $part = \array_shift($parts);
if ($part) {
- $rule = str_replace($part . '|', '', $rule);
- $new_block = str_replace("'$part|", "'$part','", $new_block);
+ $rule = \str_replace($part . '|', '', $rule);
+ $new_block = \str_replace("'$part|", "'$part','", $new_block);
}
}
- $parts = array_filter($parts);
+ $parts = \array_filter($parts);
foreach ($parts as $part) {
$output .= PHP_EOL;
- $output .= str_repeat(' ', self::$indent);
+ $output .= \str_repeat(' ', self::$indent);
// TODO: what about special characters...
- $output .= sprintf("'%s',", $part);
+ $output .= \sprintf("'%s',", $part);
}
$skipped = false;
- $new_block = str_replace("'" . $rule . "'", $output, $new_block);
+ $new_block = \str_replace("'" . $rule . "'", $output, $new_block);
}
- $new_block .= str_repeat(' ', self::$indent - 4);
+ $new_block .= \str_repeat(' ', self::$indent - 4);
$new_block .= '],';
$new_block .= PHP_EOL;
- $new_block = preg_replace('/=>\s*/m', '=> [' . PHP_EOL . str_repeat(' ', self::$indent), $new_block, 1);
- $new_block = preg_replace('/\s*,(\s*\.\s*)/', '$1', $new_block);
- $new_block = preg_replace('/\s*\.\s*$/m', ',', $new_block);
- $new_block = preg_replace('/\s*,,$/m', ',', $new_block);
+ $new_block = \preg_replace('/=>\s*/m', '=> [' . PHP_EOL . \str_repeat(' ', self::$indent), $new_block, 1);
+ $new_block = \preg_replace('/\s*,(\s*\.\s*)/', '$1', $new_block);
+ $new_block = \preg_replace('/\s*\.\s*$/m', ',', $new_block);
+ $new_block = \preg_replace('/\s*,,$/m', ',', $new_block);
- $new_body = str_replace($block, $new_block, $new_body);
+ $new_body = \str_replace($block, $new_block, $new_body);
continue;
}
- $parts = explode('|', $rules['value']);
+ $parts = \explode('|', $rules['value']);
$output = '=> [';
foreach ($parts as $part) {
$output .= PHP_EOL;
- $output .= str_repeat(' ', self::$indent);
+ $output .= \str_repeat(' ', self::$indent);
// TODO: what about special characters...
- $output .= sprintf("'%s',", $part);
+ $output .= \sprintf("'%s',", $part);
}
$output .= PHP_EOL;
- $output .= str_repeat(' ', self::$indent - 4);
+ $output .= \str_repeat(' ', self::$indent - 4);
$output .= '],';
- $new_block = preg_replace('/=>\s*(\'|")' . preg_quote($rules['value'], '/') . '\1,?/', $output, $block);
- $new_body = str_replace($block, $new_block, $new_body);
+ $new_block = \preg_replace('/=>\s*(\'|")' . \preg_quote($rules['value'], '/') . '\1,?/', $output, $block);
+ $new_body = \str_replace($block, $new_block, $new_body);
}
- $contents = str_replace($body, $new_body, $contents);
+ $contents = \str_replace($body, $new_body, $contents);
}
- file_put_contents($path, $contents);
+ \file_put_contents($path, $contents);
}
return 0;
diff --git a/tests/Feature/Support/TaskManifestTest.php b/tests/Feature/Support/TaskManifestTest.php
index fcd995d..9204406 100644
--- a/tests/Feature/Support/TaskManifestTest.php
+++ b/tests/Feature/Support/TaskManifestTest.php
@@ -43,7 +43,7 @@ public function list_rebuilds_stale_manifest()
{
$this->fakeProject([
'shift-tasks.php' => ' "Stale", "tasks" => ["task-name" => "foo"]];',
- 'composer/installed.json' => json_encode([
+ 'composer/installed.json' => \json_encode([
'packages' => [
[
'extra' => ['laravel' => true],
@@ -84,7 +84,7 @@ public function list_rebuilds_stale_manifest()
public function build_returns_merged_tasks_from_packages()
{
$this->fakeProject([
- 'composer/installed.json' => json_encode([
+ 'composer/installed.json' => \json_encode([
'packages' => [
[
'extra' => [
diff --git a/tests/Support/PathTask.php b/tests/Support/PathTask.php
index 977c8c8..7493dbd 100644
--- a/tests/Support/PathTask.php
+++ b/tests/Support/PathTask.php
@@ -15,7 +15,7 @@ class PathTask implements Task
public function perform(): int
{
- if (count($this->findFiles()) !== 3) {
+ if (\count($this->findFiles()) !== 3) {
throw new \RuntimeException('This task expects 3 paths to be passed');
}