Conditions | 10 |
Paths | 25 |
Total Lines | 36 |
Code Lines | 19 |
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 |
||
68 | protected function parse(&$input, $offset, Context $context) |
||
69 | { |
||
70 | $this->build(); |
||
71 | |||
72 | $match = $this->parser->parse($input, $offset, $context); |
||
73 | |||
74 | $localResults = []; // this is redundant, but suppresses PHP scanner warnings |
||
75 | if ($match->match) { |
||
76 | $localResults = $match->results; |
||
77 | |||
78 | if (!empty($this->definition->validators)) { |
||
79 | $text = substr($input, $offset, $match->length); |
||
80 | |||
81 | foreach ($this->definition->validators as $validator) { |
||
82 | if (!($validator)($text, $localResults)) { |
||
83 | return $this->failure($input, $offset, $match->length); |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
89 | // Copy match into new match, only pass original callbacks if processor not set |
||
90 | $successes = empty($this->definition->processors) ? $match : []; |
||
91 | $match = ($match instanceof Success) |
||
92 | ? $this->success($input, $offset, $match->length, $successes) |
||
93 | : $this->failure($input, $offset, $match->length); |
||
94 | |||
95 | if ($match instanceof Success && !empty($this->definition->processors)) { |
||
96 | foreach ($this->definition->processors as $key => $processor) { |
||
97 | $match->addResultCallback(function (&$results) use ($key, $processor, $localResults) { |
||
98 | $results[$key] = $processor($localResults, $results); |
||
99 | }); |
||
100 | } |
||
101 | } |
||
102 | |||
103 | return $match; |
||
104 | } |
||
119 |