當前位置: 首頁>>代碼示例>>PHP>>正文


PHP File::getMemberProperties方法代碼示例

本文整理匯總了PHP中PHP_CodeSniffer\Files\File::getMemberProperties方法的典型用法代碼示例。如果您正苦於以下問題:PHP File::getMemberProperties方法的具體用法?PHP File::getMemberProperties怎麽用?PHP File::getMemberProperties使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PHP_CodeSniffer\Files\File的用法示例。


在下文中一共展示了File::getMemberProperties方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: processMemberVar

 /**
  * Processes class member variables.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token
  *                                        in the stack passed in $tokens.
  *
  * @return void
  */
 protected function processMemberVar(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $memberProps = $phpcsFile->getMemberProperties($stackPtr);
     if (empty($memberProps) === true) {
         return;
     }
     $memberName = ltrim($tokens[$stackPtr]['content'], '$');
     $scope = $memberProps['scope'];
     $scopeSpecified = $memberProps['scope_specified'];
     if ($memberProps['scope'] === 'private') {
         $isPublic = false;
     } else {
         $isPublic = true;
     }
     // If it's a private member, it must have an underscore on the front.
     if ($isPublic === false && $memberName[0] !== '_') {
         $error = 'Private member variable "%s" must be prefixed with an underscore';
         $data = array($memberName);
         $phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $data);
         return;
     }
     // If it's not a private member, it must not have an underscore on the front.
     if ($isPublic === true && $scopeSpecified === true && $memberName[0] === '_') {
         $error = '%s member variable "%s" must not be prefixed with an underscore';
         $data = array(ucfirst($scope), $memberName);
         $phpcsFile->addError($error, $stackPtr, 'PublicUnderscore', $data);
         return;
     }
 }
開發者ID:thekabal,項目名稱:tki,代碼行數:39,代碼來源:ValidVariableNameSniff.php

示例2: processMemberVar

 /**
  * Processes class member variables.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token in the
  *                                        stack passed in $tokens.
  *
  * @return void
  */
 protected function processMemberVar(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $varName = ltrim($tokens[$stackPtr]['content'], '$');
     $memberProps = $phpcsFile->getMemberProperties($stackPtr);
     $public = $memberProps['scope'] === 'public';
     if ($public === true) {
         if (substr($varName, 0, 1) === '_') {
             $error = 'Public member variable "%s" must not contain a leading underscore';
             $data = array($varName);
             $phpcsFile->addError($error, $stackPtr, 'PublicHasUnderscore', $data);
             return;
         }
     } else {
         if (substr($varName, 0, 1) !== '_') {
             $scope = ucfirst($memberProps['scope']);
             $error = '%s member variable "%s" must contain a leading underscore';
             $data = array($scope, $varName);
             $phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $data);
             return;
         }
     }
     if (Common::isCamelCaps($varName, false, $public, false) === false) {
         $error = 'Member variable "%s" is not in valid camel caps format';
         $data = array($varName);
         $phpcsFile->addError($error, $stackPtr, 'MemberVarNotCamelCaps', $data);
     } else {
         if (preg_match('|\\d|', $varName) === 1) {
             $warning = 'Member variable "%s" contains numbers but this is discouraged';
             $data = array($varName);
             $phpcsFile->addWarning($warning, $stackPtr, 'MemberVarContainsNumbers', $data);
         }
     }
 }
開發者ID:thekabal,項目名稱:tki,代碼行數:43,代碼來源:ValidVariableNameSniff.php

示例3: processMemberVar

 /**
  * Processes class member variables.
  *
  * @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
  * @param int                  $stackPtr  The position of the current token in the
  *                                        stack passed in $tokens.
  *
  * @return void
  */
 protected function processMemberVar(File $phpcsFile, $stackPtr)
 {
     $tokens = $phpcsFile->getTokens();
     $varName = ltrim($tokens[$stackPtr]['content'], '$');
     $memberProps = $phpcsFile->getMemberProperties($stackPtr);
     if (empty($memberProps) === true) {
         // Couldn't get any info about this variable, which
         // generally means it is invalid or possibly has a parse
         // error. Any errors will be reported by the core, so
         // we can ignore it.
         return;
     }
     $public = $memberProps['scope'] !== 'private';
     $errorData = array($varName);
     if ($public === true) {
         if (substr($varName, 0, 1) === '_') {
             $error = '%s member variable "%s" must not contain a leading underscore';
             $data = array(ucfirst($memberProps['scope']), $errorData[0]);
             $phpcsFile->addError($error, $stackPtr, 'PublicHasUnderscore', $data);
             return;
         }
     } else {
         if (substr($varName, 0, 1) !== '_') {
             $error = 'Private member variable "%s" must contain a leading underscore';
             $phpcsFile->addError($error, $stackPtr, 'PrivateNoUnderscore', $errorData);
             return;
         }
     }
     if (Common::isCamelCaps($varName, false, $public, false) === false) {
         $error = 'Member variable "%s" is not in valid camel caps format';
         $phpcsFile->addError($error, $stackPtr, 'MemberNotCamelCaps', $errorData);
     }
 }
開發者ID:thekabal,項目名稱:tki,代碼行數:42,代碼來源:ValidVariableNameSniff.php


注:本文中的PHP_CodeSniffer\Files\File::getMemberProperties方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。