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 |
||
25 | class CacheManager extends CacheInvalidator |
||
26 | { |
||
27 | /** |
||
28 | * @var UrlGeneratorInterface |
||
29 | */ |
||
30 | private $urlGenerator; |
||
31 | |||
32 | /** |
||
33 | * What type of urls to generate. |
||
34 | * |
||
35 | * @var bool|string |
||
36 | */ |
||
37 | private $generateUrlType = UrlGeneratorInterface::ABSOLUTE_PATH; |
||
38 | |||
39 | /** |
||
40 | * Constructor |
||
41 | * |
||
42 | * @param ProxyClientInterface $cache HTTP cache proxy client |
||
43 | * @param UrlGeneratorInterface $urlGenerator Symfony route generator |
||
44 | */ |
||
45 | 11 | public function __construct(ProxyClientInterface $cache, UrlGeneratorInterface $urlGenerator) |
|
46 | { |
||
47 | 11 | parent::__construct($cache); |
|
48 | 11 | $this->urlGenerator = $urlGenerator; |
|
49 | 11 | } |
|
50 | |||
51 | /** |
||
52 | * Set what type of URLs to generate. |
||
53 | * |
||
54 | * @param bool|string $generateUrlType One of the constants in UrlGeneratorInterface |
||
55 | */ |
||
56 | 8 | public function setGenerateUrlType($generateUrlType) |
|
60 | |||
61 | /** |
||
62 | * Assign cache tags to a response |
||
63 | * |
||
64 | * @param Response $response |
||
65 | * @param array $tags |
||
66 | * @param bool $replace Whether to replace the current tags on the |
||
67 | * response |
||
68 | * |
||
69 | * @return $this |
||
70 | * |
||
71 | * @deprecated Add tags with TagHandler::addTags and then use TagHandler::tagResponse |
||
72 | */ |
||
73 | 1 | public function tagResponse(Response $response, array $tags, $replace = false) |
|
90 | |||
91 | /** |
||
92 | * Invalidate a route |
||
93 | * |
||
94 | * @param string $name Route name |
||
95 | * @param array $parameters Route parameters (optional) |
||
96 | * @param array $headers Extra HTTP headers to send to the caching proxy (optional) |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | 1 | public function invalidateRoute($name, array $parameters = array(), array $headers = array()) |
|
106 | |||
107 | /** |
||
108 | * Refresh a route |
||
109 | * |
||
110 | * @param string $route Route name |
||
111 | * @param array $parameters Route parameters (optional) |
||
112 | * @param array $headers Extra HTTP headers to send to the caching proxy (optional) |
||
113 | * |
||
114 | * @return $this |
||
115 | */ |
||
116 | 1 | public function refreshRoute($route, array $parameters = array(), array $headers = array()) |
|
122 | } |
||
123 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.