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 |
||
28 | class PuliTemplateLoader implements Twig_LoaderInterface, Twig_ExistsLoaderInterface |
||
|
|||
29 | { |
||
30 | private $repo; |
||
31 | |||
32 | 26 | public function __construct(ResourceRepository $repo) |
|
36 | |||
37 | /** |
||
38 | * Gets the source code of a template, given its name. |
||
39 | * |
||
40 | * @param string $path The name of the template to load |
||
41 | * |
||
42 | * @return string The template source code |
||
43 | * |
||
44 | * @throws Twig_Error_Loader When $path is not found |
||
45 | */ |
||
46 | 20 | View Code Duplication | public function getSource($path) |
62 | |||
63 | /** |
||
64 | * Gets the cache key to use for the cache for a given template name. |
||
65 | * |
||
66 | * @param string $path The name of the template to load |
||
67 | * |
||
68 | * @return string The cache key |
||
69 | * |
||
70 | * @throws Twig_Error_Loader When $path is not found |
||
71 | */ |
||
72 | 19 | View Code Duplication | public function getCacheKey($path) |
90 | |||
91 | /** |
||
92 | * Returns true if the template is still fresh. |
||
93 | * |
||
94 | * @param string $path The template name |
||
95 | * @param int $time The last modification time of the cached template |
||
96 | * |
||
97 | * @return bool true if the template is fresh, false otherwise |
||
98 | * |
||
99 | * @throws Twig_Error_Loader When $path is not found |
||
100 | */ |
||
101 | 1 | View Code Duplication | public function isFresh($path, $time) |
102 | { |
||
103 | try { |
||
104 | 1 | return $this->getResource($path)->getMetadata()->getModificationTime() <= $time; |
|
105 | 1 | } catch (ResourceNotFoundException $e) { |
|
106 | 1 | throw new Twig_Error_Loader($e->getMessage(), -1, null, $e); |
|
107 | 1 | } catch (InvalidArgumentException $e) { |
|
108 | throw new Twig_Error_Loader($e->getMessage(), -1, null, $e); |
||
109 | } |
||
110 | } |
||
111 | |||
112 | /** |
||
113 | * Check if we have the source code of a template, given its name. |
||
114 | * |
||
115 | * @param string $name The name of the template to check if we can load |
||
116 | * |
||
117 | * @return bool If the template source code is handled by this loader or not |
||
118 | */ |
||
119 | 6 | public function exists($name) |
|
127 | |||
128 | 21 | private function getResource($path) |
|
146 | } |
||
147 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.