| Conditions | 1 |
| Paths | 1 |
| Total Lines | 77 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 10 | ||
| Bugs | 4 | 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 | parent::setupRules(); |
||
| 40 | |||
| 41 | $this->rules->validator = new Validator( |
||
| 42 | ['!format.block.code', '!format.monospace', '!operator.escape', '!operator', '!tag'] |
||
| 43 | ); |
||
| 44 | |||
| 45 | $this->rules->addMany([ |
||
| 46 | 'format.header' => [ |
||
| 47 | new Rule(new RegexMatcher('/^\s{0,3}(#+.+?)\r?$/m')), |
||
| 48 | new Rule(new RegexMatcher('/^([^\r\n]+?)^(?:-+|=+)\r?$/m')) |
||
| 49 | ], |
||
| 50 | 'format.italics' => new Rule( |
||
| 51 | new RegexMatcher('/(?:^|[^*_])(?P<italics>(?P<i>[*_])(?>[^*_\n]|(?:(?P<b>[*_]{2})(?>[^*_\n]|(?&italics))*?\g{b}))+\g{i})/'), [ |
||
| 52 | 'italics' => Token::NAME |
||
| 53 | ] |
||
| 54 | ), |
||
| 55 | 'format.bold' => new Rule( |
||
| 56 | new RegexMatcher('/(?P<bold>(?P<b>\*\*|__)(?>[^*_\n]|(?:(?P<i>[*_]{2})(?>[^*_\n]|(?&bold))*?\g{i}))+\g{b})/', [ |
||
| 57 | 'bold' => Token::NAME |
||
| 58 | ]) |
||
| 59 | ), |
||
| 60 | 'format.strike' => new Rule(new RegexMatcher('/(~~.+?~~)/')), |
||
| 61 | 'format.monospace' => [ |
||
| 62 | new Rule(new RegexMatcher('/(?:[^`]|^)(`.*?`)/')), |
||
| 63 | new Rule(new RegexMatcher('/(``.*?``)/')), |
||
| 64 | new Rule(new RegexMatcher('/^((?:(?: {4,}|\t).*?(?>\n|$)+?)+)/m')), |
||
| 65 | ], |
||
| 66 | |||
| 67 | 'operator.list.ordered' => new Rule(new RegexMatcher('/^\s*(\d+[.)])/m')), |
||
| 68 | 'operator.list.unordered' => new Rule(new RegexMatcher('/^\s*([-+*])/m'), [ |
||
| 69 | 'context' => ['none'], |
||
| 70 | 'priority' => 1 |
||
| 71 | ]), |
||
| 72 | |||
| 73 | 'string.quote' => new Rule(new RegexMatcher('/((?:^>.*?\n)+)/m')), |
||
| 74 | 'format.block.code' => [ |
||
| 75 | new Rule( |
||
| 76 | new DelegateRegexMatcher( |
||
| 77 | '/^```(.*?)\r?\n(.*?)\r?\n^```/ms', |
||
| 78 | function($match, TokenFactoryInterface $factory) { |
||
| 79 | $lang = KeyLighter::get()->getLanguage($match[1][0]); |
||
| 80 | yield $factory->create(Token::NAME, ['pos' => $match[0][1], 'length' => strlen($match[0][0])]); |
||
| 81 | yield $factory->create( |
||
| 82 | "language.{$lang->getIdentifier()}", [ |
||
| 83 | 'pos' => $match[2][1], |
||
| 84 | 'length' => strlen($match[2][0]), |
||
| 85 | 'inject' => $lang, |
||
| 86 | 'class' => LanguageToken::class, |
||
| 87 | ] |
||
| 88 | ); |
||
| 89 | } |
||
| 90 | ), [ |
||
| 91 | 'context' => Validator::everywhere(), |
||
| 92 | 'postProcess' => true, |
||
| 93 | 'priority' => 1000 |
||
| 94 | ] |
||
| 95 | ), |
||
| 96 | ], |
||
| 97 | |||
| 98 | 'operator.escape' => new Rule(new RegexMatcher('/(\\\.)/')), |
||
| 99 | |||
| 100 | 'operator.horizontal' => new Rule(new RegexMatcher('/^\s{,3}(([-*_])( ?\2)+)$/m'), [ |
||
| 101 | 'priority' => 2 |
||
| 102 | ]), |
||
| 103 | |||
| 104 | 'symbol.link' => new Rule(new RegexMatcher('/[^!](\[(?:[^\[\]]|!\[.*?\]\(.*?\))*\])/i')), |
||
| 105 | 'symbol.url' => new Rule(new RegexMatcher('#(<(https?://|[^/])[-A-Za-z0-9+&@\#/%?=~_|!:,.;]+[-A-Za-z0-9+&@\#/%=~_|]>|https?://[-A-Za-z0-9+&@\#/%?=~_|!:,.;]+[-A-Za-z0-9+&@\#/%=~_|])#i'), [ |
||
| 106 | 'priority' => 0, |
||
| 107 | ]), |
||
| 108 | 'symbol.image' => new Rule(new RegexMatcher('/(!)(\[.*?\])\(.*?\)/i', [ |
||
| 109 | 1 => 'operator.image', |
||
| 110 | 2 => '$.title', |
||
| 111 | ])), |
||
| 112 | ]); |
||
| 113 | } |
||
| 114 | |||
| 134 |