Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
Code Lines | 44 |
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 /** @noinspection PhpUndefinedFieldInspection */ |
||
32 | public function __construct($overwrites = []) |
||
33 | { |
||
34 | /* |
||
35 | * Support rules. |
||
36 | * These are not part of the published specification, but help make the published rules more manageable without |
||
37 | * altering meaning or syntax. They exist outside the named scope. |
||
38 | */ |
||
39 | $hexdigs = plus($this->HEXDIG); |
||
40 | $digits = plus($this->DIGIT); |
||
41 | $bits = plus($this->BIT); |
||
42 | $c_wsps = star($this->c_wsp); |
||
|
|||
43 | |||
44 | /* |
||
45 | * Normal rules |
||
46 | */ |
||
47 | $rules = [ |
||
48 | /* |
||
49 | * Core rules |
||
50 | */ |
||
51 | 'ALPHA' => set('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), |
||
52 | 'BIT' => set('01'), |
||
53 | 'CHAR' => range(0x01, 0x7F), |
||
54 | 'CR' => char("\r"), |
||
55 | 'CRLF' => text("\r\n"), |
||
56 | 'DIGIT' => set('0123456789'), |
||
57 | 'DQUOTE' => char('"'), |
||
58 | 'HEXDIG' => set('0123456789ABCDEF'), |
||
59 | 'HTAB' => char("\t"), |
||
60 | 'LF' => char("\n"), |
||
61 | 'LWSP' => regex("/(?:[ \t]|(?:\r\n[ \t]))*/"), |
||
62 | 'OCTET' => range(0x00, 0xFF), |
||
63 | 'SP' => char(' '), |
||
64 | 'VCHAR' => range(0x21, 0x7E), // ['!', '~'] |
||
65 | 'WSP' => set(" \t"), |
||
66 | |||
67 | /* |
||
68 | * Definition of ABNF syntax (in reverse order for performance) |
||
69 | */ |
||
70 | 'prose_val' => s('<', star(c(range(0x20, 0x3D), range(0x3F, 0x7E))), '>'), |
||
71 | 'hex_val' => s('x', $hexdigs, opt(c(plus(['.', $hexdigs]), ['-', $hexdigs]))), |
||
72 | 'dec_val' => s('d', $digits, opt(c(plus(['.', $digits]), ['-', $digits]))), |
||
73 | 'bin_val' => s('b', $bits, opt(c(plus(['.', $bits]), ['-', $bits]))), |
||
74 | 'num_val' => s('%', [$this->bin_val, $this->dec_val, $this->hex_val]), |
||
75 | 'char_val' => s($this->DQUOTE, star(c(range(0x20, 0x21), range(0x23, 0x7E))), $this->DQUOTE), |
||
76 | 'option' => s('[', $c_wsps, $this->alternation, $c_wsps, ']'), |
||
77 | 'group' => s('(', $c_wsps, $this->alternation, $c_wsps, ')'), |
||
78 | 'element' => c($this->rulename, $this->group, $this->option, $this->char_val, $this->num_val, |
||
79 | $this->prose_val), |
||
80 | 'repeat' => c($digits, [star($this->digit), '*', star($this->digit)]), |
||
81 | 'repetition' => s(opt($this->repeat), $this->element), |
||
82 | 'concatenation' => s($this->repetition, star([plus($this->c_wsp), $this->repetition])), |
||
83 | 'alternation' => s($this->concatenation, star([$c_wsps, '/', $c_wsps, $this->concatenation])), |
||
84 | 'comment' => s(';', star(c($this->WSP, $this->VCHAR)), $this->CRLF), |
||
85 | 'c_nl' => c($this->comment, $this->CRLF), |
||
86 | 'c_wsp' => c($this->WSP, [$this->c_nl, $this->WSP]), |
||
87 | 'elements' => [$this->alternation, $c_wsps], |
||
88 | 'defined_as' => [$c_wsps, ['=', '=/'], $c_wsps], |
||
89 | 'rulename' => s($this->ALPHA, star(c($this->ALPHA, $this->DIGIT, '-'))), |
||
90 | 'rule' => s($this->rulename, $this->defined_as, $this->elements, $this->c_nl), |
||
91 | 'rulelist' => plus(c($this->rule, [$c_wsps, $this->c_nl])), |
||
92 | |||
93 | self::DEFAULT => $this->rulelist, |
||
94 | ]; |
||
95 | |||
96 | parent::__construct(array_merge($rules, $overwrites)); |
||
97 | } |
||
98 | } |