Conditions | 10 |
Paths | 32 |
Total Lines | 42 |
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 // phpcs:ignore WordPress.Files.FileName.NotHyphenatedLowercase |
||
38 | public function doRun( InputInterface $input, OutputInterface $output ) { |
||
39 | $output->getFormatter()->setStyle( 'warning', new OutputFormatterStyle( 'black', 'yellow' ) ); |
||
40 | $errout = is_callable( array( $output, 'getErrorOutput' ) ) ? $output->getErrorOutput() : $output; |
||
41 | |||
42 | // Try to find a composer.json, if COMPOSER isn't set. |
||
43 | if ( ! getenv( 'COMPOSER' ) ) { |
||
44 | $dir = getcwd(); |
||
45 | $ok = false; |
||
46 | do { |
||
47 | $composer = $dir . DIRECTORY_SEPARATOR . 'composer.json'; |
||
48 | if ( file_exists( $composer ) ) { |
||
49 | $ok = true; |
||
50 | break; |
||
51 | } |
||
52 | |||
53 | $prev = $dir; |
||
54 | $dir = dirname( $dir ); |
||
55 | } while ( $prev !== $dir ); |
||
56 | |||
57 | // If we found one in a parent directory, ask if it should be used. |
||
58 | if ( getcwd() !== $dir ) { |
||
59 | if ( ! $ok || ! $input->isInteractive() ) { |
||
60 | $errout->writeln( '<error>File composer.json is not found in ' . getcwd() . '.</>' ); |
||
61 | $errout->writeln( '<error>Run changelogger from the appropriate directory, or set the environment variable COMPOSER to point to composer.json.</>' ); |
||
62 | return -1; |
||
63 | } |
||
64 | |||
65 | $question = new ConfirmationQuestion( "<info>No composer.json in current directory, do you want to use the one at $composer? [Y/n]</> ", true ); |
||
66 | if ( ! $this->getHelperSet()->get( 'question' )->ask( $input, $output, $question ) ) { |
||
67 | return -1; |
||
68 | } |
||
69 | } |
||
70 | Config::setComposerJsonPath( $composer ); |
||
71 | } |
||
72 | |||
73 | try { |
||
74 | return parent::doRun( $input, $output ); |
||
75 | } catch ( ConfigException $ex ) { |
||
76 | $errout->writeln( "<error>{$ex->getMessage()}</>" ); |
||
77 | return -1; |
||
78 | } |
||
79 | } |
||
80 | |||
82 |