Completed
Branch symfony-console (0fa491)
by Kacper
03:12
created
bin/Application.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     protected function getCommandName(InputInterface $input)
35 35
     {
36 36
         $command = $input->getFirstArgument();
37
-        if(!$command && !$input->hasParameterOption('--help')) {
37
+        if (!$command && !$input->hasParameterOption('--help')) {
38 38
             return 'list';
39 39
         } elseif ($this->has($command)) {
40 40
             return $command;
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
     protected function getDefaultInputDefinition()
57 57
     {
58 58
         $input = parent::getDefaultInputDefinition();
59
-        $input->setOptions(array_filter($input->getOptions(), function (InputOption $option) {
59
+        $input->setOptions(array_filter($input->getOptions(), function(InputOption $option) {
60 60
             return $option->getShortcut() != 'q';
61 61
         }));
62 62
         $input->addOption(new InputOption('no-output', 's', InputOption::VALUE_NONE, 'Disables output, useful for debug'));
Please login to merge, or discard this patch.
bin/Commands/HighlightCommand.php 1 patch
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -47,25 +47,25 @@  discard block
 block discarded – undo
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
 
56 56
         $debugFormatter = new DebugFormatter();
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 62
             $formatter = KeyLighter::get()->getFormatter($input->getOption('format')) ?: KeyLighter::get()->getDefaultFormatter();
63 63
 
64
-            if(!($source = $this->content($filename))) {
64
+            if (!($source = $this->content($filename))) {
65 65
                 throw new InvalidArgumentException(sprintf('Specified file %s doesn\'t exist, check if given path is correct.', $filename));
66 66
             }
67 67
 
68
-            if($output->isVerbose()) {
68
+            if ($output->isVerbose()) {
69 69
                 $counts = ['before' => null, 'after' => null];
70 70
                 $times  = ['tokenization' => null, 'parsing' => null, 'formatting' => null];
71 71
 
@@ -74,34 +74,34 @@  discard block
 block discarded – undo
74 74
                     $filename, $language->getFQN(), get_class($formatter)
75 75
                 ));
76 76
 
77
-                $tokens    = $this->benchmark($output, function() use($language, $source) { return $language->tokenize($source); }, $times['tokenization']);
77
+                $tokens = $this->benchmark($output, function() use($language, $source) { return $language->tokenize($source); }, $times['tokenization']);
78 78
                 $counts['before'] = count($tokens);
79
-                if(in_array('tree-before', $input->getOption('debug'))) {
79
+                if (in_array('tree-before', $input->getOption('debug'))) {
80 80
                     $output->writeln('<comment>Token tree before parsing: </comment>');
81 81
                     $output->writeln($debugFormatter->format(clone $tokens, false));
82 82
                 }
83 83
 
84
-                $tokens    = $this->benchmark($output, function() use($language, $tokens) { return $language->parse($tokens); }, $times['parsing']);
84
+                $tokens = $this->benchmark($output, function() use($language, $tokens) { return $language->parse($tokens); }, $times['parsing']);
85 85
                 $counts['after'] = count($tokens);
86
-                if(in_array('tree-after', $input->getOption('debug'))) {
86
+                if (in_array('tree-after', $input->getOption('debug'))) {
87 87
                     $output->writeln('<comment>Token tree after parsing: </comment>');
88 88
                     $output->writeln($debugFormatter->format(clone $tokens));
89 89
                 }
90 90
 
91 91
                 $formatted = $this->benchmark($output, function() use($formatter, $tokens) { return $formatter->format($tokens); }, $times['formatting']);
92 92
 
93
-                if(in_array('count', $input->getOption('debug'))) {
93
+                if (in_array('count', $input->getOption('debug'))) {
94 94
                     $output->writeln(sprintf(
95 95
                         '<comment>Token count before parsing: </comment> %s (%s tokens/kB)',
96
-                        $counts['before'], number_format($counts['before']/strlen($source) * 1024)
96
+                        $counts['before'], number_format($counts['before'] / strlen($source) * 1024)
97 97
                     ));
98 98
                     $output->writeln(sprintf(
99 99
                         '<comment>Token count after parsing:  </comment> %s (%s tokens/kB)',
100
-                        $counts['after'], number_format($counts['after']/strlen($source) * 1024)
100
+                        $counts['after'], number_format($counts['after'] / strlen($source) * 1024)
101 101
                     ));
102 102
                 }
103 103
 
104
-                if(in_array('detailed-time', $input->getOption('debug'))) {
104
+                if (in_array('detailed-time', $input->getOption('debug'))) {
105 105
                     $output->writeln(sprintf(
106 106
                         '<info>Time taken</info>  [s]       <comment>tokenization</comment>/<comment>parsing</comment>/<comment>formatting</comment>: %.4f / %.4f / %.4f',
107 107
                         $times['tokenization'], $times['parsing'], $times['formatting']
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
                     ));
116 116
                 }
117 117
 
118
-                if(in_array('time', $input->getOption('debug'))) {
118
+                if (in_array('time', $input->getOption('debug'))) {
119 119
                     $output->writeln(sprintf(
120 120
                         '<info>Overall:</info> %.4fs, %s chars/s',
121 121
                         array_sum($times), number_format(strlen($source) / array_sum($times))
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
                 $formatted = KeyLighter::get()->highlight($source, $language, $formatter);
126 126
             }
127 127
             
128
-            if(!$input->getOption('no-output')) {
128
+            if (!$input->getOption('no-output')) {
129 129
                 $output->writeln($formatted);
130 130
             }
131 131
         }
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
 
134 134
     protected function content($path)
135 135
     {
136
-        if(!($file = @fopen($path, 'r'))) {
136
+        if (!($file = @fopen($path, 'r'))) {
137 137
             return false;
138 138
         }
139 139
 
140 140
         $content = '';
141
-        while(!feof($file)) {
141
+        while (!feof($file)) {
142 142
             $content .= fgets($file);
143 143
         }
144 144
         fclose($file);
Please login to merge, or discard this patch.
bin/Commands/FormattersCommand.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -40,7 +40,7 @@
 block discarded – undo
40 40
         $formatters = KeyLighter::get()->registeredFormatters();
41 41
         $table = new Table($output);
42 42
 
43
-        if(!$input->getOption('headerless')) {
43
+        if (!$input->getOption('headerless')) {
44 44
             $table->setHeaders(['Name', 'Formatter']);
45 45
         }
46 46
 
Please login to merge, or discard this patch.
bin/Commands/LanguagesCommand.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
 
47 47
         $table = new Table($output);
48 48
 
49
-        if(!$input->getOption('headerless')) {
49
+        if (!$input->getOption('headerless')) {
50 50
             $table->setHeaders([ucfirst($input->getArgument('by')), $input->getOption('classes') ? 'Class name' : 'Language']);
51 51
         }
52 52
 
53 53
         $table->setRows(array_map(function($language) {
54 54
             return [
55
-                implode(', ', array_map(function ($f) { return "<comment>{$f}</comment>"; }, $language['aliases'])),
55
+                implode(', ', array_map(function($f) { return "<comment>{$f}</comment>"; }, $language['aliases'])),
56 56
                 $language['class']
57 57
             ];
58 58
         }, $input->getOption('no-group') ? $this->processNonGrouped($languages) : $this->processGrouped($languages)));
@@ -63,8 +63,8 @@  discard block
 block discarded – undo
63 63
 
64 64
     protected function processGrouped($languages) {
65 65
         $result = [];
66
-        foreach($languages as $alias => $class) {
67
-            if(!isset($result[$class])) {
66
+        foreach ($languages as $alias => $class) {
67
+            if (!isset($result[$class])) {
68 68
                 $result[$class] = ['aliases' => [], 'class' => $class];
69 69
             }
70 70
 
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 
77 77
     protected function processNonGrouped($languages) {
78 78
         $result = [];
79
-        foreach($languages as $alias => $class) {
79
+        foreach ($languages as $alias => $class) {
80 80
             $result[] = ['aliases' => [$alias], 'class' => $class];
81 81
         }
82 82
 
Please login to merge, or discard this patch.
Parser/Validator/Validator.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -44,8 +44,8 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
-        while(list($rule, $type) = each($rules)) {
73
+        while (list($rule, $type) = each($rules)) {
74 74
             $matched = $this->_matches($context, $rule, $type);
75 75
 
76 76
             if ($type & Validator::CONTEXT_NOT_IN) {
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
         }
Please login to merge, or discard this patch.