Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php  | 
            ||
| 17 | class RepositoryCommand extends Command  | 
            ||
| 18 | { | 
            ||
| 19 | /**  | 
            ||
| 20 | * The name of command.  | 
            ||
| 21 | *  | 
            ||
| 22 | * @var string  | 
            ||
| 23 | */  | 
            ||
| 24 | protected $name = 'starter:repository';  | 
            ||
| 25 | |||
| 26 | /**  | 
            ||
| 27 | * The description of command.  | 
            ||
| 28 | *  | 
            ||
| 29 | * @var string  | 
            ||
| 30 | */  | 
            ||
| 31 | protected $description = 'Create a new repository.';  | 
            ||
| 32 | |||
| 33 | /**  | 
            ||
| 34 | * The type of class being generated.  | 
            ||
| 35 | *  | 
            ||
| 36 | * @var string  | 
            ||
| 37 | */  | 
            ||
| 38 | protected $type = 'Repository';  | 
            ||
| 39 | |||
| 40 | /**  | 
            ||
| 41 | * @var Collection  | 
            ||
| 42 | */  | 
            ||
| 43 | protected $generators = null;  | 
            ||
| 44 | |||
| 45 | /**  | 
            ||
| 46 | * Execute the command.  | 
            ||
| 47 | *  | 
            ||
| 48 | * @return void  | 
            ||
| 49 | */  | 
            ||
| 50 | public function fire()  | 
            ||
| 51 |     { | 
            ||
| 52 | $this->generators = new Collection();  | 
            ||
| 53 | |||
| 54 | $this->generators->push(new MigrationGenerator([  | 
            ||
| 55 |             'name'   => 'create_'.snake_case(str_plural($this->argument('name'))).'_table', | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 56 |             'fields' => $this->option('fillable'), | 
            ||
| 57 |             'force'  => $this->option('force'), | 
            ||
| 58 | ]));  | 
            ||
| 59 | |||
| 60 | $modelGenerator = new ModelGenerator([  | 
            ||
| 61 |             'name'     => $this->argument('name'), | 
            ||
| 62 |             'fillable' => $this->option('fillable'), | 
            ||
| 63 |             'force'    => $this->option('force'), | 
            ||
| 64 | ]);  | 
            ||
| 65 | |||
| 66 | $this->generators->push($modelGenerator);  | 
            ||
| 67 | |||
| 68 | $this->generators->push(new SeederGenerator([  | 
            ||
| 69 |             'name'  => $this->argument('name'), | 
            ||
| 70 |             'force' => $this->option('force'), | 
            ||
| 71 | ]));  | 
            ||
| 72 | |||
| 73 | $this->generators->push(new RepositoryInterfaceGenerator([  | 
            ||
| 74 |             'name'  => $this->argument('name'), | 
            ||
| 75 |             'force' => $this->option('force'), | 
            ||
| 76 | ]));  | 
            ||
| 77 | |||
| 78 | //$this->generators->push(new CriteriaGenerator([  | 
            ||
| 79 |         //    'name'  => $this->argument('name'), | 
            ||
| 80 |         //    'force' => $this->option('force'), | 
            ||
| 81 | //]));  | 
            ||
| 82 | |||
| 83 |         foreach ($this->generators as $generator) { | 
            ||
| 84 | $generator->run();  | 
            ||
| 85 | }  | 
            ||
| 86 | |||
| 87 | $model = $modelGenerator->getRootNamespace().'\\'.$modelGenerator->getName();  | 
            ||
| 88 | $model = str_replace([  | 
            ||
| 89 | '\\',  | 
            ||
| 90 | '/',  | 
            ||
| 91 | ], '\\', $model);  | 
            ||
| 92 | |||
| 93 |         try { | 
            ||
| 94 | (new RepositoryEloquentGenerator([  | 
            ||
| 95 |                 'name'      => $this->argument('name'), | 
            ||
| 96 |                 'rules'     => $this->option('rules'), | 
            ||
| 97 |                 'validator' => $this->option('validator'), | 
            ||
| 98 |                 'presenter' => $this->option('presenter'), | 
            ||
| 99 |                 'force'     => $this->option('force'), | 
            ||
| 100 | 'model' => $model,  | 
            ||
| 101 | ]))->run();  | 
            ||
| 102 |             $this->info('Repository created successfully.'); | 
            ||
| 103 |         } catch (FileAlreadyExistsException $e) { | 
            ||
| 104 | $this->error($this->type.' already exists!');  | 
            ||
| 105 | |||
| 106 | return false;  | 
            ||
| 107 | }  | 
            ||
| 108 | }  | 
            ||
| 109 | |||
| 110 | /**  | 
            ||
| 111 | * The array of command arguments.  | 
            ||
| 112 | *  | 
            ||
| 113 | * @return array  | 
            ||
| 114 | */  | 
            ||
| 115 | public function getArguments()  | 
            ||
| 126 | |||
| 127 | /**  | 
            ||
| 128 | * The array of command options.  | 
            ||
| 129 | *  | 
            ||
| 130 | * @return array  | 
            ||
| 131 | */  | 
            ||
| 132 | View Code Duplication | public function getOptions()  | 
            |
| 172 | }  | 
            ||
| 173 | 
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.