West/Sniffs/Classes/RequireInterfaceExtendSniff.php
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        $endOfStatement = $phpcsFile->findEndOfStatement($stackPtr);
        $implements = $phpcsFile->findNext(
            T_IMPLEMENTS,
            $stackPtr,
            $endOfStatement,
            false,
            null,
            true
        );

        if ($implements !== false) {
            // interface found
            $phpcsFile->recordMetric($stackPtr, 'Class ImplementExtend', 'yes');
            return;
        }

        $extends = $phpcsFile->findNext(
            T_EXTENDS,
            $stackPtr,
            $endOfStatement,
            false,
            null,
            true
        );

        if ($extends !== false) {
            // parent class found
            $phpcsFile->recordMetric($stackPtr, 'Class ImplementExtend', 'yes');
            return;
        }

        $error   = 'Class "%s" must implement an interface or extend another class';
        $nextVar = $tokens[$phpcsFile->findNext([T_STRING], $stackPtr)];
        $data    = [$nextVar['content']];

        $phpcsFile->addError($error, $stackPtr, 'NotAllowed', $data);
        $phpcsFile->recordMetric($stackPtr, 'Class implements', 'no');
    }
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();

        $endOfStatement = $phpcsFile->findEndOfStatement($stackPtr);
        $implements = $phpcsFile->findNext(
            T_IMPLEMENTS,
            $stackPtr,
            $endOfStatement,
            false,
            null,
            true
        );

        if ($implements !== false) {
            // interface found
            $phpcsFile->recordMetric($stackPtr, 'Class ImplementExtend', 'yes');
            return;
        }

        $extends = $phpcsFile->findNext(
            T_EXTENDS,
            $stackPtr,
            $endOfStatement,
            false,
            null,
            true
        );

        if ($extends !== false) {
            // parent class found
            $phpcsFile->recordMetric($stackPtr, 'Class ImplementExtend', 'yes');
            return;
        }

        $error   = 'Class "%s" must implement an interface or extend another class';
        $nextVar = $tokens[$phpcsFile->findNext([T_STRING], $stackPtr)];
        $data    = [$nextVar['content']];

        $phpcsFile->addError($error, $stackPtr, 'NotAllowed', $data);
        $phpcsFile->recordMetric($stackPtr, 'Class implements', 'no');
    }
{@inheritdoc}