| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace Scaffolder\Compilers\AngularJs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Illuminate\Support\Facades\File; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Scaffolder\Compilers\AbstractCompiler; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Scaffolder\Compilers\Support\FileToCompile; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Scaffolder\Compilers\Support\PathParser; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Scaffolder\Support\CamelCase; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | class IndexModuleCompiler extends AbstractCompiler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | 	protected $stubFilename = 'IndexModule.js' ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | 	protected $stubResourceFilename = 'IndexModuleModel.js' ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | 	protected $stubResource  ; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 19 |  | View Code Duplication | 	public function __construct($scaffolderConfig, $modelData = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | 		$this->stubsDirectory = __DIR__ . '/../../../../stubs/AngularJs/'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | 		parent::__construct($scaffolderConfig, null); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  | 		$this->stubResource = File::get($this->stubsDirectory . $this->stubResourceFilename ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  | 	 * Replace and store the Stub. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  | 	public function replaceAndStore(){} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  | 	 * Compiles a resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  | 	 * @param      $hash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  | 	 * @param null $extra | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  | 	 * @return string | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  | 	public function compile($extra = null) {} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  | 	 * Compiles a group of routes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  | 	 * @param      $hash | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  | 	 * @param null $extra | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  | 	 * @return mixed | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 51 |  |  | 	 */ | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  | 	public function compileGroup($compiledIndexes) | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  | 	{ | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  | 		$this->replaceIndexes($compiledIndexes) | 
            
                                                                        
                            
            
                                    
            
            
                | 56 |  |  | 			->store(new FileToCompile(null, null)); | 
            
                                                                        
                            
            
                                    
            
            
                | 57 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 58 |  |  | 		return $this->stub; | 
            
                                                                        
                            
            
                                    
            
            
                | 59 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  | 	 * Get output filename | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  | 	 * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  | 	protected function getOutputFilename() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  | 		$folder = PathParser::parse($this->scaffolderConfig->generator->paths->index); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  | 		return $folder  . 'index.module.js'; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  | 	 * Replace the resource. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  | 	 * @param $this->modelName | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  | 	 * @return string routeStub | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  | 	public function replaceResource($modelData) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  | 		$indexStub = str_replace('{{table_name_uc}}', $modelData->modelName, $this->stubResource); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  | 		$indexStub = str_replace('{{table_name}}', $modelData->tableName, $indexStub); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  | 		 | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  | 		return $indexStub; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  | 	/** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  | 	 * Replace compiled routes. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  | 	 * @param $compiledRoutes | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  | 	 * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  | 	 * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  | 	 */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  | 	private function replaceIndexes($compiledIndexes) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  | 	{ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  | 		$this->stub = str_replace('{{tables}}', $compiledIndexes, $this->stub); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  | 		return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  | 	} | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |  | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 106 |  |  | 	 | 
            
                                                        
            
                                    
            
            
                | 107 |  |  | } | 
            
                        
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.