url_shorteners, array_fill( 0, count( $this->url_shorteners ), '`' ) ); $this->regex = sprintf( self::REGEX_TEMPLATE, implode( '|', $urls ) ); return Tokens::$textStringTokens + [ T_COMMENT, T_DOC_COMMENT_STRING, T_DOC_COMMENT, ]; } /** * Processes this test, when one of its tokens is encountered. * * @since 0.2.0 * * @param \PHP_CodeSniffer\Files\File $phpcsFile The PHP_CodeSniffer file where the * token was found. * @param int $stackPtr The position of the current token * in the stack. * * @return void */ public function process( File $phpcsFile, $stackPtr ) { $tokens = $phpcsFile->getTokens(); $content = $tokens[ $stackPtr ]['content']; if ( stripos( $content, '.' ) === false ) { return; } if ( preg_match_all( $this->regex, $content, $matches ) > 0 ) { foreach ( $matches[0] as $matched_url ) { $phpcsFile->addError( self::ERROR_MSG, $stackPtr, 'Found', [ $matched_url ] ); } } } }