@@ -70,21 +70,19 @@ discard block |
||
| 70 | 70 | public function languageByName($name, $params = []) |
| 71 | 71 | { |
| 72 | 72 | return isset($this->_languages['name'][$name]) ? |
| 73 | - $this->_languages['name'][$name]($params) : |
|
| 74 | - new PlainText($params); |
|
| 73 | + $this->_languages['name'][$name]($params) : new PlainText($params); |
|
| 75 | 74 | } |
| 76 | 75 | |
| 77 | 76 | public function languageByMime($mime, $params = []) |
| 78 | 77 | { |
| 79 | 78 | return isset($this->_languages['mime'][$mime]) ? |
| 80 | - $this->_languages['mime'][$mime]($params) : |
|
| 81 | - new PlainText($params); |
|
| 79 | + $this->_languages['mime'][$mime]($params) : new PlainText($params); |
|
| 82 | 80 | } |
| 83 | 81 | |
| 84 | 82 | public function languageByExt($filename, $params = []) |
| 85 | 83 | { |
| 86 | - foreach($this->_languages['extension'] as $mask => $class) { |
|
| 87 | - if(fnmatch($mask, $filename)) { |
|
| 84 | + foreach ($this->_languages['extension'] as $mask => $class) { |
|
| 85 | + if (fnmatch($mask, $filename)) { |
|
| 88 | 86 | return $class($params); |
| 89 | 87 | } |
| 90 | 88 | } |
@@ -110,7 +108,7 @@ discard block |
||
| 110 | 108 | |
| 111 | 109 | public function registeredLanguages($by = 'name', $class = false) |
| 112 | 110 | { |
| 113 | - return array_map(function ($e) use($class) { |
|
| 111 | + return array_map(function($e) use($class) { |
|
| 114 | 112 | return $e([])->getFQN($class); |
| 115 | 113 | }, $this->_languages[$by]); |
| 116 | 114 | } |
@@ -150,7 +148,7 @@ discard block |
||
| 150 | 148 | |
| 151 | 149 | public function init() |
| 152 | 150 | { |
| 153 | - foreach(include __DIR__.'/Config/metadata.php' as $alias) { |
|
| 151 | + foreach (include __DIR__.'/Config/metadata.php' as $alias) { |
|
| 154 | 152 | $class = $alias[0]; |
| 155 | 153 | unset($alias[0]); |
| 156 | 154 | |
@@ -166,13 +164,13 @@ discard block |
||
| 166 | 164 | */ |
| 167 | 165 | public function register($class, array $options) |
| 168 | 166 | { |
| 169 | - if(!is_callable($class) && is_subclass_of($class, Language::class)) { |
|
| 167 | + if (!is_callable($class) && is_subclass_of($class, Language::class)) { |
|
| 170 | 168 | $class = function($arguments = []) use ($class) { |
| 171 | 169 | return new $class($arguments); |
| 172 | 170 | }; |
| 173 | 171 | } |
| 174 | 172 | |
| 175 | - foreach(array_intersect_key($options, array_flip(['name', 'mime', 'extension'])) as $name => $values) { |
|
| 173 | + foreach (array_intersect_key($options, array_flip(['name', 'mime', 'extension'])) as $name => $values) { |
|
| 176 | 174 | $this->_languages[$name] = array_merge($this->_languages[$name], array_fill_keys($values, $class)); |
| 177 | 175 | } |
| 178 | 176 | } |
@@ -36,14 +36,14 @@ |
||
| 36 | 36 | new OpenRule(new RegexMatcher('/(<[\w\.-]+)[:\/>:\s]/')), |
| 37 | 37 | new CloseRule(new SubStringMatcher('>'), ['context' => ['!string', '!comment']]) |
| 38 | 38 | ], |
| 39 | - 'tag.close' => new Rule(new RegexMatcher('/(<\/' . self::IDENTIFIER . '>)/')), |
|
| 39 | + 'tag.close' => new Rule(new RegexMatcher('/(<\/'.self::IDENTIFIER.'>)/')), |
|
| 40 | 40 | |
| 41 | - 'symbol.tag' => new Rule(new RegexMatcher('/<\\/?' . self::IDENTIFIER . '/', [ |
|
| 41 | + 'symbol.tag' => new Rule(new RegexMatcher('/<\\/?'.self::IDENTIFIER.'/', [ |
|
| 42 | 42 | 'name' => Token::NAME, |
| 43 | 43 | 'namespace' => '$.namespace' |
| 44 | 44 | ]), ['context' => ['tag', '!string']]), |
| 45 | 45 | |
| 46 | - 'symbol.attribute' => new Rule(new RegexMatcher('/' . self::IDENTIFIER . '=/', [ |
|
| 46 | + 'symbol.attribute' => new Rule(new RegexMatcher('/'.self::IDENTIFIER.'=/', [ |
|
| 47 | 47 | 'name' => Token::NAME, |
| 48 | 48 | 'namespace' => '$.namespace' |
| 49 | 49 | ]), ['context' => ['tag', '!string']]), |
@@ -44,8 +44,8 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | public function setRules($rules) |
| 46 | 46 | { |
| 47 | - if(empty($rules)) { |
|
| 48 | - $this->_rules = [ 'none' => Validator::CONTEXT_IN_ONE_OF ]; |
|
| 47 | + if (empty($rules)) { |
|
| 48 | + $this->_rules = ['none' => Validator::CONTEXT_IN_ONE_OF]; |
|
| 49 | 49 | } else { |
| 50 | 50 | foreach ($rules as $key => $rule) { |
| 51 | 51 | list($plain, $type) = $this->_parse($rule); |
@@ -57,8 +57,8 @@ discard block |
||
| 57 | 57 | private function _clean($rule, &$required) |
| 58 | 58 | { |
| 59 | 59 | if (strpos($rule, '.') !== false) { |
| 60 | - foreach (array_filter(array_keys($required), function ($key) use ($rule) { |
|
| 61 | - return fnmatch($key . '.*', $rule); |
|
| 60 | + foreach (array_filter(array_keys($required), function($key) use ($rule) { |
|
| 61 | + return fnmatch($key.'.*', $rule); |
|
| 62 | 62 | }) as $remove) { |
| 63 | 63 | unset($required[$remove]); |
| 64 | 64 | } |
@@ -66,11 +66,11 @@ discard block |
||
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | protected function _validate($context, $rules, $result = false) { |
| 69 | - if(empty($context)) { |
|
| 69 | + if (empty($context)) { |
|
| 70 | 70 | $context = ['none']; |
| 71 | 71 | } |
| 72 | 72 | |
| 73 | - foreach($rules as $rule => &$type) { |
|
| 73 | + foreach ($rules as $rule => &$type) { |
|
| 74 | 74 | $matched = $this->_matches($context, $rule, $type); |
| 75 | 75 | |
| 76 | 76 | if ($type & Validator::CONTEXT_NOT_IN) { |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | $rule = substr($rule, $pos); |
| 125 | 125 | |
| 126 | - if($type & self::CONTEXT_REGEX) { |
|
| 126 | + if ($type & self::CONTEXT_REGEX) { |
|
| 127 | 127 | $rule = "/^$rule(\\.\\w+)?/i"; |
| 128 | 128 | } |
| 129 | 129 | |
@@ -131,22 +131,22 @@ discard block |
||
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | private function _matches($context, $rule, $type) { |
| 134 | - if($type & self::CONTEXT_EXACTLY) { |
|
| 134 | + if ($type & self::CONTEXT_EXACTLY) { |
|
| 135 | 135 | return in_array($rule, $context, true); |
| 136 | - } elseif($type & self::CONTEXT_REGEX) { |
|
| 137 | - foreach($context as $item) { |
|
| 138 | - if(preg_match($rule, $item)) { |
|
| 136 | + } elseif ($type & self::CONTEXT_REGEX) { |
|
| 137 | + foreach ($context as $item) { |
|
| 138 | + if (preg_match($rule, $item)) { |
|
| 139 | 139 | return true; |
| 140 | 140 | } |
| 141 | 141 | } |
| 142 | 142 | return false; |
| 143 | 143 | } else { |
| 144 | - if(in_array($rule, $context, true)) { |
|
| 144 | + if (in_array($rule, $context, true)) { |
|
| 145 | 145 | return true; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - foreach($context as $item) { |
|
| 149 | - if(fnmatch("$rule.*", $item)) { |
|
| 148 | + foreach ($context as $item) { |
|
| 149 | + if (fnmatch("$rule.*", $item)) { |
|
| 150 | 150 | return true; |
| 151 | 151 | } |
| 152 | 152 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | { |
| 159 | 159 | static $validator; |
| 160 | 160 | if (!$validator) { |
| 161 | - $validator = new DelegateValidator(function () { |
|
| 161 | + $validator = new DelegateValidator(function() { |
|
| 162 | 162 | return true; |
| 163 | 163 | }); |
| 164 | 164 | } |
@@ -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]); |
@@ -19,14 +19,14 @@ |
||
| 19 | 19 | { |
| 20 | 20 | public static function rearrange(array $array, array $keys) |
| 21 | 21 | { |
| 22 | - return array_combine($keys, array_map(function ($key) use ($array) { |
|
| 22 | + return array_combine($keys, array_map(function($key) use ($array) { |
|
| 23 | 23 | return $array[$key]; |
| 24 | 24 | }, $keys)); |
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | public static function column(array $array, $index) |
| 28 | 28 | { |
| 29 | - return array_map(function ($e) use ($index) { return $e[$index]; }, $array); |
|
| 29 | + return array_map(function($e) use ($index) { return $e[$index]; }, $array); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public static function find(array $array, callable $tester) |
@@ -54,8 +54,8 @@ |
||
| 54 | 54 | $split = preg_split('/\R\R/', $source, 2); |
| 55 | 55 | |
| 56 | 56 | $http = $split[0]; |
| 57 | - if(isset($split[1]) && $payload = $split[1]) { |
|
| 58 | - if(preg_match('/Content-Type: ([^;]*)/', $http, $matches)) { |
|
| 57 | + if (isset($split[1]) && $payload = $split[1]) { |
|
| 58 | + if (preg_match('/Content-Type: ([^;]*)/', $http, $matches)) { |
|
| 59 | 59 | $mime = $matches[1]; |
| 60 | 60 | } else { |
| 61 | 61 | $mime = 'text/plain'; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | 'comment' => new Rule(new CommentMatcher(['//'], [['/*', '*/']]), ['priority' => 3]), |
| 63 | 63 | |
| 64 | - 'call' => new Rule(new RegexMatcher('/(' . self::IDENTIFIER . ')\s*\(/iu'), ['priority' => -1]), |
|
| 64 | + 'call' => new Rule(new RegexMatcher('/('.self::IDENTIFIER.')\s*\(/iu'), ['priority' => -1]), |
|
| 65 | 65 | |
| 66 | 66 | 'keyword' => new Rule(new WordMatcher([ |
| 67 | 67 | 'do', 'if', 'in', 'for', 'let', 'new', 'try', 'var', 'case', 'else', 'enum', 'eval', |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | ]) |
| 91 | 91 | ], |
| 92 | 92 | |
| 93 | - 'variable' => new Rule(new RegexMatcher('/\b(?<!\.)(' . self::IDENTIFIER . ':?)/iu'), [ |
|
| 93 | + 'variable' => new Rule(new RegexMatcher('/\b(?<!\.)('.self::IDENTIFIER.':?)/iu'), [ |
|
| 94 | 94 | 'priority' => -1, |
| 95 | 95 | 'enabled' => $this->variables |
| 96 | 96 | ]) |
@@ -61,7 +61,7 @@ |
||
| 61 | 61 | 'string.nowdoc' => new Rule( |
| 62 | 62 | new RegexMatcher('/<<\s*\'(\w+)\';(?P<string>.*?)\R\1/sm', [ |
| 63 | 63 | 'string' => Token::NAME, |
| 64 | - 0 => 'keyword.nowdoc' |
|
| 64 | + 0 => 'keyword.nowdoc' |
|
| 65 | 65 | ]), ['context' => ['!comment']] |
| 66 | 66 | ), |
| 67 | 67 | |
@@ -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 | } |