Conditions | 5 |
Paths | 35 |
Total Lines | 72 |
Code Lines | 47 |
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 |
||
95 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
96 | { |
||
97 | try { |
||
98 | $projectRoot = ProjectRootHelper::getProjectRoot($input); |
||
99 | $outputFormatter = $this->getOutputFormatter($input); |
||
100 | $baseLineFileName = BaseLineFileHelper::getBaselineFile($input); |
||
101 | $inputAnalysisResultsAsString = CliConfigReader::getStdin($input); |
||
102 | $showRandomIssues = CliConfigReader::getBooleanOption($input, self::SHOW_RANDOM_ERRORS); |
||
103 | |||
104 | $prunedResults = $this->resultsPruner->getPrunedResults( |
||
105 | $baseLineFileName, |
||
106 | $inputAnalysisResultsAsString, |
||
107 | $projectRoot |
||
108 | ); |
||
109 | |||
110 | $outputAnalysisResults = $prunedResults->getPrunedResults(); |
||
111 | |||
112 | OutputWriter::writeToStdError( |
||
113 | $output, |
||
114 | "Latest analysis issue count: {$prunedResults->getInputAnalysisResults()->getCount()}", |
||
115 | false |
||
116 | ); |
||
117 | |||
118 | OutputWriter::writeToStdError( |
||
119 | $output, |
||
120 | "Baseline issue count: {$prunedResults->getBaseLine()->getAnalysisResults()->getCount()}", |
||
121 | false |
||
122 | ); |
||
123 | |||
124 | OutputWriter::writeToStdError( |
||
125 | $output, |
||
126 | "Issue count with baseline removed: {$outputAnalysisResults->getCount()}", |
||
127 | !$outputAnalysisResults->hasNoIssues() |
||
128 | ); |
||
129 | |||
130 | $outputAsString = $outputFormatter->outputResults($outputAnalysisResults); |
||
131 | $output->writeln($outputAsString); |
||
132 | |||
133 | $returnCode = $outputAnalysisResults->hasNoIssues() ? 0 : 1; |
||
134 | |||
135 | if ($showRandomIssues) { |
||
136 | $issuesToReport = min(self::RANDOM_ISSUES_TO_FIX, $prunedResults->getInputAnalysisResults()->getCount()); |
||
137 | |||
138 | OutputWriter::writeToStdError( |
||
139 | $output, |
||
140 | "Random {$issuesToReport} issues in the baseline to fix...", |
||
141 | false |
||
142 | ); |
||
143 | |||
144 | $randomIssuesBuilder = new AnalysisResultsBuilder(); |
||
145 | $allIssues = $prunedResults->getInputAnalysisResults()->getAnalysisResults(); |
||
146 | |||
147 | for ($i = 0; $i < $issuesToReport; ++$i) { |
||
148 | $totalRemaining = count($allIssues); |
||
149 | $issuePicked = rand(0, $totalRemaining - 1); |
||
150 | $randomIssuesBuilder->addAnalysisResult($allIssues[$issuePicked]); |
||
151 | } |
||
152 | |||
153 | $outputAsString = $this->tableOutputFormatter->outputResults($randomIssuesBuilder->build()); |
||
154 | |||
155 | OutputWriter::writeToStdError( |
||
156 | $output, |
||
157 | $outputAsString, |
||
158 | false |
||
159 | ); |
||
160 | } |
||
161 | |||
162 | return $returnCode; |
||
163 | } catch (Throwable $throwable) { |
||
164 | $returnCode = ErrorReporter::reportError($output, $throwable); |
||
165 | |||
166 | return $returnCode; |
||
167 | } |
||
184 |