@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | public function __construct(array $singleLine = null, array $multiLine = null) |
| 32 | 32 | { |
| 33 | 33 | $this->singleLine = $singleLine ?: []; |
| 34 | - $this->multiLine = $multiLine ?: []; |
|
| 34 | + $this->multiLine = $multiLine ?: []; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $all = []; |
| 50 | 50 | |
| 51 | 51 | foreach ($this->multiLine as $name => $comment) { |
| 52 | - $comment = array_map(function ($e) { return preg_quote($e, '/'); }, $comment); |
|
| 52 | + $comment = array_map(function($e) { return preg_quote($e, '/'); }, $comment); |
|
| 53 | 53 | |
| 54 | 54 | $all[] = [$name, "/{$comment[0]}(.*?){$comment[1]}/ms"]; |
| 55 | 55 | } |
@@ -25,7 +25,7 @@ |
||
| 25 | 25 | /** |
| 26 | 26 | * RegexMatcher constructor. |
| 27 | 27 | * |
| 28 | - * @param $regex |
|
| 28 | + * @param string $regex |
|
| 29 | 29 | * @param callable $callable |
| 30 | 30 | */ |
| 31 | 31 | public function __construct($regex, callable $callable) |
@@ -49,7 +49,7 @@ |
||
| 49 | 49 | |
| 50 | 50 | $callable = $this->callable; |
| 51 | 51 | foreach ($matches as $match) { |
| 52 | - foreach($callable($match, $factory) as $token) { |
|
| 52 | + foreach ($callable($match, $factory) as $token) { |
|
| 53 | 53 | yield $token; |
| 54 | 54 | } |
| 55 | 55 | } |
@@ -32,7 +32,7 @@ |
||
| 32 | 32 | { |
| 33 | 33 | public function __construct($name, $options = []) { |
| 34 | 34 | parent::__construct($name, $options); |
| 35 | - if(isset($options['inject'])) { |
|
| 35 | + if (isset($options['inject'])) { |
|
| 36 | 36 | $this->inject = $options['inject']; |
| 37 | 37 | } |
| 38 | 38 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * |
| 49 | 49 | * @return false|Token|null |
| 50 | 50 | */ |
| 51 | - public function create($name, $params = [ ]) |
|
| 51 | + public function create($name, $params = []) |
|
| 52 | 52 | { |
| 53 | 53 | if ($name !== null) { |
| 54 | 54 | $name = $this->getName($name); |
@@ -72,29 +72,29 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | private function link($name, $params) { |
| 75 | - if($this->_type & Token::START) { |
|
| 76 | - if(!isset($params['start'])) { |
|
| 75 | + if ($this->_type & Token::START) { |
|
| 76 | + if (!isset($params['start'])) { |
|
| 77 | 77 | $params['start'] = new $params['class']($name, $params); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - if($this->_type === Token::START) { |
|
| 80 | + if ($this->_type === Token::START) { |
|
| 81 | 81 | $params['start']->setEnd(false); |
| 82 | 82 | return $params['start']; |
| 83 | 83 | } |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - if($this->_type & Token::END) { |
|
| 86 | + if ($this->_type & Token::END) { |
|
| 87 | 87 | if (isset($params['length'])) { |
| 88 | 88 | $end = $params; |
| 89 | 89 | $end['pos'] += $params['length']; |
| 90 | 90 | |
| 91 | 91 | /** @var Token $end */ |
| 92 | 92 | $params['end'] = new $params['class']($name, $end); |
| 93 | - } elseif(!isset($params['end'])) { |
|
| 93 | + } elseif (!isset($params['end'])) { |
|
| 94 | 94 | $params['end'] = new $params['class']($name, $params); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - if($this->_type === Token::END) { |
|
| 97 | + if ($this->_type === Token::END) { |
|
| 98 | 98 | $params['end']->setStart(false); |
| 99 | 99 | return $params['end']; |
| 100 | 100 | } |
@@ -111,7 +111,7 @@ |
||
| 111 | 111 | |
| 112 | 112 | private function _set($style) |
| 113 | 113 | { |
| 114 | - $escape = "\e[".implode(';', array_map(function ($style, $name) { |
|
| 114 | + $escape = "\e[".implode(';', array_map(function($style, $name) { |
|
| 115 | 115 | return $this->_style($style, $name); |
| 116 | 116 | }, array_keys($style), $style)).'m'; |
| 117 | 117 | |
@@ -35,7 +35,7 @@ |
||
| 35 | 35 | /** @var Token $token */ |
| 36 | 36 | foreach ($tokens as $token) { |
| 37 | 37 | $result .= htmlspecialchars(substr($source, $last, $token->pos - $last)); |
| 38 | - $result .= $token->isStart() ? '<span class="' . str_replace('.', ' ', $token->name) . '">' : '</span>'; |
|
| 38 | + $result .= $token->isStart() ? '<span class="'.str_replace('.', ' ', $token->name).'">' : '</span>'; |
|
| 39 | 39 | |
| 40 | 40 | $last = $token->pos; |
| 41 | 41 | } |
@@ -40,7 +40,7 @@ |
||
| 40 | 40 | new Rule(new RegexMatcher('/(\\\\\[.*?\\\\\])/s')), |
| 41 | 41 | new Rule( |
| 42 | 42 | new RegexMatcher( |
| 43 | - '/\\\begin{((?:' . implode('|', self::$mathEnvironments) . ')\*?)}(.*?)\\\end{\1}/s', |
|
| 43 | + '/\\\begin{((?:'.implode('|', self::$mathEnvironments).')\*?)}(.*?)\\\end{\1}/s', |
|
| 44 | 44 | [2 => Token::NAME] |
| 45 | 45 | ) |
| 46 | 46 | ), |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | $result = new Result($tokens->getSource(), $tokens->current()); |
| 98 | 98 | |
| 99 | 99 | for ($tokens->next(); $tokens->valid(); $tokens->next()) { |
| 100 | - if(!$tokens->current()->process($context, $this, $result, $tokens)) { |
|
| 100 | + if (!$tokens->current()->process($context, $this, $result, $tokens)) { |
|
| 101 | 101 | break; |
| 102 | 102 | } |
| 103 | 103 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | private function _rules($embedded = false) |
| 148 | 148 | { |
| 149 | 149 | $rules = clone $this->rules; |
| 150 | - if(is_bool($embedded)) { |
|
| 150 | + if (is_bool($embedded)) { |
|
| 151 | 151 | $rules->addMany(['language.'.$this->getIdentifier() => $this->getEnds($embedded)]); |
| 152 | 152 | } |
| 153 | 153 | |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | /** |
| 143 | 143 | * @param bool $embedded |
| 144 | 144 | * |
| 145 | - * @return Rule[] |
|
| 145 | + * @return \Generator |
|
| 146 | 146 | */ |
| 147 | 147 | private function _rules($embedded = false) |
| 148 | 148 | { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | * |
| 169 | 169 | * @param $embedded |
| 170 | 170 | * |
| 171 | - * @return Rule|\Kadet\Highlighter\Parser\Rule[] |
|
| 171 | + * @return Rule |
|
| 172 | 172 | */ |
| 173 | 173 | public function getEnds($embedded = false) |
| 174 | 174 | { |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | ['/*', '*/'] |
| 63 | 63 | ]), ['priority' => 3]), |
| 64 | 64 | |
| 65 | - 'call' => new Rule(new RegexMatcher('/(' . self::IDENTIFIER . ')\s*\(/iu'), ['priority' => -1]), |
|
| 65 | + 'call' => new Rule(new RegexMatcher('/('.self::IDENTIFIER.')\s*\(/iu'), ['priority' => -1]), |
|
| 66 | 66 | |
| 67 | 67 | 'keyword' => new Rule(new WordMatcher([ |
| 68 | 68 | 'do', 'if', 'in', 'for', 'let', 'new', 'try', 'var', 'case', 'else', 'enum', 'eval', 'false', |
@@ -88,7 +88,7 @@ discard block |
||
| 88 | 88 | ]) |
| 89 | 89 | ], |
| 90 | 90 | |
| 91 | - 'variable' => new Rule(new RegexMatcher('/\b(?<!\.)(' . self::IDENTIFIER . ':?)/iu'), [ |
|
| 91 | + 'variable' => new Rule(new RegexMatcher('/\b(?<!\.)('.self::IDENTIFIER.':?)/iu'), [ |
|
| 92 | 92 | 'priority' => -1, |
| 93 | 93 | 'enabled' => $this->variables |
| 94 | 94 | ]) |