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