| Conditions | 11 |
| Paths | 15 |
| Total Lines | 46 |
| Lines | 5 |
| Ratio | 10.87 % |
| 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 |
||
| 32 | public function process_matched_token( $stack_ptr, $group_name, $matched_content ) { |
||
| 33 | if ( ! $this->verify_valid_match( $stack_ptr ) ) { |
||
| 34 | return; |
||
| 35 | } |
||
| 36 | |||
| 37 | $previous_comment = $this->return_previous_comment( $stack_ptr ); |
||
| 38 | |||
| 39 | if ( ! $previous_comment ) { |
||
|
|
|||
| 40 | return; |
||
| 41 | } |
||
| 42 | |||
| 43 | /* |
||
| 44 | * Process docblock tags. |
||
| 45 | */ |
||
| 46 | $comment_end = $previous_comment; |
||
| 47 | $comment_start = $this->return_comment_start( $comment_end ); |
||
| 48 | $has = array( |
||
| 49 | 'module' => false, |
||
| 50 | ); |
||
| 51 | |||
| 52 | // The comment isn't a docblock or is documented elsewhere, so we're going to stop here. |
||
| 53 | if ( ! $comment_start || $this->is_previously_documented( $comment_start, $comment_end ) ) { |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | |||
| 57 | foreach ( $this->tokens[ $comment_start ]['comment_tags'] as $tag ) { |
||
| 58 | // Is the next tag of the docblock the "@module" tag? |
||
| 59 | if ( '@module' === $this->tokens[ $tag ]['content'] ) { |
||
| 60 | // This is used later to determine if we need to throw an error for no module tag. |
||
| 61 | $has['module'] = true; |
||
| 62 | |||
| 63 | // Find the next string, which will be the text after the @module. |
||
| 64 | $string = $this->phpcsFile->findNext( T_DOC_COMMENT_STRING, $tag, $comment_end ); |
||
| 65 | // If it is false, there is no text or if the text is on the another line, error. |
||
| 66 | if ( false === $string || $this->tokens[ $string ]['line'] !== $this->tokens[ $tag ]['line'] ) { |
||
| 67 | $this->phpcsFile->addError( 'Module tag must have a value.', $tag, 'EmptyModule' ); |
||
| 68 | } |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | View Code Duplication | foreach ( $has as $name => $present ) { |
|
| 73 | if ( ! $present ) { |
||
| 74 | $this->phpcsFile->addError( 'Hook documentation is missing a tag: ' . $name, $comment_start, 'No' . ucfirst( $name ) ); |
||
| 75 | } |
||
| 76 | } |
||
| 77 | } |
||
| 78 | } |
||
| 79 |
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: