Passed
Push — master ( 852e13...6d4e0e )
by Edward
03:37
created

TokenMatcher::match()   B

Complexity

Conditions 10
Paths 10

Size

Total Lines 70
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 10
eloc 41
nc 10
nop 2
dl 0
loc 70
rs 7.6666
c 0
b 0
f 0

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
 * Brainfuck 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\UniLex\Example\Brainfuck\Grammar;
13
14
use Remorhaz\UniLex\IO\CharBufferInterface;
15
use Remorhaz\UniLex\Lexer\TokenFactoryInterface;
16
use Remorhaz\UniLex\Lexer\TokenMatcherTemplate;
17
18
class TokenMatcher extends TokenMatcherTemplate
19
{
20
21
    public function match(CharBufferInterface $buffer, TokenFactoryInterface $tokenFactory): bool
22
    {
23
        $context = $this->createContext($buffer, $tokenFactory);
24
        goto state1;
25
26
        state1:
27
        if ($context->getBuffer()->isEnd()) {
28
            goto error;
29
        }
30
        $char = $context->getBuffer()->getSymbol();
31
        if (0x3E == $char) {
32
            $context->getBuffer()->nextSymbol();
33
            // >
34
            $context->setNewToken(TokenType::NEXT);
35
36
            return true;
37
        }
38
        if (0x3C == $char) {
39
            $context->getBuffer()->nextSymbol();
40
            // <
41
            $context->setNewToken(TokenType::PREV);
42
43
            return true;
44
        }
45
        if (0x2B == $char) {
46
            $context->getBuffer()->nextSymbol();
47
            // \+
48
            $context->setNewToken(TokenType::INC);
49
50
            return true;
51
        }
52
        if (0x2D == $char) {
53
            $context->getBuffer()->nextSymbol();
54
            // -
55
            $context->setNewToken(TokenType::DEC);
56
57
            return true;
58
        }
59
        if (0x2E == $char) {
60
            $context->getBuffer()->nextSymbol();
61
            // \.
62
            $context->setNewToken(TokenType::OUTPUT);
63
64
            return true;
65
        }
66
        if (0x2C == $char) {
67
            $context->getBuffer()->nextSymbol();
68
            // ,
69
            $context->setNewToken(TokenType::INPUT);
70
71
            return true;
72
        }
73
        if (0x5B == $char) {
74
            $context->getBuffer()->nextSymbol();
75
            // \[
76
            $context->setNewToken(TokenType::LOOP);
77
78
            return true;
79
        }
80
        if (0x5D == $char) {
81
            $context->getBuffer()->nextSymbol();
82
            // ]
83
            $context->setNewToken(TokenType::END_LOOP);
84
85
            return true;
86
        }
87
        goto error;
88
89
        error:
90
        return false;
91
    }
92
}
93