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 |
||
| 21 | class Swagger implements SourceInterface |
||
| 22 | { |
||
| 23 | /** @var string */ |
||
| 24 | private $prefix; |
||
| 25 | |||
| 26 | /** @var string */ |
||
| 27 | private $uri; |
||
| 28 | |||
| 29 | /** @var GuzzleAdapter */ |
||
| 30 | private $client; |
||
| 31 | |||
| 32 | /** @var DispersalStrategyInterface */ |
||
| 33 | private $strategy; |
||
| 34 | |||
| 35 | /** @var CacheProvider */ |
||
| 36 | private $cache; |
||
| 37 | |||
| 38 | /** @var string */ |
||
| 39 | private $cacheId; |
||
| 40 | |||
| 41 | /** @var array */ |
||
| 42 | private $options; |
||
| 43 | |||
| 44 | /** cache item lifetime */ |
||
| 45 | const CACHE_TTL = 86400; |
||
| 46 | |||
| 47 | /** cache namespace */ |
||
| 48 | const CACHE_NS = 'Graviton/ProxyBundle'; |
||
| 49 | |||
| 50 | |||
| 51 | /** |
||
| 52 | * Swagger constructor. |
||
| 53 | * |
||
| 54 | * @param GuzzleAdapter $client |
||
| 55 | * @param DispersalStrategyInterface $strategy |
||
| 56 | * @param CacheProvider $cache |
||
| 57 | * @param string $prefix Identifier of the source used in the path (serivce://3rdparty/{$prefix}/[...]) |
||
| 58 | * @param string $uri Url of the swagger file to be retrieved |
||
| 59 | * @param array $options |
||
| 60 | */ |
||
| 61 | public function __construct( |
||
| 77 | |||
| 78 | /** |
||
| 79 | * |
||
| 80 | * @param string $endpoint |
||
| 81 | * @param bool $withHost |
||
| 82 | * |
||
| 83 | * @return string |
||
| 84 | */ |
||
| 85 | public function buildUrl($endpoint, $withHost = false) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * @param CacheProvider $cache Used cache provider |
||
| 102 | * @param string $id Identifier for the cache item |
||
| 103 | */ |
||
| 104 | private function initCache(CacheProvider $cache, $id) |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @return ApiDefinition |
||
| 113 | */ |
||
| 114 | private function receiveSwaggerData() |
||
| 150 | } |
||
| 151 |