@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | public function validate(array $context, $additional = []) { |
| 40 | - if(empty($this->_rules) && empty($additional)) { |
|
| 40 | + if (empty($this->_rules) && empty($additional)) { |
|
| 41 | 41 | return true; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -46,11 +46,11 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | public function setRules($rules) |
| 48 | 48 | { |
| 49 | - if(empty($rules)) { |
|
| 50 | - $this->_rules = [ 'none' => Validator::CONTEXT_IN_ONE_OF ]; |
|
| 49 | + if (empty($rules)) { |
|
| 50 | + $this->_rules = ['none' => Validator::CONTEXT_IN_ONE_OF]; |
|
| 51 | 51 | } else { |
| 52 | 52 | foreach ($rules as $key => $rule) { |
| 53 | - list($plain, $type) = $this->_parse($rule); |
|
| 53 | + list($plain, $type) = $this->_parse($rule); |
|
| 54 | 54 | $this->_rules[$plain] = $type; |
| 55 | 55 | } |
| 56 | 56 | } |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | private function _clean($rule, &$required) |
| 60 | 60 | { |
| 61 | 61 | if (strpos($rule, '.') !== false) { |
| 62 | - foreach (array_filter(array_keys($required), function ($key) use ($rule) { |
|
| 62 | + foreach (array_filter(array_keys($required), function($key) use ($rule) { |
|
| 63 | 63 | return fnmatch($key . '.*', $rule); |
| 64 | 64 | }) as $remove) { |
| 65 | 65 | unset($required[$remove]); |
@@ -68,11 +68,11 @@ discard block |
||
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | protected function _validate($context, $rules, $result = false) { |
| 71 | - if(empty($context)) { |
|
| 71 | + if (empty($context)) { |
|
| 72 | 72 | $context = ['none']; |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - while(list($rule, $type) = each($rules)) { |
|
| 75 | + while (list($rule, $type) = each($rules)) { |
|
| 76 | 76 | $matched = $this->_matches($context, $rule, $type); |
| 77 | 77 | |
| 78 | 78 | if ($type & Validator::CONTEXT_NOT_IN) { |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | $rule = substr($rule, $pos); |
| 127 | 127 | |
| 128 | - if($type & self::CONTEXT_REGEX) { |
|
| 128 | + if ($type & self::CONTEXT_REGEX) { |
|
| 129 | 129 | $rule = "/^$rule(\\.\\w+)?/i"; |
| 130 | 130 | } |
| 131 | 131 | |
@@ -133,22 +133,22 @@ discard block |
||
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | private function _matches($context, $rule, $type) { |
| 136 | - if($type & self::CONTEXT_EXACTLY) { |
|
| 136 | + if ($type & self::CONTEXT_EXACTLY) { |
|
| 137 | 137 | return in_array($rule, $context, true); |
| 138 | - } elseif($type & self::CONTEXT_REGEX) { |
|
| 139 | - foreach($context as $item) { |
|
| 140 | - if(preg_match($rule, $item)) { |
|
| 138 | + } elseif ($type & self::CONTEXT_REGEX) { |
|
| 139 | + foreach ($context as $item) { |
|
| 140 | + if (preg_match($rule, $item)) { |
|
| 141 | 141 | return true; |
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | return false; |
| 145 | 145 | } else { |
| 146 | - if(in_array($rule, $context, true)) { |
|
| 146 | + if (in_array($rule, $context, true)) { |
|
| 147 | 147 | return true; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | - foreach($context as $item) { |
|
| 151 | - if(fnmatch("$rule.*", $item)) { |
|
| 150 | + foreach ($context as $item) { |
|
| 151 | + if (fnmatch("$rule.*", $item)) { |
|
| 152 | 152 | return true; |
| 153 | 153 | } |
| 154 | 154 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | { |
| 161 | 161 | static $validator; |
| 162 | 162 | if (!$validator) { |
| 163 | - $validator = new DelegateValidator(function () { |
|
| 163 | + $validator = new DelegateValidator(function() { |
|
| 164 | 164 | return true; |
| 165 | 165 | }); |
| 166 | 166 | } |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | $this->_end->_valid = false; |
| 44 | 44 | } |
| 45 | 45 | } else { |
| 46 | - if (!$this->rule->validator->validate($context, [ $this->name => Validator::CONTEXT_IN ])) { |
|
| 46 | + if (!$this->rule->validator->validate($context, [$this->name => Validator::CONTEXT_IN])) { |
|
| 47 | 47 | $this->setValid(false); |
| 48 | 48 | } else { |
| 49 | 49 | $this->_valid = false; |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | |
| 46 | 46 | protected function processEnd(Context $context, Language $language, Result $result, TokenIterator $tokens) |
| 47 | 47 | { |
| 48 | - foreach(array_filter($context->stack, function ($name) { |
|
| 48 | + foreach (array_filter($context->stack, function($name) { |
|
| 49 | 49 | return in_array($name, $this->closes); |
| 50 | 50 | }) as $hash => $name) { |
| 51 | 51 | $end = new Token([$name, 'pos' => $this->pos]); |
@@ -197,13 +197,12 @@ discard block |
||
| 197 | 197 | * @return bool Return true to continue processing, false to return already processed tokens. |
| 198 | 198 | */ |
| 199 | 199 | public function process(Context $context, Language $language, Result $result, TokenIterator $tokens) { |
| 200 | - if(!$this->isValid($context)) { |
|
| 200 | + if (!$this->isValid($context)) { |
|
| 201 | 201 | return true; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | return $this->isStart() ? |
| 205 | - $this->processStart($context, $language, $result, $tokens) : |
|
| 206 | - $this->processEnd($context, $language, $result, $tokens); |
|
| 205 | + $this->processStart($context, $language, $result, $tokens) : $this->processEnd($context, $language, $result, $tokens); |
|
| 207 | 206 | } |
| 208 | 207 | |
| 209 | 208 | protected function processStart(Context $context, Language $language, Result $result, TokenIterator $tokens) { |
@@ -214,7 +213,7 @@ discard block |
||
| 214 | 213 | } |
| 215 | 214 | |
| 216 | 215 | protected function processEnd(Context $context, Language $language, Result $result, TokenIterator $tokens) { |
| 217 | - if($this->_start) { |
|
| 216 | + if ($this->_start) { |
|
| 218 | 217 | $context->pop($this->_start); |
| 219 | 218 | } else { |
| 220 | 219 | if (($start = $context->find($this->closedBy)) !== false) { |
@@ -244,11 +243,11 @@ discard block |
||
| 244 | 243 | return $multiplier; |
| 245 | 244 | } |
| 246 | 245 | } elseif (($rule = Helper::cmp($b->rule->priority, $a->rule->priority)) !== 0) { |
| 247 | - return $multiplier*$rule; |
|
| 246 | + return $multiplier * $rule; |
|
| 248 | 247 | } elseif (($rule = Helper::cmp($b->index, $a->index)) !== 0) { |
| 249 | - return $multiplier*$rule; |
|
| 248 | + return $multiplier * $rule; |
|
| 250 | 249 | } else { |
| 251 | - return $multiplier*($a->id < $b->id ? -1 : 1); |
|
| 250 | + return $multiplier * ($a->id < $b->id ? -1 : 1); |
|
| 252 | 251 | } |
| 253 | 252 | } |
| 254 | 253 | } |
@@ -30,7 +30,7 @@ |
||
| 30 | 30 | |
| 31 | 31 | public function find($needle) { |
| 32 | 32 | foreach (array_reverse($this->stack, true) as $id => $name) { |
| 33 | - if($name === $needle) { |
|
| 33 | + if ($name === $needle) { |
|
| 34 | 34 | return $id; |
| 35 | 35 | } |
| 36 | 36 | } |
@@ -28,7 +28,7 @@ |
||
| 28 | 28 | $this->_source = $source; |
| 29 | 29 | $this->_start = $start; |
| 30 | 30 | |
| 31 | - parent::__construct($start !== null ? [ $start->id => $start ] : [], 0, \ArrayIterator::class); |
|
| 31 | + parent::__construct($start !== null ? [$start->id => $start] : [], 0, \ArrayIterator::class); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | public function getSource() |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | public function styled($style, $text) |
| 34 | 34 | { |
| 35 | - return $this->open($style).$text.$this->close(); |
|
| 35 | + return $this->open($style) . $text . $this->close(); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function open($style) |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | { |
| 52 | 52 | $this->_current = empty($this->_stack) ? $this->_default : array_pop($this->_stack); |
| 53 | 53 | |
| 54 | - return "\033[0m".$this->_set(array_diff_assoc($this->_current, $this->_default)); |
|
| 54 | + return "\033[0m" . $this->_set(array_diff_assoc($this->_current, $this->_default)); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | private function _color($name, $bg = false) |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | private function _set($style) |
| 105 | 105 | { |
| 106 | - $escape = "\e[".implode(';', array_map(function ($style, $name) { |
|
| 106 | + $escape = "\e[" . implode(';', array_map(function($style, $name) { |
|
| 107 | 107 | return $this->_style($style, $name); |
| 108 | - }, array_keys($style), $style)).'m'; |
|
| 108 | + }, array_keys($style), $style)) . 'm'; |
|
| 109 | 109 | |
| 110 | - return $escape === "\e[m" ? null : "\033[0m".$escape; |
|
| 110 | + return $escape === "\e[m" ? null : "\033[0m" . $escape; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | public function reset() |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | $css = new Css(); |
| 34 | 34 | $js = new JavaScript(); |
| 35 | 35 | $this->rules->addMany([ |
| 36 | - 'language.'.$js->getIdentifier() => [ |
|
| 36 | + 'language.' . $js->getIdentifier() => [ |
|
| 37 | 37 | new OpenRule(new RegexMatcher('/<script.*?>()/'), [ |
| 38 | 38 | 'factory' => new TokenFactory(LanguageToken::class), |
| 39 | 39 | 'inject' => $js, |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | 'language' => $js |
| 46 | 46 | ]) |
| 47 | 47 | ], |
| 48 | - 'language.'.$css->getIdentifier() => [ |
|
| 48 | + 'language.' . $css->getIdentifier() => [ |
|
| 49 | 49 | new OpenRule(new RegexMatcher('/<style.*?>()/'), [ |
| 50 | 50 | 'factory' => new TokenFactory(LanguageToken::class), |
| 51 | 51 | 'inject' => $css, |