Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install rector/rector during first run of php artisan ray:clean instead of requiring rector/rector #363

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
"require": {
"ext-json": "*",
"php": "^7.4|^8.0",
"composer-runtime-api": "^2.2",
"illuminate/contracts": "^7.20|^8.19|^9.0|^10.0|^11.0",
"illuminate/database": "^7.20|^8.19|^9.0|^10.0|^11.0",
"illuminate/queue": "^7.20|^8.19|^9.0|^10.0|^11.0",
"illuminate/support": "^7.20|^8.19|^9.0|^10.0|^11.0",
"rector/rector": "^0.19.2|^1.0",
"spatie/backtrace": "^1.0",
"spatie/ray": "^1.41.1",
"symfony/stopwatch": "4.2|^5.1|^6.0|^7.0",
Expand All @@ -35,6 +35,7 @@
"pestphp/pest": "^1.22|^2.0",
"phpstan/phpstan": "^1.10.57",
"phpunit/phpunit": "^9.3|^10.1",
"rector/rector": "^0.19.2|^1.0",
"spatie/pest-plugin-snapshots": "^1.1|^2.0",
"symfony/var-dumper": "^4.2|^5.1|^6.0|^7.0.3"
},
Expand Down
10 changes: 9 additions & 1 deletion src/Commands/CleanRayCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace Spatie\LaravelRay\Commands;

use Composer\InstalledVersions;
use Illuminate\Console\Command;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Facades\Process;
use Spatie\LaravelRay\Support\Composer;

class CleanRayCommand extends Command
{
protected $signature = 'ray:clean';

protected $description = 'Remove all Ray calls from your codebase.';

public function handle()
public function handle(Filesystem $files)
{
$directories = [
'app',
Expand All @@ -23,6 +26,11 @@ public function handle()
'tests',
];

if (! InstalledVersions::isInstalled('rector/rector')) {
(new Composer($files, defined('TESTBENCH_WORKING_PATH') ? TESTBENCH_WORKING_PATH : base_path()))
->requirePackages(['rector/rector'], true, $this->output);
}

$this->withProgressBar($directories, function ($directory) {
$result = Process::run('./vendor/bin/remove-ray.sh ' . $directory);

Expand Down
40 changes: 40 additions & 0 deletions src/Support/Composer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Spatie\LaravelRay\Support;

use Closure;
use Symfony\Component\Console\Output\OutputInterface;

class Composer extends \Illuminate\Support\Composer
{
/**
* Install the given Composer packages into the application.
*
* Override this method for `illuminate/support` 10 and below.
*
* @param array<int, string> $packages
* @param bool $dev
* @param \Closure|\Symfony\Component\Console\Output\OutputInterface|null $output
* @param string|null $composerBinary
* @return bool
*/
public function requirePackages(array $packages, bool $dev = false, Closure|OutputInterface|null $output = null, $composerBinary = null)
{
$command = collect([
...$this->findComposer($composerBinary),
'require',
...$packages,
])
->when($dev, function ($command) {
$command->push('--dev');
})->all();

return 0 === $this->getProcess($command, ['COMPOSER_MEMORY_LIMIT' => '-1'])
->run(
$output instanceof OutputInterface
? function ($type, $line) use ($output) {
$output->write(' '.$line);
} : $output
);
}
}
Loading