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 |
||
| 14 | class CreateClientCommand extends Command |
||
| 15 | { |
||
| 16 | |||
| 17 | protected $signature = 'oauth2-server:create-client {--id=} {--secret=} {--name=} {--redirect_uri=} {--scope=*}'; |
||
| 18 | |||
| 19 | protected $description = 'Create new clients for your OAuth2 server'; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var ClientRepository |
||
| 23 | */ |
||
| 24 | protected $clients; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var ScopeRepository |
||
| 28 | */ |
||
| 29 | protected $scopes; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * CreateClientCommand constructor. |
||
| 33 | * @param ClientRepository $clients |
||
| 34 | * @param ScopeRepository $scopes |
||
| 35 | */ |
||
| 36 | 16 | public function __construct(ClientRepository $clients, ScopeRepository $scopes) |
|
| 43 | |||
| 44 | public function handle() |
||
| 45 | { |
||
| 46 | try { |
||
| 47 | $this->clients->forceCreate([ |
||
|
|
|||
| 48 | 'id' => (string) $this->getClientId(), |
||
| 49 | 'secret' => (string) $this->getClientSecret(), |
||
| 50 | 'name' => $this->option('name') ?: $this->ask('Please enter a name'), |
||
| 51 | 'redirect_uri' => $this->option('redirect_uri') |
||
| 52 | ])->scopes()->sync($this->option('scope')); |
||
| 53 | } catch (Exception $e) { |
||
| 54 | $this->error("An error occurred: {$e->getMessage()}"); |
||
| 55 | return 1; |
||
| 56 | } |
||
| 57 | |||
| 58 | $this->info('Client created succesfully'); |
||
| 59 | } |
||
| 60 | |||
| 61 | /** |
||
| 62 | * @return UuidInterface |
||
| 63 | */ |
||
| 64 | View Code Duplication | protected function getClientId() |
|
| 75 | |||
| 76 | /** |
||
| 77 | * @return UuidInterface |
||
| 78 | */ |
||
| 79 | View Code Duplication | protected function getClientSecret() |
|
| 90 | |||
| 91 | } |
||
| 92 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.