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 |
||
15 | class iDokladTokenFactory |
||
16 | { |
||
17 | /** @var AccessTokenStorageInterface $storage */ |
||
18 | protected $storage; |
||
19 | |||
20 | /** |
||
21 | * @param AccessTokenStorageInterface $storage |
||
22 | */ |
||
23 | public function __construct(AccessTokenStorageInterface $storage = null) |
||
31 | |||
32 | /** |
||
33 | * @param Client $client |
||
34 | * @param array $config |
||
35 | * |
||
36 | * @throws \RuntimeException |
||
37 | * @throws InvalidTokenException |
||
38 | * |
||
39 | * @return AccessToken |
||
40 | */ |
||
41 | public function getToken(Client $client, array $config): AccessToken |
||
49 | |||
50 | /** |
||
51 | * @param Client $client |
||
52 | * @param array $config |
||
53 | * |
||
54 | * @throws \RuntimeException |
||
55 | * @throws InvalidTokenException |
||
56 | * |
||
57 | * @return AccessToken |
||
58 | */ |
||
59 | protected function createToken(Client $client, array $config): AccessToken |
||
74 | |||
75 | /** |
||
76 | * @param ResponseInterface $response |
||
77 | * @param \DateTime $requestedAt |
||
78 | * |
||
79 | * @throws \RuntimeException |
||
80 | * @throws InvalidTokenException |
||
81 | * |
||
82 | * @return AccessToken |
||
83 | */ |
||
84 | protected function extractToken(ResponseInterface $response, \DateTime $requestedAt): AccessToken |
||
112 | } |
||
113 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.