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 (#14)
by
unknown
03:38
created

TwigSpreadsheetExtension   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 12

Test Coverage

Coverage 78.56%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 12
dl 0
loc 93
ccs 22
cts 28
cp 0.7856
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getAttributes() 0 4 1
A getFunctions() 0 7 1
A getTokenParsers() 0 15 1
A getNodeVisitors() 0 7 1
A mergeStyles() 0 8 3
A getRowIndex() 0 3 1
1
<?php
2
3
namespace MewesK\TwigSpreadsheetBundle\Twig;
4
5
use MewesK\TwigSpreadsheetBundle\Twig\NodeVisitor\MacroContextNodeVisitor;
6
use MewesK\TwigSpreadsheetBundle\Twig\NodeVisitor\SyntaxCheckNodeVisitor;
7
use MewesK\TwigSpreadsheetBundle\Twig\TokenParser\AlignmentTokenParser;
8
use MewesK\TwigSpreadsheetBundle\Twig\TokenParser\CellTokenParser;
9
use MewesK\TwigSpreadsheetBundle\Twig\TokenParser\DocumentTokenParser;
10
use MewesK\TwigSpreadsheetBundle\Twig\TokenParser\DrawingTokenParser;
11
use MewesK\TwigSpreadsheetBundle\Twig\TokenParser\HeaderFooterTokenParser;
12
use MewesK\TwigSpreadsheetBundle\Twig\TokenParser\RowTokenParser;
13
use MewesK\TwigSpreadsheetBundle\Twig\TokenParser\SheetTokenParser;
14
use MewesK\TwigSpreadsheetBundle\Wrapper\HeaderFooterWrapper;
15
use MewesK\TwigSpreadsheetBundle\Wrapper\PhpSpreadsheetWrapper;
16
17
18
/**
19
 * Class TwigSpreadsheetExtension.
20
 */
21
class TwigSpreadsheetExtension extends \Twig_Extension
22
{
23
    /**
24
     * @var array
25
     */
26
    private $attributes;
27
28
    /**
29
     * TwigSpreadsheetExtension constructor.
30
     *
31
     * @param array $attributes
32
     */
33 26
    public function __construct(array $attributes = [])
34
    {
35 26
        $this->attributes = $attributes;
36 26
    }
37
38
    /**
39
     * @return array
40
     */
41 2
    public function getAttributes(): array
42
    {
43 2
        return $this->attributes;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 8
    public function getFunctions()
50
    {
51
        return [
52 8
            new \Twig_SimpleFunction('xlsmergestyles', [$this, 'mergeStyles']),
53 8
            new \Twig_SimpleFunction('xlsrowindex', [$this, 'getRowIndex'], ['needs_context' => true]),
54
        ];
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     *
60
     * @throws \InvalidArgumentException
61
     */
62 8
    public function getTokenParsers()
63
    {
64
        return [
65 8
            new AlignmentTokenParser([], HeaderFooterWrapper::ALIGNMENT_CENTER),
66 8
            new AlignmentTokenParser([], HeaderFooterWrapper::ALIGNMENT_LEFT),
67 8
            new AlignmentTokenParser([], HeaderFooterWrapper::ALIGNMENT_RIGHT),
68 8
            new CellTokenParser(),
69 8
            new DocumentTokenParser($this->attributes),
70 8
            new DrawingTokenParser(),
71 8
            new HeaderFooterTokenParser([], HeaderFooterWrapper::BASETYPE_FOOTER),
72 8
            new HeaderFooterTokenParser([], HeaderFooterWrapper::BASETYPE_HEADER),
73 8
            new RowTokenParser(),
74 8
            new SheetTokenParser(),
75
        ];
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 8
    public function getNodeVisitors()
82
    {
83
        return [
84 8
            new MacroContextNodeVisitor(),
85 8
            new SyntaxCheckNodeVisitor(),
86
        ];
87
    }
88
89
    /**
90
     * @param array $style1
91
     * @param array $style2
92
     *
93
     * @throws \Twig_Error_Runtime
94
     *
95
     * @return array
96
     */
97
    public function mergeStyles(array $style1, array $style2): array
98
    {
99
        if (!\is_array($style1) || !\is_array($style2)) {
100
            throw new \Twig_Error_Runtime('The xlsmergestyles function only works with arrays.');
101
        }
102
103
        return array_merge_recursive($style1, $style2);
104
    }
105
106
    /**
107
     * @param array $context
108
     * @return int|null
109
     */
110
    public function getRowIndex(array $context) {
111
        return $context[PhpSpreadsheetWrapper::INSTANCE_KEY]->getSheetRow();
112
    }
113
}
114