@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | * @param InputInterface $input |
48 | 48 | * @param Language $language |
49 | 49 | * @param FormatterInterface $formatter |
50 | - * @param $source |
|
50 | + * @param string $source |
|
51 | 51 | */ |
52 | 52 | public function __construct( |
53 | 53 | OutputInterface $output, InputInterface $input, Language $language, FormatterInterface $formatter, $source |
@@ -97,11 +97,17 @@ discard block |
||
97 | 97 | return $formatted; |
98 | 98 | } |
99 | 99 | |
100 | + /** |
|
101 | + * @param string $feature |
|
102 | + */ |
|
100 | 103 | public function wants($feature) |
101 | 104 | { |
102 | 105 | return in_array($feature, $this->_input->getOption('debug')); |
103 | 106 | } |
104 | 107 | |
108 | + /** |
|
109 | + * @return Tokens |
|
110 | + */ |
|
105 | 111 | protected function tokenize() |
106 | 112 | { |
107 | 113 | $tokens = $this->benchmark(function () { |
@@ -125,12 +131,18 @@ discard block |
||
125 | 131 | return $return; |
126 | 132 | } |
127 | 133 | |
134 | + /** |
|
135 | + * @param string $message |
|
136 | + */ |
|
128 | 137 | private function _tree(Tokens $tree, $message, $indented = true) |
129 | 138 | { |
130 | 139 | $this->_output->writeln("Token tree <comment>$message</comment>: "); |
131 | 140 | $this->_output->writeln($this->_debug->format(clone $tree, $indented)); |
132 | 141 | } |
133 | 142 | |
143 | + /** |
|
144 | + * @return Tokens |
|
145 | + */ |
|
134 | 146 | protected function parse(Tokens $tokens) |
135 | 147 | { |
136 | 148 | $tokens = $this->benchmark(function () use ($tokens) { |
@@ -152,6 +164,9 @@ discard block |
||
152 | 164 | }, $this->_times['formatting']); |
153 | 165 | } |
154 | 166 | |
167 | + /** |
|
168 | + * @param string $message |
|
169 | + */ |
|
155 | 170 | private function _slashed($message, $data) |
156 | 171 | { |
157 | 172 | $this->_output->writeln(sprintf( |
@@ -68,14 +68,14 @@ discard block |
||
68 | 68 | $parsed = $this->parse($tokenized); |
69 | 69 | $formatted = $this->format($parsed); |
70 | 70 | |
71 | - if($this->wants('time')) { |
|
71 | + if ($this->wants('time')) { |
|
72 | 72 | $this->_output->writeln(sprintf( |
73 | 73 | '<info>Overall:</info> %.4fs, %s chars/s', |
74 | 74 | array_sum($this->_times), number_format(strlen($this->_source) / array_sum($this->_times)) |
75 | 75 | )); |
76 | 76 | } |
77 | 77 | |
78 | - if($this->wants('detailed-time')) { |
|
78 | + if ($this->wants('detailed-time')) { |
|
79 | 79 | $this->_slashed('Times [s]', array_map(function($t) { |
80 | 80 | return number_format($t, 5); |
81 | 81 | }, $this->_times)); |
@@ -84,11 +84,11 @@ discard block |
||
84 | 84 | }, $this->_times)); |
85 | 85 | } |
86 | 86 | |
87 | - if($this->wants('count')) { |
|
87 | + if ($this->wants('count')) { |
|
88 | 88 | $this->_slashed('Token count', array_map('number_format', $this->_counts)); |
89 | 89 | } |
90 | 90 | |
91 | - if($this->wants('density')) { |
|
91 | + if ($this->wants('density')) { |
|
92 | 92 | $this->_slashed('Token density [tokens/kB]', array_map(function($c) { |
93 | 93 | return number_format($c / strlen($this->_source) * 1024, 1); |
94 | 94 | }, $this->_counts)); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | |
105 | 105 | protected function tokenize() |
106 | 106 | { |
107 | - $tokens = $this->benchmark(function () { |
|
107 | + $tokens = $this->benchmark(function() { |
|
108 | 108 | return $this->_language->tokenize($this->_source); |
109 | 109 | }, $this->_times['tokenization']); |
110 | 110 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | |
134 | 134 | protected function parse(Tokens $tokens) |
135 | 135 | { |
136 | - $tokens = $this->benchmark(function () use ($tokens) { |
|
136 | + $tokens = $this->benchmark(function() use ($tokens) { |
|
137 | 137 | return $this->_language->parse($tokens); |
138 | 138 | }, $this->_times['parsing']); |
139 | 139 | |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | protected function format(Tokens $tokens) |
149 | 149 | { |
150 | - return $this->benchmark(function () use ($tokens) { |
|
150 | + return $this->benchmark(function() use ($tokens) { |
|
151 | 151 | return $this->_formatter->format($tokens); |
152 | 152 | }, $this->_times['formatting']); |
153 | 153 | } |
@@ -156,10 +156,10 @@ discard block |
||
156 | 156 | { |
157 | 157 | $this->_output->writeln(sprintf( |
158 | 158 | "$message %s: %s", |
159 | - implode(' / ', array_map(function ($f) { |
|
159 | + implode(' / ', array_map(function($f) { |
|
160 | 160 | return "<comment>{$f}</comment>"; |
161 | 161 | }, array_keys($data))), |
162 | - implode(' / ', array_map(function ($f) { |
|
162 | + implode(' / ', array_map(function($f) { |
|
163 | 163 | return "<info>{$f}</info>"; |
164 | 164 | }, array_values($data))) |
165 | 165 | )); |
@@ -47,23 +47,23 @@ discard block |
||
47 | 47 | |
48 | 48 | protected function execute(InputInterface $input, OutputInterface $output) |
49 | 49 | { |
50 | - if(!empty($input->getOption('debug')) && $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { |
|
50 | + if (!empty($input->getOption('debug')) && $output->getVerbosity() < OutputInterface::VERBOSITY_VERBOSE) { |
|
51 | 51 | $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); |
52 | 52 | } |
53 | 53 | |
54 | 54 | $output->writeln($this->getApplication()->getLongVersion()."\n", Output::VERBOSITY_VERBOSE); |
55 | 55 | $formatter = KeyLighter::get()->getFormatter($input->getOption('format')) ?: KeyLighter::get()->getDefaultFormatter(); |
56 | 56 | |
57 | - foreach($input->getArgument('path') as $filename) { |
|
57 | + foreach ($input->getArgument('path') as $filename) { |
|
58 | 58 | $language = $input->getOption('language') |
59 | 59 | ? Language::byName($input->getOption('language')) |
60 | 60 | : Language::byFilename($filename); |
61 | 61 | |
62 | - if(!($source = $this->content($filename))) { |
|
62 | + if (!($source = $this->content($filename))) { |
|
63 | 63 | throw new InvalidArgumentException(sprintf('Specified file %s doesn\'t exist, check if given path is correct.', $filename)); |
64 | 64 | } |
65 | 65 | |
66 | - if($output->isVerbose()) { |
|
66 | + if ($output->isVerbose()) { |
|
67 | 67 | $output->writeln(sprintf( |
68 | 68 | "Used file: <path>%s</path>, Language: <language>%s</language>, Formatter: <formatter>%s</formatter>", |
69 | 69 | $filename, $language->getFQN(), get_class($formatter) |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | $formatted = KeyLighter::get()->highlight($source, $language, $formatter); |
76 | 76 | } |
77 | 77 | |
78 | - if(!$input->getOption('no-output')) { |
|
78 | + if (!$input->getOption('no-output')) { |
|
79 | 79 | $output->writeln($formatted); |
80 | 80 | } |
81 | 81 | } |
@@ -83,12 +83,12 @@ discard block |
||
83 | 83 | |
84 | 84 | protected function content($path) |
85 | 85 | { |
86 | - if(!($file = @fopen($path, 'r'))) { |
|
86 | + if (!($file = @fopen($path, 'r'))) { |
|
87 | 87 | return false; |
88 | 88 | } |
89 | 89 | |
90 | 90 | $content = ''; |
91 | - while(!feof($file)) { |
|
91 | + while (!feof($file)) { |
|
92 | 92 | $content .= fgets($file); |
93 | 93 | } |
94 | 94 | fclose($file); |