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