Conditions | 10 |
Paths | 43 |
Total Lines | 39 |
Lines | 6 |
Ratio | 15.38 % |
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 |
||
20 | public function parse($str) |
||
21 | { |
||
22 | if ($this->lexer->token['type'] === EmailLexer::S_OPENPARENTHESIS) { |
||
23 | $this->MopenedParenthesis++; |
||
24 | if($this->noClosingParenthesis()) { |
||
25 | return new InvalidEmail(new UnclosedComment(), $this->lexer->token['value']); |
||
26 | } |
||
27 | } |
||
28 | |||
29 | View Code Duplication | if ($this->lexer->token['type'] === EmailLexer::S_CLOSEPARENTHESIS) { |
|
|
|||
30 | return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']); |
||
31 | } |
||
32 | |||
33 | $this->warnings[WarningComment::CODE] = new WarningComment(); |
||
34 | while (!$this->lexer->isNextToken(EmailLexer::S_AT)) {//!$this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) { |
||
35 | if ($this->lexer->isNextToken(EmailLexer::S_OPENPARENTHESIS)) { |
||
36 | $this->MopenedParenthesis++; |
||
37 | } |
||
38 | $this->warnEscaping(); |
||
39 | if($this->lexer->isNextToken(EmailLexer::S_CLOSEPARENTHESIS)) { |
||
40 | $this->MopenedParenthesis--; |
||
41 | } |
||
42 | $this->lexer->moveNext(); |
||
43 | } |
||
44 | |||
45 | if($this->MopenedParenthesis >= 1) { |
||
46 | return new InvalidEmail(new UnclosedComment(), $this->lexer->token['value']); |
||
47 | View Code Duplication | } else if ($this->MopenedParenthesis < 0) { |
|
48 | return new InvalidEmail(new UnOpenedComment(), $this->lexer->token['value']); |
||
49 | } |
||
50 | |||
51 | if (!$this->lexer->isNextToken(EmailLexer::S_AT)) { |
||
52 | return new InvalidEmail(new ExpectingATEXT('ATEX is not expected after closing comments'), $this->lexer->token['value']); |
||
53 | } |
||
54 | |||
55 | //You should always end at @ |
||
56 | $this->warnings[CFWSNearAt::CODE] = new CFWSNearAt(); |
||
57 | return new ValidEmail(); |
||
58 | } |
||
59 | |||
69 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.