Conditions | 11 |
Paths | 13 |
Total Lines | 47 |
Code Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
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 |
||
47 | public function dump(){ |
||
48 | |||
49 | if($this->options->type === QRCode::OUTPUT_STRING_JSON){ |
||
50 | return json_encode($this->matrix); |
||
51 | } |
||
52 | |||
53 | else if($this->options->type === QRCode::OUTPUT_STRING_TEXT){ |
||
54 | $text = ''; |
||
55 | |||
56 | foreach($this->matrix as $row){ |
||
57 | foreach($row as $col){ |
||
58 | $text .= $col |
||
59 | ? $this->options->textDark |
||
60 | : $this->options->textLight; |
||
61 | } |
||
62 | |||
63 | $text .= $this->options->textNewline; |
||
64 | } |
||
65 | |||
66 | return $text; |
||
67 | } |
||
68 | |||
69 | else if($this->options->type === QRCode::OUTPUT_STRING_HTML){ |
||
70 | $html = ''; |
||
71 | |||
72 | foreach($this->matrix as $row){ |
||
73 | // in order to not bloat the output too much, we use the shortest possible valid HTML tags |
||
74 | $html .= '<'.$this->options->htmlRowTag.'>'; |
||
75 | foreach($row as $col){ |
||
76 | $tag = $col |
||
77 | ? 'b' // dark |
||
78 | : 'i'; // light |
||
79 | |||
80 | $html .= '<'.$tag.'></'.$tag.'>'; |
||
81 | } |
||
82 | |||
83 | if(!(bool)$this->options->htmlOmitEndTag){ |
||
84 | $html .= '</'.$this->options->htmlRowTag.'>'; |
||
85 | } |
||
86 | |||
87 | $html .= PHP_EOL; |
||
88 | } |
||
89 | |||
90 | return $html; |
||
91 | } |
||
92 | |||
93 | } |
||
94 | |||
96 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.