GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

MacroCallCompiler::compile()   C
last analyzed

Complexity

Conditions 7
Paths 9

Size

Total Lines 51
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 51
rs 6.9743
cc 7
eloc 34
nc 9
nop 2

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace TwigJs\Compiler\Expression;
4
5
use TwigJs\JsCompiler;
6
use TwigJs\TypeCompilerInterface;
7
8
class MacroCallCompiler implements TypeCompilerInterface
9
{
10
    public function getType()
11
    {
12
        return 'Twig_Node_Expression_MacroCall';
13
    }
14
15
    public function compile(JsCompiler $compiler, \Twig_NodeInterface $node)
16
    {
17
        if (! $node instanceof \Twig_Node_Expression_MacroCall) {
0 ignored issues
show
Bug introduced by
The class Twig_Node_Expression_MacroCall does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to 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 require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
18
            throw new \LogicException(sprintf('This compiler does not support the type "%s".', get_class($node)));
19
        }
20
21
        $argsNode = $node->getNode('arguments');
22
        if (! $argsNode instanceof \Twig_Node_Expression_Array) {
23
            throw new \LogicException('Did not find args node.');
24
        }
25
26
        $namedNames = array();
27
        $namedCount = 0;
28
        $positionalCount = 0;
29
        foreach ($argsNode->getKeyValuePairs() as $pair) {
30
            $name = $pair['key']->getAttribute('value');
31
            if (!is_int($name)) {
32
                $namedCount++;
33
                $namedNames[$name] = 1;
34
            } elseif ($namedCount > 0) {
35
                throw new \Twig_Error_Syntax(
36
                    sprintf(
37
                        'Positional arguments cannot be used after named arguments for macro "%s".',
38
                        $node->getAttribute('name')
39
                    ),
40
                    $node->getLine()
41
                );
42
            } else {
43
                $positionalCount++;
44
            }
45
        }
46
47
        $compiler
48
            ->raw('this.callMacro(')
49
            ->subcompile($node->getNode('template'))
50
            ->raw(', ')->repr($node->getAttribute('name'))
51
            ->raw(', ')->subcompile($argsNode)
52
        ;
53
54
        if ($namedCount > 0) {
55
            $compiler
56
                ->raw(', ')->repr($namedNames)
57
                ->raw(', ')->repr($namedCount)
58
                ->raw(', ')->repr($positionalCount)
59
            ;
60
        }
61
62
        $compiler
63
            ->raw(')')
64
        ;
65
    }
66
}
67