Conditions | 10 |
Paths | 11 |
Total Lines | 51 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
94 | private function replaceRecursively($placeholder, $replaced = array()) |
||
95 | { |
||
96 | // if the current placeholder was already replaced before, this is a cyclic dependecy |
||
97 | if (in_array($placeholder, $replaced)){ |
||
98 | $tree = implode('>', $replaced); |
||
99 | throw new Exception("Cyclic placeholder dependecy detected. Trying to replace $placeholder again when already replaced: $tree"); |
||
100 | } |
||
101 | |||
102 | $tags = $this->getScenarioTags(); |
||
103 | |||
104 | //@todo abort if there's no config tag |
||
105 | $configTag = PlaceholderUtils::getConfigTag($tags); |
||
106 | $configKey = PlaceholderUtils::getConfigKey($configTag); |
||
107 | |||
108 | $variantTags = PlaceholderUtils::filterVariantTags($tags, false); |
||
109 | $variant = end($variantTags); |
||
110 | $environment = $this->getEnvironment(); |
||
111 | |||
112 | $keys = array('$' . $variant, '$' . $environment, $placeholder); |
||
113 | |||
114 | // First try to find it in the runtime placeholders |
||
115 | $replacement = $this->recursiveReplacementSearch($keys, $this->runtimePlaceholders); |
||
116 | |||
117 | |||
118 | // Then look in the placeholder files |
||
119 | if ($replacement === null && $configTag !== false ) { |
||
120 | $section = PlaceholderUtils::getSectionKey($configTag); |
||
121 | $placeholders = $this->getSectionPlaceholders($configKey, $section); |
||
122 | $replacement = $this->recursiveReplacementSearch($keys, $placeholders); |
||
123 | } |
||
124 | |||
125 | if ($replacement === null && $configTag !== false){ |
||
126 | $configPath = $this->getFilePath($configKey); |
||
127 | $treePosition = "$configPath>$section>placeholders"; |
||
128 | throw new UndefinedPlaceholderException("No $placeholder replacement was defined on runtime or on $treePosition>$placeholder for variant $variant and environment $environment"); |
||
129 | } elseif ($replacement === null && $configTag === false) { |
||
130 | throw new UndefinedPlaceholderException("No $placeholder replacement was defined on runtime, and this scenario is not linked with any replacements file"); |
||
131 | } |
||
132 | |||
133 | //if the replaced string doesn't have placeholders itself, return it right away |
||
134 | if (preg_match_all(self::PLACEHOLDER_REGEX, $replacement, $matches, PREG_SET_ORDER) == 0) { |
||
135 | return $replacement; |
||
136 | } |
||
137 | |||
138 | //if it does have, replace them before returning |
||
139 | foreach ($matches as $match) { |
||
140 | $replaced[] = $placeholder; |
||
141 | $replacement = str_replace('${' . $match['placeholder'] . '}', $this->replaceRecursively($match['placeholder'], $replaced), $replacement); |
||
142 | } |
||
143 | return $replacement; |
||
144 | } |
||
145 | |||
197 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.