| Conditions | 6 |
| Paths | 11 |
| Total Lines | 52 |
| Code Lines | 37 |
| 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 |
||
| 113 | private function extract($file, ZikulaTwigFileExtractor $extractor = null) |
||
| 114 | { |
||
| 115 | if (!is_file($file = __DIR__.'/Fixture/'.$file)) { |
||
| 116 | throw new RuntimeException(sprintf('The file "%s" does not exist.', $file)); |
||
| 117 | } |
||
| 118 | $kernel = $this |
||
| 119 | ->getMockBuilder('\Zikula\Bundle\CoreBundle\HttpKernel\ZikulaKernel') |
||
| 120 | ->disableOriginalConstructor() |
||
| 121 | ->getMock(); |
||
| 122 | $kernel |
||
| 123 | ->method('getBundle') |
||
| 124 | ->will($this->returnCallback(function ($bundleName) { |
||
| 125 | $bundle = $this |
||
| 126 | ->getMockBuilder('Zikula\Core\AbstractBundle') |
||
| 127 | ->disableOriginalConstructor() |
||
| 128 | ->getMock(); |
||
| 129 | $bundle |
||
| 130 | ->method('getTranslationDomain') |
||
| 131 | ->willReturn(strtolower($bundleName)); |
||
| 132 | |||
| 133 | return $bundle; |
||
| 134 | })); |
||
| 135 | |||
| 136 | $env = new \Twig_Environment(); |
||
| 137 | $env->addExtension(new SymfonyTranslationExtension($translator = new IdentityTranslator(new MessageSelector()))); |
||
| 138 | $env->addExtension(new TranslationExtension($translator, true)); |
||
| 139 | $env->addExtension(new RoutingExtension(new UrlGenerator(new RouteCollection(), new RequestContext()))); |
||
| 140 | $env->addExtension(new FormExtension(new TwigRenderer(new TwigRendererEngine()))); |
||
| 141 | $env->addExtension(new GettextExtension(new \Zikula\Common\Translator\IdentityTranslator(new MessageSelector()), $kernel)); |
||
| 142 | self::bootKernel(); |
||
| 143 | $env->addExtension(new CoreExtension(self::$kernel->getContainer())); |
||
| 144 | |||
| 145 | foreach ($env->getNodeVisitors() as $visitor) { |
||
| 146 | if ($visitor instanceof DefaultApplyingNodeVisitor) { |
||
|
1 ignored issue
–
show
|
|||
| 147 | $visitor->setEnabled(false); |
||
| 148 | } |
||
| 149 | if ($visitor instanceof RemovingNodeVisitor) { |
||
|
1 ignored issue
–
show
|
|||
| 150 | $visitor->setEnabled(false); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | if (null === $extractor) { |
||
| 155 | $extractor = new ZikulaTwigFileExtractor($env, $kernel); |
||
| 156 | } |
||
| 157 | |||
| 158 | $ast = $env->parse($env->tokenize(file_get_contents($file), $file)); |
||
| 159 | |||
| 160 | $catalogue = new MessageCatalogue(); |
||
| 161 | $extractor->visitTwigFile(new SplFileInfo($file, 'Fixture/', 'Fixture/' . basename($file)), $catalogue, $ast); |
||
| 162 | |||
| 163 | return $catalogue; |
||
| 164 | } |
||
| 165 | |||
| 171 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.jsonfile (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.jsonto be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
requireorrequire-devsection?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceofchecks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.