| Conditions | 13 |
| Paths | 48 |
| Total Lines | 61 |
| Lines | 12 |
| Ratio | 19.67 % |
| 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 |
||
| 17 | public function parse($localPart) : Result |
||
| 18 | { |
||
| 19 | $parseDQuote = true; |
||
|
|
|||
| 20 | $closingQuote = false; |
||
| 21 | $openedParenthesis = 0; |
||
| 22 | $totalLength = 0; |
||
| 23 | |||
| 24 | while ($this->lexer->token['type'] !== EmailLexer::S_AT && null !== $this->lexer->token['type']) { |
||
| 25 | if ($this->hasDotAtStart()) { |
||
| 26 | return new InvalidEmail(new DotAtStart(), $this->lexer->token['value']); |
||
| 27 | } |
||
| 28 | |||
| 29 | //if ($parseDQuote) { |
||
| 30 | if ($this->lexer->token['type'] === EmailLexer::S_DQUOTE) { |
||
| 31 | $dquoteParsingResult = $this->parseDoubleQuote(); |
||
| 32 | $parseDQuote = !$dquoteParsingResult->isValid(); |
||
| 33 | |||
| 34 | //Invalid double quote parsing |
||
| 35 | if($parseDQuote) { |
||
| 36 | return $dquoteParsingResult; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { |
||
| 41 | $this->parseComments(); |
||
| 42 | $openedParenthesis += $this->getOpenedParenthesis(); |
||
| 43 | } |
||
| 44 | |||
| 45 | View Code Duplication | if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) { |
|
| 46 | if ($openedParenthesis === 0) { |
||
| 47 | throw new UnopenedComment(); |
||
| 48 | } |
||
| 49 | |||
| 50 | $openedParenthesis--; |
||
| 51 | } |
||
| 52 | |||
| 53 | $this->checkConsecutiveDots(); |
||
| 54 | |||
| 55 | View Code Duplication | if ($this->lexer->token['type'] === EmailLexer::S_DOT && |
|
| 56 | $this->lexer->isNextToken(EmailLexer::S_AT) |
||
| 57 | ) { |
||
| 58 | throw new DotAtEnd(); |
||
| 59 | } |
||
| 60 | |||
| 61 | $this->warnEscaping(); |
||
| 62 | $this->isInvalidToken($this->lexer->token, $closingQuote); |
||
| 63 | |||
| 64 | if ($this->isFWS()) { |
||
| 65 | $this->parseFWS(); |
||
| 66 | } |
||
| 67 | |||
| 68 | $totalLength += strlen($this->lexer->token['value']); |
||
| 69 | $this->lexer->moveNext(); |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($totalLength > LocalTooLong::LOCAL_PART_LENGTH) { |
||
| 73 | $this->warnings[LocalTooLong::CODE] = new LocalTooLong(); |
||
| 74 | } |
||
| 75 | |||
| 76 | return new ValidEmail(); |
||
| 77 | } |
||
| 78 | |||
| 116 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.