Conditions | 12 |
Paths | 12 |
Total Lines | 38 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
102 | private function parse(int $type, string $value): void |
||
103 | { |
||
104 | switch ($type) { |
||
105 | case AnnotationLexer::T_ANNOTATION: |
||
106 | $this->tokenConsumer->consumeAnnotationToken($value); |
||
107 | break; |
||
108 | case AnnotationLexer::T_O_PARENTHESIS: |
||
109 | $this->tokenConsumer->consumeOpeningParenthesisToken(); |
||
110 | $this->tokenConsumer->addTokenToContent($value); |
||
111 | break; |
||
112 | case AnnotationLexer::T_C_PARENTHESIS: |
||
113 | $this->tokenConsumer->addTokenToContent($value); |
||
114 | $this->tokenConsumer->consumeClosingParenthesisToken(); |
||
115 | break; |
||
116 | case AnnotationLexer::T_SINGLE_QUOTE: |
||
117 | case AnnotationLexer::T_DOUBLE_QUOTE: |
||
118 | $this->tokenConsumer->addTokenToContent($value); |
||
119 | $this->tokenConsumer->consumeQuoteToken($type); |
||
120 | break; |
||
121 | case AnnotationLexer::T_ASTERISK: |
||
122 | if ($this->tokenConsumer->hasOpenedString()) { |
||
123 | // We are in a string, save this token value. |
||
124 | $this->tokenConsumer->addTokenToContent($value); |
||
125 | } |
||
126 | break; |
||
127 | case AnnotationLexer::T_LINE_BREAK: |
||
128 | $this->tokenConsumer->addTokenToContent($value); |
||
129 | $this->tokenConsumer->increaseLine(); |
||
130 | break; |
||
131 | case AnnotationLexer::T_BACKSLASH: |
||
132 | case AnnotationLexer::T_WHITESPACE: |
||
133 | case AnnotationLexer::T_OTHER: |
||
134 | $this->tokenConsumer->addTokenToContent($value); |
||
135 | break; |
||
136 | default: |
||
137 | throw new AnnotationParseException(sprintf('A token of value "%s" has an invalid type', $value)); |
||
138 | } |
||
139 | $this->tokenConsumer->afterConsume($type); |
||
140 | } |
||
142 |