| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace PrismX\Generators\Support; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Support\Str; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Illuminate\Support\Collection; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Illuminate\Support\Facades\File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Symfony\Component\Process\Process; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Illuminate\Support\Facades\Storage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Symfony\Component\Process\Exception\ProcessFailedException; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 11 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 12 |  |  | class CSFixer | 
            
                                                                        
                            
            
                                    
            
            
                | 13 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |     public function __construct() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |         if (File::exists(base_path('vendor/bin/php-cs-fixer')) && File::exists(base_path('.php_cs'))) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |             $process = new Process(array_merge([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |                 base_path('vendor/bin/php-cs-fixer'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |                 'fix', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |                 '--config='.base_path('.php_cs'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             ], $this->paths()->toArray())); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             $process->run(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             if (! $process->isSuccessful()) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |                 throw new ProcessFailedException($process); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 29 |  |  |             echo $process->getOutput(); | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |     } | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     public function paths(): Collection | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |         $modelsPath = Str::camel(str_replace('\\', '/', config('generators.model_namespace'))); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |         $models = glob(base_path($modelsPath.'/*.php')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |         $caches = glob(base_path(Storage::path('generators/cache').'/*.php')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |         return collect([ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |             base_path('database/factories'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |             base_path('database/migrations'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |             base_path('database/seeds'), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |             File::isDirectory('app/Nova') ? base_path('app/nova') : null, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         ]) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |             ->concat($models ?: []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |             ->concat($caches ?: []) | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 48 |  |  |             ->filter(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 50 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 51 |  |  |  |