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 |
||
| 11 | final class AccessTokenFactory |
||
| 12 | { |
||
| 13 | const API_ACCESS_TOKEN_REQUEST_URL = 'https://oauth.izettle.net/token'; |
||
| 14 | const API_ACCESS_TOKEN_PASSWORD_GRANT = 'password'; |
||
| 15 | const API_ACCESS_TOKEN_REFRESH_TOKEN_URL = 'https://oauth.izettle.net/token'; |
||
| 16 | const API_ACCESS_TOKEN_REFRESH_TOKEN_GRANT = 'refresh_token'; |
||
| 17 | |||
| 18 | private $guzzleClient; |
||
| 19 | private $clientId; |
||
| 20 | private $clientSecret; |
||
| 21 | |||
| 22 | 2 | public function __construct(GuzzleClient $guzzleClient, string $clientId, string $clientSecret) |
|
| 28 | |||
| 29 | 1 | View Code Duplication | public function getFromUserLogin(string $username, string $password): AccessToken |
| 43 | |||
| 44 | 1 | View Code Duplication | public function refresh(AccessToken $accessToken): AccessToken |
| 57 | |||
| 58 | 2 | private function makeRequest($url, $options): array |
|
| 68 | |||
| 69 | 2 | private function getAccessTokenFromData(array $data): AccessToken |
|
| 77 | } |
||
| 78 |