本文整理汇总了PHP中PHP_CodeSniffer::isUnderscoreName方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer::isUnderscoreName方法的具体用法?PHP PHP_CodeSniffer::isUnderscoreName怎么用?PHP PHP_CodeSniffer::isUnderscoreName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer
的用法示例。
在下文中一共展示了PHP_CodeSniffer::isUnderscoreName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
if (empty($tokens[$stackPtr]['conditions']) === true) {
$functionName = $phpcsFile->getDeclarationName($stackPtr);
if (false === strpos($phpcsFile->getFilename(), 'helper')) {
$error = 'Defining functions is NOT permitted expecting helper functions.';
$phpcsFile->addError($error, $stackPtr);
}
if (!PHP_CodeSniffer::isUnderscoreName($functionName)) {
$error = 'Function name must use underscores in accordance.' . $functionName;
$phpcsFile->addError($error, $stackPtr);
}
}
}
示例2: processPackage
/**
* Process the package tag.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
*
*/
protected function processPackage(PHP_CodeSniffer_File $phpcsFile, array $tags)
{
$tokens = $phpcsFile->getTokens();
foreach ($tags as $tag) {
if ($tokens[$tag + 2]['code'] !== T_DOC_COMMENT_STRING) {
// No content.
continue;
}
$namespace = $this->extractNamespace($phpcsFile);
$content = $tokens[$tag + 2]['content'];
if ($namespace !== $content) {
$phpcsFile->addError('Package name "%s" should be "%s"', $tag, 'InvalidPackage', [$content, $namespace]);
continue;
}
if (PHP_CodeSniffer::isUnderscoreName($content) === true) {
continue;
}
$newContent = str_replace(' ', '_', $content);
$newContent = trim($newContent, '_');
$newContent = preg_replace('/[^A-Za-z_]/', '', $newContent);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
if ($bit !== '') {
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
}
}
$error = 'Package name "%s" is not valid; consider "%s" instead';
$validName = trim($newName, '_');
$data = [$content, $validName];
$phpcsFile->addError($error, $tag, 'InvalidPackage', $data);
}
}
示例3: processSubpackage
/**
* Process the subpackage tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processSubpackage($errorPos)
{
$package = $this->commentParser->getSubpackage();
if ($package !== null) {
$content = $package->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
}
$validName = trim($newName, '_');
$error = "Subpackage name \"{$content}\" is not valid; consider \"{$validName}\" instead";
$this->currentFile->addError($error, $errorPos);
}
} else {
$error = '@subpackage tag must contain a name';
$this->currentFile->addError($error, $errorPos);
}
}
}
示例4: processSubpackage
/**
* Process the subpackage tag.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param array $tags The tokens for these tags.
*
* @return void
*/
protected function processSubpackage(PHP_CodeSniffer_File $phpcsFile, array $tags)
{
$tokens = $phpcsFile->getTokens();
foreach ($tags as $tag) {
if ($tokens[$tag + 2]['code'] !== T_DOC_COMMENT_STRING) {
// No content.
continue;
}
$content = $tokens[$tag + 2]['content'];
if (PHP_CodeSniffer::isUnderscoreName($content) === true) {
continue;
}
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
if ($bit !== '') {
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
}
}
$error = 'Subpackage name "%s" is not valid; consider "%s" instead';
$validName = trim($newName, '_');
$data = array($content, $validName);
$phpcsFile->addError($error, $tag, 'InvalidSubpackage', $data);
}
//end foreach
}
示例5: processSubpackage
/**
* The subpackage name must be camel-cased.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processSubpackage($errorPos)
{
$subpackage = $this->commentParser->getSubpackage();
if ($subpackage !== null) {
$content = $subpackage->getContent();
if (empty($content) === true) {
$error = 'Content missing for @subpackage tag in file comment';
$this->currentFile->addError($error, $errorPos);
} else {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
// Subpackage name must be properly camel-cased.
$nameBits = explode('_', $content);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
}
$validName = trim($newName, '_');
$error = "Subpackage name \"{$content}\" is not valid; ";
$error .= "consider \"{$validName}\" instead";
$this->currentFile->addError($error, $errorPos);
}
}
}
}
示例6: processSubpackage
/**
* Process the subpackage tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processSubpackage($errorPos)
{
$package = $this->commentParser->getSubpackage();
if ($package !== null) {
$content = $package->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
// $newContent = str_replace(' ', '_', $content);
// $nameBits = explode('_', $newContent);
// $firstBit = array_shift($nameBits);
// $newName = strtoupper($firstBit{0}).substr($firstBit, 1).'_';
// foreach ($nameBits as $bit) {
// $newName .= strtoupper($bit{0}).substr($bit, 1).'_';
// }
//
// $error = 'Subpackage name "%s" is not valid; consider "%s" instead';
// $validName = trim($newName, '_');
// $data = array(
// $content,
// $validName,
// );
// $this->currentFile->addError($error, $errorPos, 'InvalidSubpackage', $data);
}
} else {
$error = '@subpackage tag must contain a name';
$this->currentFile->addError($error, $errorPos, 'EmptySubpackage');
}
}
}
示例7: processSubpackage
/**
* Process the subpackage tag.
*
* @param int $errorPos The line number where the error occurs.
*
* @return void
*/
protected function processSubpackage($errorPos)
{
$package = $this->commentParser->getSubpackage();
if ($package !== null) {
$content = $package->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
// Ignore..
}
} else {
$error = '@subpackage tag must contain a name';
$this->currentFile->addError($error, $errorPos);
}
}
}//end processSubpackage()
示例8: checkSubpackage
/**
* check subpackage tag
*
* @param string $content Tag content
* @access protected
* @return array
* @since 1.0.0
*/
protected function checkSubpackage($content)
{
$result = array(true, $content);
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$result = array(false, $this->sanitazeUnderscoreName($content));
}
return $result;
}
示例9: getUses
/**
* Process the depreciated tag
*
* @return void
*/
public function getUses()
{
$uses = $this->commentParser->getUses();
if ($uses !== null) {
foreach ($uses as $use) {
$content = $use->getContent();
if ($content !== '') {
if (PHP_CodeSniffer::isUnderscoreName($content) !== true) {
$newContent = str_replace(' ', '_', $content);
$nameBits = explode('_', $newContent);
$firstBit = array_shift($nameBits);
$newName = strtoupper($firstBit[0]) . substr($firstBit, 1) . '_';
foreach ($nameBits as $bit) {
$newName .= strtoupper($bit[0]) . substr($bit, 1) . '_';
}
$validName = trim($newName, '_');
$error = "34Uses name \"{$content}\" is not valid; consider \"{$validName}\" instead";
$this->currentFile->addError($error, $errorPos, 'UsesNameClassComment');
}
} else {
$error = '35@uses tag must contain a name';
$this->currentFile->addError($error, $errorPos, 'UsesTagMustContainNameClassComment');
}
}
}
}