| Conditions | 12 |
| Paths | 22 |
| Total Lines | 29 |
| Code Lines | 22 |
| 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 |
||
| 23 | public function build(LexerInterface $lexer, array $params): ?array |
||
| 24 | { |
||
| 25 | // Many definitions begin with a description and require a lookahead. |
||
| 26 | $keywordToken = $this->peekDescription($lexer) ? $lexer->lookahead() : $lexer->getToken(); |
||
| 27 | |||
| 28 | if ($keywordToken->getKind() === TokenKindEnum::NAME) { |
||
| 29 | switch ($keywordToken->getValue()) { |
||
| 30 | case KeywordEnum::SCHEMA: |
||
| 31 | return $this->buildAST(ASTKindEnum::SCHEMA_DEFINITION, $lexer); |
||
| 32 | case KeywordEnum::SCALAR: |
||
| 33 | return $this->buildAST(ASTKindEnum::SCALAR_TYPE_DEFINITION, $lexer); |
||
| 34 | case KeywordEnum::TYPE: |
||
| 35 | return $this->buildAST(ASTKindEnum::OBJECT_TYPE_DEFINITION, $lexer); |
||
| 36 | case KeywordEnum::INTERFACE: |
||
| 37 | return $this->buildAST(ASTKindEnum::INTERFACE_TYPE_DEFINITION, $lexer); |
||
| 38 | case KeywordEnum::UNION: |
||
| 39 | return $this->buildAST(ASTKindEnum::UNION_TYPE_DEFINITION, $lexer); |
||
| 40 | case KeywordEnum::ENUM: |
||
| 41 | return $this->buildAST(ASTKindEnum::ENUM_TYPE_DEFINITION, $lexer); |
||
| 42 | case KeywordEnum::INPUT: |
||
| 43 | return $this->buildAST(ASTKindEnum::INPUT_OBJECT_TYPE_DEFINITION, $lexer); |
||
| 44 | case KeywordEnum::EXTEND: |
||
| 45 | return $this->buildAST(ASTKindEnum::TYPE_SYSTEM_EXTENSION, $lexer); |
||
| 46 | case KeywordEnum::DIRECTIVE: |
||
| 47 | return $this->buildAST(ASTKindEnum::DIRECTIVE_DEFINITION, $lexer); |
||
| 48 | } |
||
| 49 | } |
||
| 50 | |||
| 51 | throw $this->unexpected($lexer, $keywordToken); |
||
| 52 | } |
||
| 54 |