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 |
||
| 47 | class MiniProgram |
||
| 48 | { |
||
| 49 | /** |
||
| 50 | * Access Token. |
||
| 51 | * |
||
| 52 | * @var \EasyWeChat\MiniProgram\AccessToken |
||
| 53 | */ |
||
| 54 | protected $accessToken; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Mini program config. |
||
| 58 | * |
||
| 59 | * @var array |
||
| 60 | */ |
||
| 61 | protected $config; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Guard. |
||
| 65 | * |
||
| 66 | * @var \EasyWeChat\MiniProgram\Server\Guard |
||
| 67 | */ |
||
| 68 | protected $server; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Components. |
||
| 72 | * |
||
| 73 | * @var array |
||
| 74 | */ |
||
| 75 | protected $components = [ |
||
| 76 | 'user' => User::class, |
||
| 77 | 'notice' => Notice::class, |
||
| 78 | 'staff' => Staff::class, |
||
| 79 | 'qrcode' => QRCode::class, |
||
| 80 | 'material_temporary' => Temporary::class, |
||
| 81 | ]; |
||
| 82 | |||
| 83 | /** |
||
| 84 | * MiniProgram constructor. |
||
| 85 | * |
||
| 86 | * @param \EasyWeChat\MiniProgram\Server\Guard $server |
||
| 87 | * @param \EasyWeChat\MiniProgram\AccessToken $accessToken |
||
| 88 | * @param array $config |
||
| 89 | */ |
||
| 90 | public function __construct($server, $accessToken, $config) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Magic get access. |
||
| 101 | * |
||
| 102 | * @param $name |
||
| 103 | * |
||
| 104 | * @return mixed |
||
| 105 | * |
||
| 106 | * @throws InvalidArgumentException |
||
| 107 | */ |
||
| 108 | View Code Duplication | public function __get($name) |
|
| 120 | } |
||
| 121 |