Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. ObjectMemberCommaSniff.php

class ObjectMemberCommaSniff

Hierarchy

  • class \PHP_CodeSniffer\Standards\Squiz\Sniffs\Objects\ObjectMemberCommaSniff implements \PHP_CodeSniffer\Sniffs\Sniff

Expanded class hierarchy of ObjectMemberCommaSniff

File

vendor/squizlabs/php_codesniffer/src/Standards/Squiz/Sniffs/Objects/ObjectMemberCommaSniff.php, line 18

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Objects
View source
class ObjectMemberCommaSniff implements Sniff {
    
    /**
     * A list of tokenizers this sniff supports.
     *
     * @var array
     */
    public $supportedTokenizers = [
        'JS',
    ];
    
    /**
     * Registers the token types that this sniff wishes to listen to.
     *
     * @return array<int|string>
     */
    public function register() {
        return [
            T_CLOSE_OBJECT,
        ];
    }
    
    //end register()
    
    /**
     * Process the tokens that this sniff is listening for.
     *
     * @param \PHP_CodeSniffer\Files\File $phpcsFile The file where the token was found.
     * @param int                         $stackPtr  The position in the stack where
     *                                               the token was found.
     *
     * @return void
     */
    public function process(File $phpcsFile, $stackPtr) {
        $tokens = $phpcsFile->getTokens();
        $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, $stackPtr - 1, null, true);
        if ($tokens[$prev]['code'] === T_COMMA) {
            $error = 'Last member of object must not be followed by a comma';
            $fix = $phpcsFile->addFixableError($error, $prev, 'Found');
            if ($fix === true) {
                $phpcsFile->fixer
                    ->replaceToken($prev, '');
            }
        }
    }
    
    //end process()

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ObjectMemberCommaSniff::$supportedTokenizers public property A list of tokenizers this sniff supports.
ObjectMemberCommaSniff::process public function Process the tokens that this sniff is listening for. Overrides Sniff::process
ObjectMemberCommaSniff::register public function Registers the token types that this sniff wishes to listen to. Overrides Sniff::register

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal