Conditions | 15 |
Paths | 17 |
Total Lines | 83 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
83 | protected function execute(InputInterface $input, OutputInterface $output): int { |
||
84 | $appId = $input->getArgument('app-id'); |
||
85 | |||
86 | $checkList = new EmptyCheck(); |
||
87 | foreach ($input->getOption('checker') as $checker) { |
||
88 | if (!isset($this->checkers[$checker])) { |
||
89 | throw new \InvalidArgumentException('Invalid checker: '.$checker); |
||
90 | } |
||
91 | $checkerClass = $this->checkers[$checker]; |
||
92 | $checkList = new $checkerClass($checkList); |
||
93 | } |
||
94 | |||
95 | $codeChecker = new CodeChecker($checkList, !$input->getOption('skip-validate-info')); |
||
96 | |||
97 | $codeChecker->listen('CodeChecker', 'analyseFileBegin', function ($params) use ($output) { |
||
98 | if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
||
99 | $output->writeln("<info>Analysing {$params}</info>"); |
||
100 | } |
||
101 | }); |
||
102 | $codeChecker->listen('CodeChecker', 'analyseFileFinished', function ($filename, $errors) use ($output) { |
||
103 | $count = count($errors); |
||
104 | |||
105 | // show filename if the verbosity is low, but there are errors in a file |
||
106 | if ($count > 0 && OutputInterface::VERBOSITY_VERBOSE > $output->getVerbosity()) { |
||
107 | $output->writeln("<info>Analysing {$filename}</info>"); |
||
108 | } |
||
109 | |||
110 | // show error count if there are errors present or the verbosity is high |
||
111 | if ($count > 0 || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) { |
||
112 | $output->writeln(" {$count} errors"); |
||
113 | } |
||
114 | usort($errors, function ($a, $b) { |
||
115 | return $a['line'] > $b['line']; |
||
116 | }); |
||
117 | |||
118 | foreach ($errors as $p) { |
||
119 | $line = sprintf("%' 4d", $p['line']); |
||
120 | $output->writeln(" <error>line $line: {$p['disallowedToken']} - {$p['reason']}</error>"); |
||
121 | } |
||
122 | }); |
||
123 | $errors = []; |
||
124 | if (!$input->getOption('skip-checkers')) { |
||
125 | $errors = $codeChecker->analyse($appId); |
||
126 | } |
||
127 | |||
128 | if (!$input->getOption('skip-validate-info')) { |
||
129 | $infoChecker = new InfoChecker(); |
||
130 | $infoChecker->listen('InfoChecker', 'parseError', function ($error) use ($output) { |
||
131 | $output->writeln("<error>Invalid appinfo.xml file found: $error</error>"); |
||
132 | }); |
||
133 | |||
134 | $infoErrors = $infoChecker->analyse($appId); |
||
135 | |||
136 | $errors = array_merge($errors, $infoErrors); |
||
137 | |||
138 | $languageParser = new LanguageParseChecker(); |
||
139 | $languageErrors = $languageParser->analyse($appId); |
||
140 | |||
141 | foreach ($languageErrors as $languageError) { |
||
142 | $output->writeln("<error>$languageError</error>"); |
||
143 | } |
||
144 | |||
145 | $errors = array_merge($errors, $languageErrors); |
||
146 | |||
147 | $databaseSchema = new DatabaseSchemaChecker(); |
||
148 | $schemaErrors = $databaseSchema->analyse($appId); |
||
149 | |||
150 | foreach ($schemaErrors['errors'] as $schemaError) { |
||
151 | $output->writeln("<error>$schemaError</error>"); |
||
152 | } |
||
153 | foreach ($schemaErrors['warnings'] as $schemaWarning) { |
||
154 | $output->writeln("<comment>$schemaWarning</comment>"); |
||
155 | } |
||
156 | |||
157 | $errors = array_merge($errors, $schemaErrors['errors']); |
||
158 | } |
||
159 | |||
160 | if (empty($errors)) { |
||
161 | $output->writeln('<info>App is compliant - awesome job!</info>'); |
||
162 | return 0; |
||
163 | } else { |
||
164 | $output->writeln('<error>App is not compliant</error>'); |
||
165 | return 101; |
||
166 | } |
||
193 |