Conditions | 1 |
Paths | 1 |
Total Lines | 57 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
Bugs | 1 | 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 |
||
37 | public function setupRules() |
||
38 | { |
||
39 | $this->rules->validator = new Validator(['!format.block.code', '!format.monospace', '!keyword.escape', '!operator']); |
||
40 | $this->rules->addMany([ |
||
41 | 'format.header' => [ |
||
42 | new Rule(new RegexMatcher('/^(#+.+?)$/m')), |
||
43 | new Rule(new RegexMatcher('/^(.+?)^(?:-+|=+)$/m')) |
||
44 | ], |
||
45 | 'format.italics' => new Rule( |
||
46 | new RegexMatcher('/(?:^|[^*_])(?P<italics>(?P<i>[*_])(?>[^*_\n]|(?:(?P<b>[*_]{2})(?>[^*_\n]|(?&italics))*?\g{b}))+\g{i})/'), [ |
||
47 | 'italics' => Token::NAME |
||
48 | ] |
||
49 | ), |
||
50 | 'format.emphasis' => new Rule( |
||
51 | new RegexMatcher('/(?P<bold>(?P<b>\*\*|__)(?>[^*_\n]|(?:(?P<i>[*_]{2})(?>[^*_\n]|(?&bold))*?\g{i}))+\g{b})/', [ |
||
52 | 'bold' => Token::NAME |
||
53 | ]) |
||
54 | ), |
||
55 | 'format.strike' => new Rule(new RegexMatcher('/(~~.+?~~)/')), |
||
56 | 'format.monospace' => new Rule(new RegexMatcher('/[^`](`[^`]+?`)/')), |
||
57 | |||
58 | 'operator.list.ordered' => new Rule(new RegexMatcher('/^\s*(\d+[.)])/m')), |
||
59 | 'operator.list.unordered' => new Rule(new RegexMatcher('/^\s*([-+*])/m'), [ |
||
60 | 'context' => ['none'], |
||
61 | 'priority' => 1 |
||
62 | ]), |
||
63 | |||
64 | 'string.quote' => new Rule(new RegexMatcher('/((?:^>.*?\n)+)/m')), |
||
65 | 'format.block.code' => new Rule( |
||
66 | new DelegateRegexMatcher( |
||
67 | '/^```(.*?)\r?\n(.*?)\r?\n^```/ms', |
||
68 | function($match, TokenFactoryInterface $factory) { |
||
69 | $lang = KeyLighter::get()->getLanguage($match[1][0]); |
||
70 | yield $factory->create(null, ['pos' => $match[0][1], 'length' => strlen($match[0][0])]); |
||
71 | yield $factory->create( |
||
72 | "language.{$lang->getIdentifier()}", [ |
||
73 | 'pos' => $match[2][1], |
||
74 | 'length' => strlen($match[2][0]), |
||
75 | 'postProcessed' => true, |
||
76 | 'inject' => $lang, |
||
77 | 'class' => LanguageToken::class, |
||
78 | 'language' => $this |
||
79 | ] |
||
80 | ); |
||
81 | } |
||
82 | ), [ |
||
83 | 'context' => Validator::everywhere(), |
||
84 | 'postProcess' => true, |
||
85 | 'priority' => 1000 |
||
86 | ] |
||
87 | ), |
||
88 | |||
89 | 'keyword.escape' => new Rule(new RegexMatcher('/(\\\.)/')), |
||
90 | |||
91 | 'operator.horizontal' => new Rule(new RegexMatcher('/^(-+)\s*$/m')), |
||
92 | ]); |
||
93 | } |
||
94 | |||
105 |