当前位置: 首页>>代码示例>>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;未经允许,请勿转载。