本文整理汇总了PHP中PHP_CodeSniffer_File::getMemberProperties方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::getMemberProperties方法的具体用法?PHP PHP_CodeSniffer_File::getMemberProperties怎么用?PHP PHP_CodeSniffer_File::getMemberProperties使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer_File
的用法示例。
在下文中一共展示了PHP_CodeSniffer_File::getMemberProperties方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processMemberVar
/**
* @param PHP_CodeSniffer_File $phpcsFile
* @param int $stackPtr
* @return void
*/
protected function processMemberVar(PHP_CodeSniffer_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 {
// private
return;
// 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 (PHP_CodeSniffer::isCamelCaps($varName, FALSE, $public, FALSE) === FALSE) {
$error = 'Variable "%s" is not in valid camel caps format';
$data = array($varName);
$phpcsFile->addError($error, $stackPtr, 'MemberVarNotCamelCaps', $data);
}
}
示例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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// FIXME - incompatible with the "camel case" notation
return;
$tokens = $phpcsFile->getTokens();
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$isPublic = $memberProps['scope'] === 'private' ? false : true;
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
// If it's a private member, it must have an underscore on the front.
if ($isPublic === false && $memberName[0] !== '_') {
$error = "Private member variable \"{$memberName}\" must be prefixed with an underscore";
$phpcsFile->addError($this->getReqPrefix('?') . $error, $stackPtr);
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 = ucfirst($scope) . " member variable \"{$memberName}\" must not be prefixed with an underscore";
$phpcsFile->addError($this->getReqPrefix('?') . $error, $stackPtr);
return;
}
$this->processVariable($phpcsFile, $stackPtr);
}
示例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(PHP_CodeSniffer_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 ($varName === '_id') {
return;
}
// allow \MongoId()
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;
}
if (PHP_CodeSniffer::isCamelCaps($varName, false, true, false) === false) {
$error = 'Variable "%s" is not in valid camel caps format' . $varName;
$phpcsFile->addError($error, $stackPtr, 'MemberNotCamelCaps', $errorData);
}
}
示例4: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$isPublic = $memberProps['scope'] === 'private' ? false : true;
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
// Even if it's a private member, it must not have an underscore on the
// front.
if ($isPublic === false && $memberName[0] === '_') {
$error = "Private member variable \"{$memberName}\" must not be\n \tprefixed with an underscore - it is discouraged in PHP 5-specific code";
$phpcsFile->addError($error, $stackPtr);
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 = ucfirst($scope) . " member variable \"{$memberName}\" must not be\n prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
if (strpos($memberName, '_') !== false) {
$error = 'Class property %s should use lowerCamel naming without underscores';
$data = array($tokens[$stackPtr]['content']);
$phpcsFile->addError($error, $stackPtr, 'LowerCamelName', $data);
}
}
示例5: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$isPublic = $memberProps['scope'] === 'private' ? false : true;
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
// 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;
}
}
示例6: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$isPublic = $memberProps['scope'] === 'private' ? false : true;
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
// If it's a private member, it must have an underscore on the front.
/*if ($isPublic === false && $memberName{0} !== '_') {
$error = "Private member variable \"$memberName\" must be
prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}*/
// Even if it's a private member, it must have an underscore on the front.
if ($isPublic === false && $memberName[0] === '_') {
$error = "Private member variable \"{$memberName}\" must not be\n \tprefixed with an underscore - it is discouraged in PHP 5-specific code";
$phpcsFile->addError($error, $stackPtr);
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 = ucfirst($scope) . " member variable \"{$memberName}\" must not be\n prefixed with an underscore";
$phpcsFile->addError($error, $stackPtr);
return;
}
}
示例7: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$this->processVariableNameCheck($phpcsFile, $stackPtr, 'member ');
}
示例8: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
if (strpos($memberName, '_') !== false) {
$error = 'Class property %s should use lowerCamel naming without underscores';
$data = array($tokens[$stackPtr]['content']);
$phpcsFile->addError($error, $stackPtr, 'LowerCamelName', $data);
}
}
示例9: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$varName = ltrim($tokens[$stackPtr]['content'], '$');
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
$public = $memberProps['scope'] === 'public';
$private = $memberProps['scope'] === 'private';
if ($public === true) {
if (substr($varName, 0, 1) === '_') {
$error = 'Public member variable "%s" must not contain a leading underscore';
$data = [$varName];
$phpcsFile->addError($error, $stackPtr, 'PublicHasUnderscore', $data);
return;
}
} elseif ($private === true) {
if (substr($varName, 0, 2) === '__') {
$error = 'Private member variable "%s" must not contain two leading underscores';
$data = [$varName];
$phpcsFile->addError($error, $stackPtr, 'PrivateWithUnderscore', $data);
return;
}
$filename = $phpcsFile->getFilename();
if (strpos($filename, '/lib/Cake/') !== false) {
$warning = 'Private variable "%s" in CakePHP core is discouraged';
$data = [$varName];
$phpcsFile->addWarning($warning, $stackPtr, 'PrivateInCore', $data);
}
} else {
// protected var
if (substr($varName, 0, 1) == '_') {
$error = 'Protected member variable "%s" must not contain a leading underscore';
$data = [$varName];
$phpcsFile->addError($error, $stackPtr, 'ProtectedUnderscore', $data);
return;
}
}
$conditions = array_keys($tokens[$stackPtr]['conditions']);
$className = $phpcsFile->getDeclarationName(array_pop($conditions));
// Schema properties are allowed to not be CamelCase.
if (substr($className, -6) === 'Schema') {
return;
}
if ($this->isValidVar($varName, $public) === false) {
$error = 'Member variable "%s" is not in valid camel caps format';
$data = [$varName];
$phpcsFile->addError($error, $stackPtr, 'MemberVarNotCamelCaps', $data);
}
}
示例10: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$isPublic = $memberProps['scope'] === 'private' ? false : true;
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
// Detect if it is marked deprecated
$find = array(T_COMMENT, T_DOC_COMMENT, T_CLASS, T_FUNCTION, T_OPEN_TAG);
$tokens = $phpcsFile->getTokens();
$commentEnd = $phpcsFile->findPrevious($find, $stackPtr - 1);
if ($commentEnd !== false && $tokens[$commentEnd]['code'] === T_DOC_COMMENT) {
$commentStart = $phpcsFile->findPrevious(T_DOC_COMMENT, $commentEnd - 1, null, true) + 1;
$comment = $phpcsFile->getTokensAsString($commentStart, $commentEnd - $commentStart + 1);
try {
$this->commentParser = new PHP_CodeSniffer_CommentParser_FunctionCommentParser($comment, $phpcsFile);
$this->commentParser->parse();
} catch (PHP_CodeSniffer_CommentParser_ParserException $e) {
$line = $e->getLineWithinComment() + $commentStart;
$phpcsFile->addError($e->getMessage(), $line, 'FailedParse');
return;
}
$deprecated = $this->commentParser->getDeprecated();
$isDeprecated = !is_null($deprecated);
} else {
$isDeprecated = false;
}
// 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 ($isDeprecated === false && $isPublic === true && $scopeSpecified === true && $memberName[0] === '_') {
$error = '%s member variable "%s" must not be prefixed with an underscore';
$data = array(ucfirst($scope), $memberName);
// AJE Changed from error to warning.
$phpcsFile->addWarning($error, $stackPtr, 'PublicUnderscore', $data);
return;
}
}
示例11: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// get variable name and properties
$tokens = $phpcsFile->getTokens();
$varTk = $tokens[$stackPtr];
$varName = substr($varTk['content'], 1);
$varProps = $phpcsFile->getMemberProperties($stackPtr);
// check(s)
if (!$this->checkLowerCase($phpcsFile, $stackPtr, $varName)) {
return;
}
if (!$this->checkVisibilityPrefix($phpcsFile, $stackPtr, $varName, $varProps)) {
return;
}
if (!$this->checkLength($phpcsFile, $stackPtr, $varName)) {
return;
}
}
示例12: processMemberVar
protected function processMemberVar(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// copied code from parent class
$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;
}
// end of copied code
// always validate as if the member variable is public
$public = true;
$errorData = array($varName);
if (PHP_CodeSniffer::isCamelCaps($varName, false, $public, false) === false) {
$error = 'Variable "%s" is not in valid camel caps format';
$phpcsFile->addError($error, $stackPtr, 'MemberNotCamelCaps', $errorData);
}
}
示例13: processMemberVar
protected function processMemberVar(PHP_CodeSniffer_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;
}
}
}
示例14: 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(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$memberProps = $phpcsFile->getMemberProperties($stackPtr);
if (empty($memberProps) === true) {
return;
}
$memberName = ltrim($tokens[$stackPtr]['content'], '$');
$isPublic = $memberProps['scope'] === 'private' ? false : true;
$scope = $memberProps['scope'];
$scopeSpecified = $memberProps['scope_specified'];
/* In PHP5, there's no need for the underscore to label private
* methods. Instead, the underscore in Joomla is used to distinguish
* native table properties from derived properties.
*
// 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,
);
// AJE Changed from error to warning.
$phpcsFile->addWarning($error, $stackPtr, 'PublicUnderscore', $data);
return;
}
*/
}
示例15: processMemberVar
/**
* Processes class member variables.
*
* @param PHP_CodeSniffer_File $phpcs_file The file being scanned.
* @param int $stack_ptr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
protected function processMemberVar(PHP_CodeSniffer_File $phpcs_file, $stack_ptr)
{
$tokens = $phpcs_file->getTokens();
$var_name = ltrim($tokens[$stack_ptr]['content'], '$');
$member_props = $phpcs_file->getMemberProperties($stack_ptr);
if (empty($member_props) === 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;
}
$error_data = array($var_name);
if (!in_array($var_name, $this->whitelisted_mixed_case_member_var_names, true) && self::isSnakeCase($var_name) === false) {
$error = 'Member variable "%s" is not in valid snake_case format.';
$phpcs_file->addError($error, $stack_ptr, 'MemberNotSnakeCase', $error_data);
}
}