| Conditions | 14 |
| Paths | 66 |
| Total Lines | 68 |
| Lines | 5 |
| Ratio | 7.35 % |
| 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 |
||
| 67 | public function process_matched_token( $stack_ptr, $group_name, $matched_content ) { |
||
| 68 | |||
| 69 | if ( ! $this->verify_valid_match( $stack_ptr ) ) { |
||
| 70 | return; |
||
| 71 | } |
||
| 72 | |||
| 73 | $previous_comment = $this->return_previous_comment( $stack_ptr ); |
||
| 74 | |||
| 75 | if ( false !== $previous_comment ) { |
||
| 76 | /* |
||
| 77 | * Check to determine if there is a comment immediately preceding the function call. |
||
| 78 | */ |
||
| 79 | if ( ( $this->tokens[ $previous_comment ]['line'] + 1 ) !== $this->tokens[ $stack_ptr ]['line'] ) { |
||
| 80 | $this->phpcsFile->addError( |
||
| 81 | 'The inline documentation for a hook must be on the line immediately before the function call.', |
||
| 82 | $stack_ptr, |
||
| 83 | 'DocMustBePreceding' |
||
| 84 | ); |
||
| 85 | } |
||
| 86 | |||
| 87 | /* |
||
| 88 | * Check that the comment starts is a docblock. |
||
| 89 | */ |
||
| 90 | if ( \T_DOC_COMMENT_CLOSE_TAG !== $this->tokens[ $previous_comment ]['code'] ) { |
||
| 91 | $this->phpcsFile->addError( |
||
| 92 | 'Hooks must include a docblock with /** formatting */', |
||
| 93 | $stack_ptr, |
||
| 94 | 'NoDocblockFound' |
||
| 95 | ); |
||
| 96 | // return; Do we need to return here? Can we keep going? |
||
| 97 | } |
||
| 98 | |||
| 99 | /* |
||
| 100 | * Process docblock tags. |
||
| 101 | */ |
||
| 102 | $comment_end = $previous_comment; |
||
| 103 | $comment_start = $this->return_comment_start( $comment_end ); |
||
| 104 | $has = array( |
||
| 105 | 'since' => false, |
||
| 106 | ); |
||
| 107 | |||
| 108 | // The comment isn't a docblock or is documented elsewhere, so we're going to stop here. |
||
| 109 | if ( ! $comment_start || $this->is_previously_documented( $comment_start, $comment_end ) ) { |
||
| 110 | return; |
||
| 111 | } |
||
| 112 | |||
| 113 | foreach ( $this->tokens[ $comment_start ]['comment_tags'] as $tag ) { |
||
| 114 | // Is the next tag of the docblock the "@since" tag? |
||
| 115 | if ( '@since' === $this->tokens[ $tag ]['content'] ) { |
||
| 116 | $has['since'] = true; |
||
| 117 | // Find the next string, which will be the text after the @since. |
||
| 118 | $string = $this->phpcsFile->findNext( T_DOC_COMMENT_STRING, $tag, $comment_end ); |
||
| 119 | // If it is false, there is no text or if the text is on the another line, error. |
||
| 120 | if ( false === $string || $this->tokens[ $string ]['line'] !== $this->tokens[ $tag ]['line'] ) { |
||
| 121 | $this->phpcsFile->addError( 'Since tag must have a value.', $tag, 'EmptySince' ); |
||
| 122 | } elseif ( ! preg_match( '\'/^\d+\.\d+\.\d+/\'', $string ) ) { // Requires X.Y.Z. Trailing 0 is needed for a major release. |
||
| 123 | $this->phpcsFile->addError( 'Since tag must have a X.Y.Z. version number.', $tag, 'InvalidSince' ); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | View Code Duplication | foreach ( $has as $name => $present ) { |
|
| 129 | if ( ! $present ) { |
||
| 130 | $this->phpcsFile->addError( 'Hook documentation is missing a tag: ' . $name, $comment_start, 'No' . ucfirst( $name ) ); |
||
| 131 | } |
||
| 132 | } |
||
| 133 | } |
||
| 134 | } |
||
| 135 | |||
| 192 |