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.
Test Failed
Pull Request — master (#23)
by
unknown
04:15
created

TwigSpreadsheetExtension   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 113
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 13

Test Coverage

Coverage 91.43%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 13
dl 0
loc 113
ccs 32
cts 35
cp 0.9143
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 8 1
A getTokenParsers() 0 15 1
A getNodeVisitors() 0 7 1
A mergeStyles() 0 7 3
A getCurrentColumn() 0 6 2
A getCurrentRow() 0 6 2
A getAttributes() 0 4 1
1
<?php
2
3
namespace MyWheels\TwigSpreadsheetBundle\Twig;
4
5
use MyWheels\TwigSpreadsheetBundle\Helper\Arrays;
6
use MyWheels\TwigSpreadsheetBundle\Twig\NodeVisitor\MacroContextNodeVisitor;
7
use MyWheels\TwigSpreadsheetBundle\Twig\NodeVisitor\SyntaxCheckNodeVisitor;
8
use MyWheels\TwigSpreadsheetBundle\Twig\TokenParser\AlignmentTokenParser;
9
use MyWheels\TwigSpreadsheetBundle\Twig\TokenParser\CellTokenParser;
10
use MyWheels\TwigSpreadsheetBundle\Twig\TokenParser\DocumentTokenParser;
11
use MyWheels\TwigSpreadsheetBundle\Twig\TokenParser\DrawingTokenParser;
12
use MyWheels\TwigSpreadsheetBundle\Twig\TokenParser\HeaderFooterTokenParser;
13
use MyWheels\TwigSpreadsheetBundle\Twig\TokenParser\RowTokenParser;
14
use MyWheels\TwigSpreadsheetBundle\Twig\TokenParser\SheetTokenParser;
15
use MyWheels\TwigSpreadsheetBundle\Wrapper\HeaderFooterWrapper;
16
use MyWheels\TwigSpreadsheetBundle\Wrapper\PhpSpreadsheetWrapper;
17
18
19
/**
20
 * Class TwigSpreadsheetExtension.
21
 */
22
class TwigSpreadsheetExtension extends \Twig_Extension
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Extension has been deprecated with message: since Twig 2.7, use "Twig\Extension\AbstractExtension" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
23
{
24
    /**
25
     * @var array
26
     */
27
    private $attributes;
28
29
    /**
30
     * TwigSpreadsheetExtension constructor.
31
     *
32
     * @param array $attributes
33
     */
34 27
    public function __construct(array $attributes = [])
35
    {
36 27
        $this->attributes = $attributes;
37 27
    }
38
39
    /**
40
     * @return array
41
     */
42 3
    public function getAttributes(): array
43
    {
44 3
        return $this->attributes;
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50 8
    public function getFunctions()
51
    {
52
        return [
53 8
            new \Twig_SimpleFunction('xlsmergestyles', [$this, 'mergeStyles']),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
54 8
            new \Twig_SimpleFunction('xlscellindex', [$this, 'getCurrentColumn'], ['needs_context' => true]),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
55 8
            new \Twig_SimpleFunction('xlsrowindex', [$this, 'getCurrentRow'], ['needs_context' => true]),
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: since Twig 2.7, use "Twig\TwigFunction" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
56
        ];
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     *
62
     * @throws \InvalidArgumentException
63
     */
64 8
    public function getTokenParsers()
65
    {
66
        return [
67 8
            new AlignmentTokenParser([], HeaderFooterWrapper::ALIGNMENT_CENTER),
68 8
            new AlignmentTokenParser([], HeaderFooterWrapper::ALIGNMENT_LEFT),
69 8
            new AlignmentTokenParser([], HeaderFooterWrapper::ALIGNMENT_RIGHT),
70 8
            new CellTokenParser(),
71 8
            new DocumentTokenParser($this->attributes),
72 8
            new DrawingTokenParser(),
73 8
            new HeaderFooterTokenParser([], HeaderFooterWrapper::BASETYPE_FOOTER),
74 8
            new HeaderFooterTokenParser([], HeaderFooterWrapper::BASETYPE_HEADER),
75 8
            new RowTokenParser(),
76 8
            new SheetTokenParser(),
77
        ];
78
    }
79
80
    /**
81
     * {@inheritdoc}
82
     */
83 8
    public function getNodeVisitors()
84
    {
85
        return [
86 8
            new MacroContextNodeVisitor(),
87 8
            new SyntaxCheckNodeVisitor(),
88
        ];
89
    }
90
91
    /**
92
     * @param array $style1
93
     * @param array $style2
94
     *
95
     * @throws \Twig_Error_Runtime
96
     *
97
     * @return array
98
     */
99 2
    public function mergeStyles(array $style1, array $style2): array
100
    {
101 2
        if (!\is_array($style1) || !\is_array($style2)) {
102
            throw new \Twig_Error_Runtime('The xlsmergestyles function only works with arrays.');
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Error_Runtime has been deprecated with message: since Twig 2.7, use "Twig\Error\RuntimeError" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
103
        }
104 2
        return Arrays::mergeRecursive($style1, $style2);
105
    }
106
107
    /**
108
     * @param array $context
109
     *
110
     * @throws \Twig_Error_Runtime
111
     *
112
     * @return int|null
113
     */
114 4
    public function getCurrentColumn(array $context) {
115 4
        if (!isset($context[PhpSpreadsheetWrapper::INSTANCE_KEY])) {
116
            throw new \Twig_Error_Runtime('The PhpSpreadsheetWrapper instance is missing.');
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Error_Runtime has been deprecated with message: since Twig 2.7, use "Twig\Error\RuntimeError" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
117
        }
118 4
        return $context[PhpSpreadsheetWrapper::INSTANCE_KEY]->getCurrentColumn();
119
    }
120
121
    /**
122
     * @param array $context
123
     *
124
     * @throws \Twig_Error_Runtime
125
     *
126
     * @return int|null
127
     */
128 4
    public function getCurrentRow(array $context) {
129 4
        if (!isset($context[PhpSpreadsheetWrapper::INSTANCE_KEY])) {
130
            throw new \Twig_Error_Runtime('The PhpSpreadsheetWrapper instance is missing.');
0 ignored issues
show
Deprecated Code introduced by
The class Twig_Error_Runtime has been deprecated with message: since Twig 2.7, use "Twig\Error\RuntimeError" instead

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
131
        }
132 4
        return $context[PhpSpreadsheetWrapper::INSTANCE_KEY]->getCurrentRow();
133
    }
134
}
135