@@ -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) |
@@ -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 | } |
@@ -51,7 +51,7 @@ |
||
| 51 | 51 | new Rule(new RegexMatcher('/(\$\w+)/i'), ['context' => ['*none', '*string.double']]), |
| 52 | 52 | 'special' => new Rule(new RegexMatcher('/(\$[#@_])/i'), ['context' => ['*none', '*string.double']]), |
| 53 | 53 | 'argument' => new Rule(new RegexMatcher('/(\$\d+)/i'), ['context' => ['*none', '*string.double']]), |
| 54 | - new Rule(new RegexMatcher('/\$\{(\w+)(.*?)\}/i', [ 1 => Token::NAME, 2 => 'string' ]), ['context' => ['*none', '*string.double']]) |
|
| 54 | + new Rule(new RegexMatcher('/\$\{(\w+)(.*?)\}/i', [1 => Token::NAME, 2 => 'string']), ['context' => ['*none', '*string.double']]) |
|
| 55 | 55 | ], |
| 56 | 56 | |
| 57 | 57 | 'number' => new Rule(new RegexMatcher('/(-?(?:0[0-7]+|0[xX][0-9a-fA-F]+|0b[01]+|\d+))/')), |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | new Rule(new RegexMatcher('/(\\\\\[.*?\\\\\])/s')), |
| 42 | 42 | new Rule( |
| 43 | 43 | new RegexMatcher( |
| 44 | - '/\\\begin{((?:' . implode('|', self::$mathEnvironments) . ')\*?)}(.*?)\\\end{\1}/s', |
|
| 44 | + '/\\\begin{((?:'.implode('|', self::$mathEnvironments).')\*?)}(.*?)\\\end{\1}/s', |
|
| 45 | 45 | [2 => Token::NAME] |
| 46 | 46 | ) |
| 47 | 47 | ) |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | { |
| 36 | 36 | $this->setName('highlight') |
| 37 | 37 | ->addArgument('path', InputArgument::REQUIRED | InputArgument::IS_ARRAY, 'File(s) to highlight') |
| 38 | - ->addOption('normalize', null, InputOption::VALUE_OPTIONAL, 'Normalize input to LF') |
|
| 38 | + ->addOption('normalize', null, InputOption::VALUE_OPTIONAL, 'Normalize input to LF') |
|
| 39 | 39 | ->addOption('language', 'l', InputOption::VALUE_OPTIONAL, 'Source Language to highlight, see <comment>list-languages</comment> command') |
| 40 | 40 | ->addOption('format', 'f', InputOption::VALUE_OPTIONAL, 'Output format, see <comment>list-languages</comment> command', 'cli') |
| 41 | 41 | ->addOption( |
@@ -48,26 +48,26 @@ discard block |
||
| 48 | 48 | |
| 49 | 49 | protected function execute(InputInterface $input, OutputInterface $output) |
| 50 | 50 | { |
| 51 | - if(!empty($input->getOption('debug')) && $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { |
|
| 51 | + if (!empty($input->getOption('debug')) && $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { |
|
| 52 | 52 | $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | $output->writeln($this->getApplication()->getLongVersion()."\n", Output::VERBOSITY_VERBOSE); |
| 56 | 56 | $formatter = KeyLighter::get()->getFormatter($input->getOption('format')) ?: KeyLighter::get()->getDefaultFormatter(); |
| 57 | 57 | |
| 58 | - foreach($input->getArgument('path') as $filename) { |
|
| 58 | + foreach ($input->getArgument('path') as $filename) { |
|
| 59 | 59 | $this->process($input, $output, $filename, $formatter); |
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | protected function content($path, $normalize = false) |
| 64 | 64 | { |
| 65 | - if(!($file = @fopen($path, 'r'))) { |
|
| 65 | + if (!($file = @fopen($path, 'r'))) { |
|
| 66 | 66 | return false; |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | $content = ''; |
| 70 | - while(!feof($file)) { |
|
| 70 | + while (!feof($file)) { |
|
| 71 | 71 | $content .= fgets($file); |
| 72 | 72 | } |
| 73 | 73 | fclose($file); |
@@ -99,6 +99,9 @@ |
||
| 99 | 99 | || $input->hasParameterOption('-r'); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | + /** |
|
| 103 | + * @param string $filename |
|
| 104 | + */ |
|
| 102 | 105 | private function regenerate(InputInterface $input, $filename) { |
| 103 | 106 | $filename = str_replace(DIRECTORY_SEPARATOR, '/', $filename); |
| 104 | 107 | $patterns = $input->getArgument('files'); |
@@ -59,7 +59,7 @@ discard block |
||
| 59 | 59 | /** @var \SplFileInfo $file */ |
| 60 | 60 | foreach ($iterator as $file) { |
| 61 | 61 | $pathname = substr($file->getPathname(), strlen($this->_input) + 1); |
| 62 | - if(!$this->regenerate($input, $pathname)) { |
|
| 62 | + if (!$this->regenerate($input, $pathname)) { |
|
| 63 | 63 | continue; |
| 64 | 64 | } |
| 65 | 65 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | if ($this->review($input, $output, $tokens, $reviewer)) { |
| 72 | 72 | $result = StringHelper::normalize($this->_formatter->format($tokens)); |
| 73 | 73 | |
| 74 | - if(!file_exists($this->_output.'/'.dirname($pathname))) { |
|
| 74 | + if (!file_exists($this->_output.'/'.dirname($pathname))) { |
|
| 75 | 75 | mkdir($this->_output.'/'.dirname($pathname), 755, true); |
| 76 | 76 | } |
| 77 | 77 | |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | $filename = str_replace(DIRECTORY_SEPARATOR, '/', $filename); |
| 104 | 104 | $patterns = $input->getArgument('files'); |
| 105 | 105 | |
| 106 | - foreach($patterns as $pattern) { |
|
| 107 | - if($input->getOption('new') && file_exists("{$this->_output}/$filename.tkn")) { |
|
| 106 | + foreach ($patterns as $pattern) { |
|
| 107 | + if ($input->getOption('new') && file_exists("{$this->_output}/$filename.tkn")) { |
|
| 108 | 108 | continue; |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - if(fnmatch($pattern, $filename)) { |
|
| 111 | + if (fnmatch($pattern, $filename)) { |
|
| 112 | 112 | return true; |
| 113 | 113 | } |
| 114 | 114 | } |
@@ -16,9 +16,7 @@ |
||
| 16 | 16 | namespace Kadet\Highlighter\bin\Commands\Benchmark; |
| 17 | 17 | |
| 18 | 18 | |
| 19 | -use Kadet\Highlighter\Formatter\FormatterInterface; |
|
| 20 | 19 | use Kadet\Highlighter\KeyLighter; |
| 21 | -use Kadet\Highlighter\Language\Language; |
|
| 22 | 20 | use Symfony\Component\Console\Command\Command; |
| 23 | 21 | use Symfony\Component\Console\Helper\Table; |
| 24 | 22 | use Symfony\Component\Console\Helper\TableCell; |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $this->separator($file, $table); |
| 50 | 50 | |
| 51 | 51 | foreach ($data['times'] as $set => $times) { |
| 52 | - $result = array_map(function ($time) use ($data, $input) { |
|
| 52 | + $result = array_map(function($time) use ($data, $input) { |
|
| 53 | 53 | return $input->getOption('relative') ? $data['size'] / $time : $time * 1000; |
| 54 | 54 | }, $times); |
| 55 | 55 | |
@@ -63,8 +63,8 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | foreach ($data['memory'] as $set => $memory) { |
| 66 | - $result = array_map(function ($memory) use ($data, $input) { |
|
| 67 | - $bytes = $input->getOption('relative') ? $memory/$data['size'] : $memory; |
|
| 66 | + $result = array_map(function($memory) use ($data, $input) { |
|
| 67 | + $bytes = $input->getOption('relative') ? $memory / $data['size'] : $memory; |
|
| 68 | 68 | return $this->formatBytes($bytes, (bool)$input->getOption('relative')); |
| 69 | 69 | }, $memory); |
| 70 | 70 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | } |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | - if(!$input->hasParameterOption('--summary')) { |
|
| 75 | + if (!$input->hasParameterOption('--summary')) { |
|
| 76 | 76 | $table->render(); |
| 77 | 77 | } |
| 78 | 78 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | }, ARRAY_FILTER_USE_KEY); |
| 82 | 82 | |
| 83 | 83 | $max = max(array_map('strlen', array_keys($summary))); |
| 84 | - foreach($summary as $name => $set) { |
|
| 84 | + foreach ($summary as $name => $set) { |
|
| 85 | 85 | $output->writeln(sprintf( |
| 86 | 86 | "<comment>%s</comment> %s %s", |
| 87 | 87 | str_pad($name, $max, ' ', STR_PAD_LEFT), |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | { |
| 131 | 131 | $mean = array_sum($result) / count($result); |
| 132 | 132 | |
| 133 | - return sqrt(array_sum(array_map(function ($result) use ($mean) { |
|
| 133 | + return sqrt(array_sum(array_map(function($result) use ($mean) { |
|
| 134 | 134 | return pow($result - $mean, 2); |
| 135 | 135 | }, $result)) / count($result)); |
| 136 | 136 | } |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | $bytes /= (1 << (10 * $pow)); |
| 146 | 146 | |
| 147 | - return $this->format($bytes);//.$units[$pow].($relative ? '/byte' : ''); |
|
| 147 | + return $this->format($bytes); //.$units[$pow].($relative ? '/byte' : ''); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | protected function configure() |
@@ -110,6 +110,9 @@ discard block |
||
| 110 | 110 | ; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | + /** |
|
| 114 | + * @param string $source |
|
| 115 | + */ |
|
| 113 | 116 | protected function benchmark($source, Language $language, FormatterInterface $formatter, $geshi = null) |
| 114 | 117 | { |
| 115 | 118 | gc_collect_cycles(); // force garbage collector |
@@ -161,6 +164,9 @@ discard block |
||
| 161 | 164 | ]; |
| 162 | 165 | } |
| 163 | 166 | |
| 167 | + /** |
|
| 168 | + * @param string $source |
|
| 169 | + */ |
|
| 164 | 170 | protected function geshi($source, $language) |
| 165 | 171 | { |
| 166 | 172 | $geshi = microtime(true); |
@@ -70,13 +70,13 @@ discard block |
||
| 70 | 70 | $times = []; |
| 71 | 71 | $memory = []; |
| 72 | 72 | |
| 73 | - for($i = $input->getOption('times'), $progress = new ProgressBar($output, $i); $i > 0; $i--) { |
|
| 73 | + for ($i = $input->getOption('times'), $progress = new ProgressBar($output, $i); $i > 0; $i--) { |
|
| 74 | 74 | $progress->display(); |
| 75 | 75 | $result = $this->benchmark($source, $language, $formatter); |
| 76 | - $times = array_merge_recursive($times, $result['times']); |
|
| 76 | + $times = array_merge_recursive($times, $result['times']); |
|
| 77 | 77 | $memory = array_merge_recursive($memory, $result['memory']); |
| 78 | 78 | |
| 79 | - if($input->getOption('geshi') && class_exists('GeSHi')) { |
|
| 79 | + if ($input->getOption('geshi') && class_exists('GeSHi')) { |
|
| 80 | 80 | $times['geshi'][] = $this->geshi($source, $file->getExtension()); |
| 81 | 81 | } |
| 82 | 82 | |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | { |
| 179 | 179 | $result = json_encode($results, $input->getOption('pretty') ? JSON_PRETTY_PRINT : 0); |
| 180 | 180 | |
| 181 | - if($input->hasArgument('output')) { |
|
| 181 | + if ($input->hasArgument('output')) { |
|
| 182 | 182 | file_put_contents($input->getArgument('output'), $result); |
| 183 | 183 | } else { |
| 184 | 184 | $output->write($result); |