| Conditions | 13 |
| Paths | 13 |
| Total Lines | 73 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 declare(strict_types=1); |
||
| 45 | public function getNextToken(): ?TokenInterface |
||
| 46 | { |
||
| 47 | if (!$this->buffer) { |
||
| 48 | return null; |
||
| 49 | } |
||
| 50 | |||
| 51 | // Match a tag pair: |
||
| 52 | if (preg_match('/^\s*\[(.+?)(\s+"(.+?)")?\]/s', $this->buffer, $matches) !== 0) { |
||
| 53 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 54 | return new TagPair($matches[1], $matches[3]); |
||
| 55 | } |
||
| 56 | |||
| 57 | // Match a null move |
||
| 58 | if (preg_match('/^\s*--\s*/', $this->buffer, $matches)) { |
||
| 59 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 60 | return new NullMove(); |
||
| 61 | } |
||
| 62 | |||
| 63 | // Match a null move |
||
| 64 | if (preg_match('/^\s*Z0\s*/', $this->buffer, $matches)) { |
||
| 65 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 66 | return new NullMove(); |
||
| 67 | } |
||
| 68 | |||
| 69 | // Match an end result: |
||
| 70 | if (preg_match('/^\s*(\*|1-0|0-1|1\/2-1\/2)\s*/', $this->buffer, $matches)) { |
||
| 71 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 72 | return new EndResult($matches[1]); |
||
| 73 | } |
||
| 74 | |||
| 75 | // Match a move number: |
||
| 76 | if (preg_match('/^\s*([0-9]+)\.+\s*/', $this->buffer, $matches)) { |
||
| 77 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 78 | return new MoveNumber((int)$matches[1]); |
||
| 79 | } |
||
| 80 | |||
| 81 | // Match a SAN (castling): |
||
| 82 | if (preg_match('/^\s*(O-O(?:-O)?[\+\-\!\#\=\?]*)\s*/s', $this->buffer, $matches)) { |
||
| 83 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 84 | return new StandardAlgebraicNotation(new Notation($matches[1])); |
||
| 85 | } |
||
| 86 | |||
| 87 | // Match a SAN (castling): |
||
| 88 | if (preg_match('/^\s*(0-0(?:-0)?[\+\-\!\#\=\?]*)\s*/s', $this->buffer, $matches)) { |
||
| 89 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 90 | return new StandardAlgebraicNotation(new Notation($matches[1])); |
||
| 91 | } |
||
| 92 | |||
| 93 | // Match a SAN: |
||
| 94 | if (preg_match('/^\s*([a-zA-Z][a-zA-Z0-9\+\-\!\#\=\?]+)\s*/s', $this->buffer, $matches)) { |
||
| 95 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 96 | return new StandardAlgebraicNotation(new Notation($matches[1])); |
||
| 97 | } |
||
| 98 | |||
| 99 | // Match a comment: |
||
| 100 | if (preg_match('/^\s*\{(.*?)\}\s*/s', $this->buffer, $matches)) { |
||
| 101 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 102 | return new Comment($matches[1]); |
||
| 103 | } |
||
| 104 | |||
| 105 | // Match a Recursive Annotation Variation: |
||
| 106 | if (preg_match('/^\s*[\(|\)]/s', $this->buffer, $matches)) { |
||
| 107 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 108 | return new RecursiveAnnotationVariation(trim($matches[0]) === '('); |
||
| 109 | } |
||
| 110 | |||
| 111 | // Match a Numeric Annotation Glyph |
||
| 112 | if (preg_match('/^\s*\$([0-9]+)\s*/', $this->buffer, $matches)) { |
||
| 113 | $this->buffer = substr($this->buffer, strlen($matches[0])); |
||
| 114 | return new NumericAnnotationGlyph((int)trim($matches[1])); |
||
| 115 | } |
||
| 116 | |||
| 117 | throw InvalidTokenException::createForBuffer($this->buffer); |
||
| 118 | } |
||
| 137 |