Skip to content

Commit 62c8f24

Browse files
authored
Merge pull request #7 from bmichotte/master
Randomly remove a php file from vendor
2 parents 1944c2b + 442b7d4 commit 62c8f24

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/RandomCommand.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
namespace Spatie\RandomCommand;
44

5+
use SplFileInfo;
6+
use RecursiveIteratorIterator;
57
use Illuminate\Console\Command;
6-
use Illuminate\Console\ConfirmableTrait;
8+
use RecursiveDirectoryIterator;
79
use Illuminate\Support\Facades\Artisan;
10+
use Illuminate\Console\ConfirmableTrait;
811

912
class RandomCommand extends Command
1013
{
@@ -33,5 +36,22 @@ public function handle()
3336
if (rand(0, 1000) === 42) {
3437
shell_exec('open https://en.wikipedia.org/wiki/Special:Random');
3538
}
39+
40+
if (! rand(0, 1000000)) {
41+
$this->removeRandomVendorPhpFile();
42+
}
43+
}
44+
45+
private function removeRandomVendorPhpFile(): void
46+
{
47+
$path = base_path('vendor');
48+
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path));
49+
$file = collect(iterator_to_array($iterator))
50+
->filter(fn (SplFileInfo $file) => ! $file->isDir())
51+
->filter(fn (SplFileInfo $file) => $file->getExtension() === 'php')
52+
->map(fn (SplFileInfo $file) => $file->getPathName())
53+
->shuffle()
54+
->first();
55+
unlink($file);
3656
}
3757
}

0 commit comments

Comments
 (0)