Conditions | 13 |
Paths | 12 |
Total Lines | 65 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
35 | protected function parseValueLiteral(LexerInterface $lexer, bool $isConst): array |
||
36 | { |
||
37 | $token = $lexer->getToken(); |
||
38 | |||
39 | switch ($token->getKind()) { |
||
40 | case TokenKindEnum::BRACKET_L: |
||
41 | return $this->parseList($lexer, $isConst); |
||
42 | case TokenKindEnum::BRACE_L: |
||
43 | return $this->parseObject($lexer, $isConst); |
||
44 | case TokenKindEnum::INT: |
||
45 | $lexer->advance(); |
||
46 | |||
47 | return [ |
||
48 | 'kind' => NodeKindEnum::INT, |
||
49 | 'value' => $token->getValue(), |
||
50 | 'loc' => $this->buildLocation($lexer, $token), |
||
51 | ]; |
||
52 | case TokenKindEnum::FLOAT: |
||
53 | $lexer->advance(); |
||
54 | |||
55 | return [ |
||
56 | 'kind' => NodeKindEnum::FLOAT, |
||
57 | 'value' => $token->getValue(), |
||
58 | 'loc' => $this->buildLocation($lexer, $token), |
||
59 | ]; |
||
60 | case TokenKindEnum::STRING: |
||
61 | case TokenKindEnum::BLOCK_STRING: |
||
62 | return $this->buildAST(ASTKindEnum::STRING_LITERAL, $lexer); |
||
|
|||
63 | case TokenKindEnum::NAME: |
||
64 | $value = $token->getValue(); |
||
65 | |||
66 | if ($value === 'true' || $value === 'false') { |
||
67 | $lexer->advance(); |
||
68 | |||
69 | return [ |
||
70 | 'kind' => NodeKindEnum::BOOLEAN, |
||
71 | 'value' => $value === 'true', |
||
72 | 'loc' => $this->buildLocation($lexer, $token), |
||
73 | ]; |
||
74 | } |
||
75 | |||
76 | if ($value === 'null') { |
||
77 | $lexer->advance(); |
||
78 | |||
79 | return [ |
||
80 | 'kind' => NodeKindEnum::NULL, |
||
81 | 'loc' => $this->buildLocation($lexer, $token), |
||
82 | ]; |
||
83 | } |
||
84 | |||
85 | $lexer->advance(); |
||
86 | |||
87 | return [ |
||
88 | 'kind' => NodeKindEnum::ENUM, |
||
89 | 'value' => $token->getValue(), |
||
90 | 'loc' => $this->buildLocation($lexer, $token), |
||
91 | ]; |
||
92 | case TokenKindEnum::DOLLAR: |
||
93 | if (!$isConst) { |
||
94 | return $this->buildAST(ASTKindEnum::VARIABLE, $lexer); |
||
95 | } |
||
96 | break; |
||
97 | } |
||
98 | |||
99 | throw $this->unexpected($lexer); |
||
100 | } |
||
193 |