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 |
||
30 | class StemplerEngine extends AbstractEngine |
||
31 | { |
||
32 | use BenchmarkTrait; |
||
33 | |||
34 | /** |
||
35 | * Container is needed to provide proper scope isolation at moment of rendering. |
||
36 | * |
||
37 | * @var ContainerInterface |
||
38 | */ |
||
39 | protected $container; |
||
40 | |||
41 | /** |
||
42 | * @var StemplerCache |
||
43 | */ |
||
44 | protected $cache; |
||
45 | |||
46 | /** |
||
47 | * To be applied to view source before it's being loaded. |
||
48 | * |
||
49 | * @var array |
||
50 | */ |
||
51 | protected $modifiers = []; |
||
52 | |||
53 | /** |
||
54 | * To be applied to already compiled view source. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $processors = []; |
||
59 | |||
60 | /** |
||
61 | * @param EnvironmentInterface $environment |
||
62 | * @param LoaderInterface $loader |
||
63 | * @param FilesInterface $files |
||
64 | * @param ContainerInterface $container |
||
65 | * @param array $modifiers |
||
66 | * @param array $processors |
||
67 | */ |
||
68 | public function __construct( |
||
85 | |||
86 | /** |
||
87 | * {@inheritdoc} |
||
88 | */ |
||
89 | public function get(string $path): ViewInterface |
||
96 | |||
97 | /** |
||
98 | * {@inheritdoc} |
||
99 | * |
||
100 | * @return ViewSource Points to compiled view source. |
||
101 | */ |
||
102 | public function compile(string $path, bool $reset = false): ViewSource |
||
150 | |||
151 | /** |
||
152 | * {@inheritdoc} |
||
153 | * |
||
154 | * @return $this |
||
155 | */ |
||
156 | public function withEnvironment(EnvironmentInterface $environment): EngineInterface |
||
166 | |||
167 | /** |
||
168 | * Create new instance of supervisor. |
||
169 | * |
||
170 | * @return Supervisor |
||
171 | */ |
||
172 | protected function createSupervisor(): Supervisor |
||
177 | |||
178 | /** |
||
179 | * Run associated processors for post-processing. |
||
180 | * |
||
181 | * @param \Spiral\Views\ViewSource $source |
||
182 | * |
||
183 | * @return ViewSource |
||
184 | */ |
||
185 | protected function postProcess(ViewSource $source): ViewSource |
||
214 | |||
215 | /** |
||
216 | * In most of cases stempler will get view processors to be executed before composing, to run |
||
217 | * such processors we need special wrapper at top of environment. |
||
218 | * |
||
219 | * @return \Spiral\Stempler\LoaderInterface |
||
220 | */ |
||
221 | View Code Duplication | private function wrapLoader(): \Spiral\Stempler\LoaderInterface |
|
236 | } |
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.