| Conditions | 9 |
| Paths | 21 |
| Total Lines | 72 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 89 | public function __construct(string $markup, Parser $parser) |
||
| 90 | { |
||
| 91 | $this->markup = $markup; |
||
| 92 | $this->parser = $parser; |
||
| 93 | |||
| 94 | $filterSeparatorRegex = '/' |
||
| 95 | . Token::FILTER_SEPARATOR |
||
| 96 | . '\s*(.*)/m'; |
||
| 97 | $syntaxRegex = '/(' |
||
| 98 | . Token::QUOTED_FRAGMENT |
||
| 99 | . ')(.*)/m'; |
||
| 100 | $filterRegex = '/(?:\s+|' |
||
| 101 | . Token::QUOTED_FRAGMENT |
||
| 102 | . '|' |
||
| 103 | . Token::FILTER_METHOD_ARGS_SEPARATOR |
||
| 104 | . ')+/'; |
||
| 105 | $filterArgumentsRegex = '/(?:' |
||
| 106 | . Token::FILTER_NAME_ARG_SEPARATOR |
||
| 107 | . '|' |
||
| 108 | . Token::FILTER_METHOD_ARGS_SEPARATOR |
||
| 109 | . ')\s*((?:\w+\s*\:\s*)?' |
||
| 110 | . Token::QUOTED_FRAGMENT |
||
| 111 | . ')/'; |
||
| 112 | |||
| 113 | $lexerFilterSeparator = new Lexer($filterSeparatorRegex); |
||
| 114 | $lexerSyntax = new Lexer($syntaxRegex); |
||
| 115 | $lexerFilter = new Lexer($filterRegex); |
||
| 116 | $lexerFilterArguments = new Lexer($filterArgumentsRegex); |
||
| 117 | |||
| 118 | $this->filters = []; |
||
| 119 | if ($lexerSyntax->match($markup)) { |
||
| 120 | $nameMarkup = $lexerSyntax->getStringMatch(1); |
||
| 121 | $this->name = $nameMarkup; |
||
| 122 | $filterMarkup = $lexerSyntax->getStringMatch(2); |
||
| 123 | |||
| 124 | if ($lexerFilterSeparator->match($filterMarkup)) { |
||
| 125 | $lexerFilter->matchAll($lexerFilterSeparator->getStringMatch(1)); |
||
| 126 | |||
| 127 | foreach ($lexerFilter->getArrayMatch(0) as $filter) { |
||
| 128 | $filter = trim($filter); |
||
| 129 | $matches = []; |
||
| 130 | if (preg_match('/\w+/', $filter, $matches)) { |
||
| 131 | $filterName = $matches[0]; |
||
| 132 | $lexerFilterArguments->matchAll($filter); |
||
| 133 | |||
| 134 | $matches = Helper::arrayFlatten($lexerFilterArguments->getArrayMatch(1)); |
||
| 135 | $this->filters[] = $this->parseFilterExpressions($filterName, $matches); |
||
| 136 | } |
||
| 137 | } |
||
| 138 | } |
||
| 139 | } |
||
| 140 | |||
| 141 | if ($this->parser->getConfig()->get('auto_escape')) { |
||
| 142 | // if auto_escape is enabled, and |
||
| 143 | // - there's no raw filter, and |
||
| 144 | // - no escape filter |
||
| 145 | // - no other standard html-adding filter |
||
| 146 | // then |
||
| 147 | // - add a mandatory escape filter |
||
| 148 | $addEscapeFilter = true; |
||
| 149 | |||
| 150 | foreach ($this->filters as $filter) { |
||
| 151 | // with empty filters set we would just move along |
||
| 152 | if (in_array($filter[0], ['escape', 'raw', 'nl2br', 'escape_once'])) { |
||
| 153 | // if we have any raw-like filter, stop |
||
| 154 | $addEscapeFilter = false; |
||
| 155 | break; |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($addEscapeFilter) { |
||
| 160 | $this->filters[] = ['escape', []]; |
||
| 161 | } |
||
| 250 |