| Conditions | 7 |
| Paths | 5 |
| Total Lines | 51 |
| Code Lines | 29 |
| 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 |
||
| 60 | public function parse(InlineParserContext $inlineContext) |
||
| 61 | { |
||
| 62 | $cursor = $inlineContext->getCursor(); |
||
| 63 | |||
| 64 | $previous = $cursor->peek(-1); |
||
| 65 | if ($previous !== null && $previous !== ' ') { |
||
| 66 | return false; |
||
| 67 | } |
||
| 68 | |||
| 69 | $saved = $cursor->saveState(); |
||
| 70 | |||
| 71 | $cursor->advance(); |
||
| 72 | |||
| 73 | $handle = $cursor->match('/^[a-z0-9\+\-_]+:/'); |
||
| 74 | |||
| 75 | if (!$handle) { |
||
| 76 | $cursor->restoreState($saved); |
||
| 77 | |||
| 78 | return false; |
||
| 79 | } |
||
| 80 | |||
| 81 | $next = $cursor->peek(0); |
||
| 82 | |||
| 83 | if ($next !== null && $next !== ' ') { |
||
| 84 | $cursor->restoreState($saved); |
||
| 85 | |||
| 86 | return false; |
||
| 87 | } |
||
| 88 | |||
| 89 | $key = substr($handle, 0, -1); |
||
| 90 | |||
| 91 | if (!in_array($key, $this->map)) { |
||
| 92 | $cursor->restoreState($saved); |
||
| 93 | |||
| 94 | return false; |
||
| 95 | } |
||
| 96 | |||
| 97 | $fileName = $this->path . $key . $this->ext; |
||
| 98 | |||
| 99 | $inline = new Image($fileName, $key); |
||
| 100 | $inline->data['attributes'] = [ |
||
| 101 | 'class' => 'emoji', |
||
| 102 | 'data-emoji' => $key, |
||
| 103 | 'width' => '24', |
||
| 104 | 'height' => '24', |
||
| 105 | 'title' => ':' . $key . ':' |
||
| 106 | ]; |
||
| 107 | $inlineContext->getContainer()->appendChild($inline); |
||
| 108 | |||
| 109 | return true; |
||
| 110 | } |
||
| 111 | } |
||
| 112 |
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.