Conditions | 11 |
Paths | 11 |
Total Lines | 19 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 declare( strict_types=1 ); |
||
77 | private function checkRequired( array $opts ) { |
||
78 | foreach ( self::REQUIRED_OPTS as $opt ) { |
||
79 | if ( !array_key_exists( $opt, $opts ) ) { |
||
80 | exit( "Required option $opt missing." ); |
||
1 ignored issue
–
show
|
|||
81 | } |
||
82 | } |
||
83 | |||
84 | if ( !array_key_exists( 'password', $opts ) && !array_key_exists( 'use-password-file', $opts ) ) { |
||
85 | exit( 'Please provide a password or use a password file' ); |
||
1 ignored issue
–
show
|
|||
86 | } elseif ( array_key_exists( 'password', $opts ) && array_key_exists( 'use-password-file', $opts ) ) { |
||
87 | exit( 'Can only use one of "password" and "use-password-file"' ); |
||
1 ignored issue
–
show
|
|||
88 | } |
||
89 | |||
90 | if ( array_key_exists( 'use-password-file', $opts ) && !file_exists( self::PASSWORD_FILE ) ) { |
||
91 | exit( 'Please create the password file (' . self::PASSWORD_FILE . ')' ); |
||
1 ignored issue
–
show
|
|||
92 | } |
||
93 | |||
94 | if ( array_key_exists( 'task', $opts ) && array_key_exists( 'subtask', $opts ) ) { |
||
95 | exit( 'Cannot specify both task and subtask.' ); |
||
1 ignored issue
–
show
|
|||
96 | } |
||
147 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.