| Conditions | 20 |
| Paths | 2886 |
| Total Lines | 93 |
| Code Lines | 56 |
| 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 |
||
| 132 | protected function doIntegrationTest($file, $message, $condition, $templates, $exception, $outputs) |
||
| 133 | { |
||
| 134 | if (!$outputs) { |
||
| 135 | $this->markTestSkipped('no legacy tests to run'); |
||
| 136 | } |
||
| 137 | |||
| 138 | if ($condition) { |
||
| 139 | eval('$ret = '.$condition.';'); |
||
| 140 | if (!$ret) { |
||
| 141 | $this->markTestSkipped($condition); |
||
| 142 | } |
||
| 143 | } |
||
| 144 | |||
| 145 | $loader = new Twig_Loader_Array($templates); |
||
| 146 | |||
| 147 | foreach ($outputs as $i => $match) { |
||
| 148 | $config = array_merge(array( |
||
| 149 | 'cache' => false, |
||
| 150 | 'strict_variables' => true, |
||
| 151 | ), $match[2] ? eval($match[2].';') : array()); |
||
| 152 | $twig = new Twig_Environment($loader, $config); |
||
| 153 | $twig->addGlobal('global', 'global'); |
||
| 154 | foreach ($this->getRuntimeLoaders() as $runtimeLoader) { |
||
| 155 | $twig->addRuntimeLoader($runtimeLoader); |
||
| 156 | } |
||
| 157 | |||
| 158 | foreach ($this->getExtensions() as $extension) { |
||
| 159 | $twig->addExtension($extension); |
||
| 160 | } |
||
| 161 | |||
| 162 | foreach ($this->getTwigFilters() as $filter) { |
||
| 163 | $twig->addFilter($filter); |
||
| 164 | } |
||
| 165 | |||
| 166 | foreach ($this->getTwigTests() as $test) { |
||
| 167 | $twig->addTest($test); |
||
| 168 | } |
||
| 169 | |||
| 170 | foreach ($this->getTwigFunctions() as $function) { |
||
| 171 | $twig->addFunction($function); |
||
| 172 | } |
||
| 173 | |||
| 174 | // avoid using the same PHP class name for different cases |
||
| 175 | $p = new ReflectionProperty($twig, 'templateClassPrefix'); |
||
| 176 | $p->setAccessible(true); |
||
| 177 | $p->setValue($twig, '__TwigTemplate_'.hash('sha256', uniqid(mt_rand(), true), false).'_'); |
||
| 178 | |||
| 179 | try { |
||
| 180 | $template = $twig->loadTemplate('index.twig'); |
||
| 181 | } catch (Exception $e) { |
||
| 182 | if (false !== $exception) { |
||
| 183 | $message = $e->getMessage(); |
||
| 184 | $this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $message))); |
||
| 185 | $last = substr($message, strlen($message) - 1); |
||
| 186 | $this->assertTrue('.' === $last || '?' === $last, $message, 'Exception message must end with a dot or a question mark.'); |
||
| 187 | |||
| 188 | return; |
||
| 189 | } |
||
| 190 | |||
| 191 | throw new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); |
||
| 192 | } |
||
| 193 | |||
| 194 | try { |
||
| 195 | $output = trim($template->render(eval($match[1].';')), "\n "); |
||
| 196 | } catch (Exception $e) { |
||
| 197 | if (false !== $exception) { |
||
| 198 | $this->assertSame(trim($exception), trim(sprintf('%s: %s', get_class($e), $e->getMessage()))); |
||
| 199 | |||
| 200 | return; |
||
| 201 | } |
||
| 202 | |||
| 203 | $e = new Twig_Error(sprintf('%s: %s', get_class($e), $e->getMessage()), -1, $file, $e); |
||
| 204 | |||
| 205 | $output = trim(sprintf('%s: %s', get_class($e), $e->getMessage())); |
||
| 206 | } |
||
| 207 | |||
| 208 | if (false !== $exception) { |
||
| 209 | list($class) = explode(':', $exception); |
||
| 210 | $constraintClass = class_exists('PHPUnit\Framework\Constraint\Exception') ? 'PHPUnit\Framework\Constraint\Exception' : 'PHPUnit_Framework_Constraint_Exception'; |
||
| 211 | $this->assertThat(null, new $constraintClass($class)); |
||
| 212 | } |
||
| 213 | |||
| 214 | $expected = trim($match[3], "\n "); |
||
| 215 | |||
| 216 | if ($expected !== $output) { |
||
| 217 | printf("Compiled templates that failed on case %d:\n", $i + 1); |
||
| 218 | |||
| 219 | foreach (array_keys($templates) as $name) { |
||
| 220 | echo "Template: $name\n"; |
||
| 221 | echo $twig->compile($twig->parse($twig->tokenize($twig->getLoader()->getSourceContext($name)))); |
||
| 222 | } |
||
| 223 | } |
||
| 224 | $this->assertEquals($expected, $output, $message.' (in '.$file.')'); |
||
| 225 | } |
||
| 241 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths