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 |
||
| 32 | class CommandRepository |
||
| 33 | { |
||
| 34 | /** |
||
| 35 | * The Eloquent Model associated with the requested server. |
||
| 36 | * |
||
| 37 | * @var \Pterodactyl\Models\Server |
||
| 38 | */ |
||
| 39 | protected $server; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The Eloquent Model associated with the user to run the request as. |
||
| 43 | * |
||
| 44 | * @var \Pterodactyl\Models\User|null |
||
| 45 | */ |
||
| 46 | protected $user; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Constuctor for repository. |
||
| 50 | * |
||
| 51 | * @param \Pterodactyl\Models\Server $server |
||
| 52 | * @param \Pterodactyl\Models\User|null $user |
||
| 53 | * @return void |
||
|
|
|||
| 54 | */ |
||
| 55 | public function __construct(Server $server, User $user = null) |
||
| 60 | |||
| 61 | /** |
||
| 62 | * Sends a command to the daemon. |
||
| 63 | * |
||
| 64 | * @param string $command |
||
| 65 | * @return string |
||
| 66 | * |
||
| 67 | * @throws \Pterodactyl\Exceptions\DisplayException |
||
| 68 | * @throws \GuzzleHttp\Exception\RequestException |
||
| 69 | */ |
||
| 70 | View Code Duplication | public function send($command) |
|
| 91 | } |
||
| 92 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.