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 TemplatePathResolver extends AbstractPathResolver |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * @var UrlGenerator |
||
| 34 | */ |
||
| 35 | private $urlGenerator; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var bool |
||
| 39 | */ |
||
| 40 | private $checkPaths; |
||
| 41 | |||
| 42 | 23 | public function __construct(ResourceRepository $repo, UrlGenerator $urlGenerator = null, $checkPaths = false) |
|
| 43 | { |
||
| 44 | 23 | parent::__construct($repo); |
|
| 45 | |||
| 46 | 23 | $this->urlGenerator = $urlGenerator; |
|
| 47 | 23 | $this->checkPaths = $checkPaths; |
|
| 48 | 23 | } |
|
| 49 | |||
| 50 | /** |
||
| 51 | * Returns the priority for this visitor. |
||
| 52 | * |
||
| 53 | * Priority should be between -10 and 10 (0 is the default). |
||
| 54 | * |
||
| 55 | * @return int The priority level |
||
| 56 | */ |
||
| 57 | 23 | public function getPriority() |
|
| 61 | |||
| 62 | /** |
||
| 63 | * {@inheritdoc} |
||
| 64 | */ |
||
| 65 | 19 | protected function processNode(Twig_Node $node) |
|
| 85 | |||
| 86 | 19 | private function processModuleNode(Twig_Node_Module $node) |
|
| 87 | { |
||
| 88 | // Resolve relative parent template paths to absolute paths |
||
| 89 | 19 | $parentNode = $node->hasNode('parent') ? $node->getNode('parent') : null; |
|
| 90 | 19 | $traitsNode = $node->getNode('traits'); |
|
| 91 | |||
| 92 | // If the template extends another template, resolve the path |
||
| 93 | 19 | if ($parentNode instanceof Twig_Node_Expression_Constant) { |
|
| 94 | 5 | $this->processConstantNode($parentNode, $this->checkPaths); |
|
| 95 | } |
||
| 96 | |||
| 97 | // Resolve paths of embedded templates |
||
| 98 | 19 | foreach ($node->getAttribute('embedded_templates') as $embeddedNode) { |
|
| 99 | 2 | $this->processEmbeddedTemplateNode($embeddedNode); |
|
| 100 | } |
||
| 101 | |||
| 102 | // Resolve paths of used templates |
||
| 103 | 17 | foreach ($traitsNode as $traitNode) { |
|
| 104 | 2 | $this->processTraitNode($traitNode); |
|
| 105 | } |
||
| 106 | |||
| 107 | 17 | return null; |
|
| 108 | } |
||
| 109 | |||
| 110 | 2 | private function processEmbeddedTemplateNode(Twig_Node_Module $embeddedNode) |
|
| 111 | { |
||
| 112 | 2 | $embedParent = $embeddedNode->hasParent('parent') ? $embeddedNode->getNode('parent') : null; |
|
|
|
|||
| 113 | |||
| 114 | // If the template extends another template, resolve the path |
||
| 115 | if ($embedParent instanceof Twig_Node_Expression_Constant) { |
||
| 116 | $this->processConstantNode($embedParent, $this->checkPaths); |
||
| 117 | } |
||
| 118 | } |
||
| 119 | |||
| 120 | 2 | private function processTraitNode(Twig_Node $traitNode) |
|
| 129 | |||
| 130 | 6 | View Code Duplication | private function processIncludeNode(Twig_Node_Include $node) |
| 131 | { |
||
| 132 | 6 | $exprNode = $node->getNode('expr'); |
|
| 133 | |||
| 134 | 6 | if ($exprNode instanceof Twig_Node_Expression_Constant) { |
|
| 135 | 6 | $this->processConstantNode($exprNode, $this->checkPaths); |
|
| 136 | } |
||
| 137 | |||
| 138 | 6 | return null; |
|
| 139 | } |
||
| 140 | |||
| 141 | 2 | View Code Duplication | private function processImportNode(Twig_Node_Import $node) |
| 151 | |||
| 152 | 3 | protected function processResourceUrlFunction(Twig_Node $node) |
|
| 153 | { |
||
| 154 | 3 | if (!$this->urlGenerator) { |
|
| 182 | |||
| 183 | 16 | private function processConstantNode(Twig_Node_Expression_Constant $node, $checkPath) |
|
| 187 | } |
||
| 188 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.