Conditions | 5 |
Paths | 8 |
Total Lines | 56 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 0 | Features | 1 |
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 |
||
52 | protected function execute(InputInterface $input, OutputInterface $output) : int |
||
53 | { |
||
54 | |||
55 | if(!$output->isQuiet()) { |
||
56 | $output->writeln($this->getApplication()->getLongVersion()); |
||
57 | } |
||
58 | |||
59 | $composerJson = $input->getArgument('composer-json'); |
||
60 | $this->checkJsonFile($composerJson); |
||
61 | |||
62 | $getPackageSourceFiles = new LocateComposerPackageSourceFiles(); |
||
63 | |||
64 | $sourcesASTs = new LocateASTFromFiles((new ParserFactory())->create(ParserFactory::PREFER_PHP7)); |
||
65 | |||
66 | $definedVendorSymbols = (new LocateDefinedSymbolsFromASTRoots())->__invoke($sourcesASTs( |
||
67 | (new ComposeGenerators())->__invoke( |
||
68 | $getPackageSourceFiles($composerJson), |
||
69 | (new LocateComposerPackageDirectDependenciesSourceFiles())->__invoke($composerJson) |
||
|
|||
70 | ) |
||
71 | )); |
||
72 | |||
73 | $options = $this->getCheckOptions($input); |
||
74 | |||
75 | $definedExtensionSymbols = (new LocateDefinedSymbolsFromExtensions())->__invoke( |
||
76 | (new DefinedExtensionsResolver())->__invoke($composerJson, $options->getPhpCoreExtensions()) |
||
77 | ); |
||
78 | |||
79 | $usedSymbols = (new LocateUsedSymbolsFromASTRoots())->__invoke($sourcesASTs($getPackageSourceFiles($composerJson))); |
||
80 | |||
81 | $unknownSymbols = array_diff( |
||
82 | $usedSymbols, |
||
83 | $definedVendorSymbols, |
||
84 | $definedExtensionSymbols, |
||
85 | $options->getSymbolWhitelist() |
||
86 | ); |
||
87 | |||
88 | if (!$unknownSymbols) { |
||
89 | $output->writeln("There were no unknown symbols found."); |
||
90 | return 0; |
||
91 | } |
||
92 | |||
93 | $output->writeln("The following unknown symbols were found:"); |
||
94 | $table = new Table($output); |
||
95 | $table->setHeaders(['unknown symbol', 'guessed dependency']); |
||
96 | $guesser = new DependencyGuesser(); |
||
97 | foreach ($unknownSymbols as $unknownSymbol) { |
||
98 | $guessedDependencies = []; |
||
99 | foreach($guesser($unknownSymbol) as $guessedDependency) { |
||
100 | $guessedDependencies[] = $guessedDependency; |
||
101 | } |
||
102 | $table->addRow([$unknownSymbol, implode("\n", $guessedDependencies)]); |
||
103 | } |
||
104 | $table->render(); |
||
105 | |||
106 | return ((int) (bool) $unknownSymbols); |
||
107 | } |
||
108 | |||
146 | } |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.