TokenMatcher::match()   D
last analyzed

Complexity

Conditions 19
Paths 8

Size

Total Lines 71
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 40
CRAP Score 19

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 19
eloc 49
c 2
b 0
f 0
nc 8
nop 2
dl 0
loc 71
ccs 40
cts 40
cp 1
crap 19
rs 4.5166

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
/**
4
 * JSON Pointer token matcher.
5
 *
6
 * Auto-generated file, please don't edit manually.
7
 * Generated by UniLex.
8
 */
9
10
declare(strict_types=1);
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
            // /
35
            $context
36 1
                ->setNewToken(TokenType::SLASH)
37 1
                ->setTokenAttribute('text', '/');
38
39 1
            return true;
40
        }
41 7
        if (0x7E == $char) {
42 1
            $context->getBuffer()->nextSymbol();
43
            // ~
44
            $context
45 1
                ->setNewToken(TokenType::TILDE)
46 1
                ->setTokenAttribute('text', '~');
47
48 1
            return true;
49
        }
50 6
        if (0x30 == $char) {
51 1
            $context->getBuffer()->nextSymbol();
52
            // 0
53
            $context
54 1
                ->setNewToken(TokenType::ZERO)
55 1
                ->setTokenAttribute('text', '0');
56
57 1
            return true;
58
        }
59 5
        if (0x31 == $char) {
60 1
            $context->getBuffer()->nextSymbol();
61
            // 1
62
            $context
63 1
                ->setNewToken(TokenType::ONE)
64 1
                ->setTokenAttribute('text', '1');
65
66 1
            return true;
67
        }
68 4
        if (0x00 <= $char && $char <= 0x2E || 0x32 <= $char && $char <= 0x7D || 0x7F <= $char && $char <= 0x10FFFF) {
69 3
            $context->getBuffer()->nextSymbol();
70 3
            goto state6;
71
        }
72 1
        goto error;
73
74
        state6:
75 3
        if ($context->getBuffer()->isEnd()) {
76 2
            goto finish6;
77
        }
78 2
        $char = $context->getBuffer()->getSymbol();
79 2
        if (0x00 <= $char && $char <= 0x2E || 0x32 <= $char && $char <= 0x7D || 0x7F <= $char && $char <= 0x10FFFF) {
80 2
            $context->getBuffer()->nextSymbol();
81 2
            goto state6;
82
        }
83
        finish6:
84
        // [^/~01]+
85
        $context
86 3
            ->setNewToken(TokenType::UNESCAPED)
87 3
            ->setTokenAttribute('text', $context->getSymbolString());
88
89 3
        return true;
90
91
        error:
92 2
        return false;
93
    }
94
}
95