SlevomatCodingStandard\Helpers\StringHelper::startsWith PHP Method

startsWith() public static method

public static startsWith ( string $haystack, string $needle ) : boolean
$haystack string
$needle string
return boolean
    public static function startsWith($haystack, $needle)
    {
        return strncmp($haystack, $needle, strlen($needle)) === 0;
    }

Usage Example

コード例 #1
0
 /**
  * @param \PHP_CodeSniffer_File $phpcsFile
  * @param integer $usePointer
  */
 public function process(PHP_CodeSniffer_File $phpcsFile, $usePointer)
 {
     if (UseStatementHelper::isAnonymousFunctionUse($phpcsFile, $usePointer) || UseStatementHelper::isTraitUse($phpcsFile, $usePointer)) {
         return;
     }
     $namespaceName = NamespaceHelper::findCurrentNamespaceName($phpcsFile, $usePointer);
     if ($namespaceName === null) {
         $namespaceName = '';
     }
     $usedTypeName = UseStatementHelper::getFullyQualifiedTypeNameFromUse($phpcsFile, $usePointer);
     if (!StringHelper::startsWith($usedTypeName, $namespaceName)) {
         return;
     }
     $asPointer = $this->findAsPointer($phpcsFile, $usePointer);
     if ($asPointer !== null) {
         return;
     }
     $usedTypeNameRest = substr($usedTypeName, strlen($namespaceName));
     if (!NamespaceHelper::isFullyQualifiedName($usedTypeNameRest) && $namespaceName !== '') {
         return;
     }
     if (!NamespaceHelper::hasNamespace($usedTypeNameRest)) {
         $fix = $phpcsFile->addFixableError(sprintf('Use %s is from the same namespace – that is prohibited', $usedTypeName), $usePointer, self::CODE_USE_FROM_SAME_NAMESPACE);
         if ($fix) {
             $phpcsFile->fixer->beginChangeset();
             $endPointer = $phpcsFile->findNext(T_SEMICOLON, $usePointer) + 1;
             for ($i = $usePointer; $i <= $endPointer; $i++) {
                 $phpcsFile->fixer->replaceToken($i, '');
             }
             $phpcsFile->fixer->endChangeset();
         }
     }
 }
All Usage Examples Of SlevomatCodingStandard\Helpers\StringHelper::startsWith