Passed
Push — master ( 3a32e2...77143f )
by Edward
04:21
created

TokenMatcher::match()   D

Complexity

Conditions 26
Paths 10

Size

Total Lines 76
Code Lines 60

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 49
CRAP Score 26

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 26
eloc 60
c 1
b 0
f 0
nc 10
nop 2
dl 0
loc 76
ccs 49
cts 49
cp 1
crap 26
rs 4.1666

How to fix   Long Method    Complexity   

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
 * JSON Pointer token matcher.
4
 *
5
 * Auto-generated file, please don't edit manually.
6
 * Run following command to update this file:
7
 *     vendor/bin/phing json-pointer-matcher
8
 *
9
 * Phing version: 2.16.1
10
 */
11
12
namespace Remorhaz\JSON\Pointer;
13
14
use Remorhaz\JSON\Pointer\Parser\TokenType;
15
use Remorhaz\UniLex\IO\CharBufferInterface;
16
use Remorhaz\UniLex\Lexer\TokenFactoryInterface;
17
use Remorhaz\UniLex\Lexer\TokenMatcherTemplate;
18
19
class TokenMatcher extends TokenMatcherTemplate
20
{
21
22 9
    public function match(CharBufferInterface $buffer, TokenFactoryInterface $tokenFactory): bool
23
    {
24 9
        $context = $this->createContext($buffer, $tokenFactory);
25 9
        goto state1;
26
27
        state1:
28 9
        if ($context->getBuffer()->isEnd()) {
29 1
            goto error;
30
        }
31 8
        $char = $context->getBuffer()->getSymbol();
32 8
        if (0x2F == $char) {
33 1
            $context->getBuffer()->nextSymbol();
34
            $context
35 1
                ->setNewToken(TokenType::SLASH)
36 1
                ->setTokenAttribute('text', '/');
37 1
            return true;
38
        }
39 7
        if (0x7E == $char) {
40 1
            $context->getBuffer()->nextSymbol();
41
            $context
42 1
                ->setNewToken(TokenType::TILDE)
43 1
                ->setTokenAttribute('text', '~');
44 1
            return true;
45
        }
46 6
        if (0x30 == $char) {
47 1
            $context->getBuffer()->nextSymbol();
48
            $context
49 1
                ->setNewToken(TokenType::ZERO)
50 1
                ->setTokenAttribute('text', '0');
51 1
            return true;
52
        }
53 5
        if (0x31 == $char) {
54 1
            $context->getBuffer()->nextSymbol();
55
            $context
56 1
                ->setNewToken(TokenType::ONE)
57 1
                ->setTokenAttribute('text', '1');
58 1
            return true;
59
        }
60 4
        if (0x00 <= $char && $char <= 0x2E || 0x32 <= $char && $char <= 0x7D || 0x7F <= $char && $char <= 0x10FFFF) {
61 3
            $context->getBuffer()->nextSymbol();
62 3
            goto state6;
63
        }
64 1
        goto error;
65
66
        state6:
67 3
        if ($context->getBuffer()->isEnd()) {
68 1
            goto finish6;
69
        }
70 2
        $char = $context->getBuffer()->getSymbol();
71 2
        if (0x00 <= $char && $char <= 0x2E || 0x32 <= $char && $char <= 0x7D || 0x7F <= $char && $char <= 0x10FFFF) {
72 2
            $context->getBuffer()->nextSymbol();
73 2
            goto state7;
74
        }
75
        finish6:
76
        $context
77 1
            ->setNewToken(TokenType::UNESCAPED)
78 1
            ->setTokenAttribute('text', $context->getSymbolString());
79 1
        return true;
80
81
        state7:
82 2
        if ($context->getBuffer()->isEnd()) {
83 1
            goto finish7;
84
        }
85 1
        $char = $context->getBuffer()->getSymbol();
86 1
        if (0x00 <= $char && $char <= 0x2E || 0x32 <= $char && $char <= 0x7D || 0x7F <= $char && $char <= 0x10FFFF) {
87 1
            $context->getBuffer()->nextSymbol();
88 1
            goto state7;
89
        }
90
        finish7:
91
        $context
92 2
            ->setNewToken(TokenType::UNESCAPED)
93 2
            ->setTokenAttribute('text', $context->getSymbolString());
94 2
        return true;
95
96
        error:
97 2
        return false;
98
    }
99
}
100