本文整理汇总了PHP中PHP_CodeSniffer_File::getFilename方法的典型用法代码示例。如果您正苦于以下问题:PHP PHP_CodeSniffer_File::getFilename方法的具体用法?PHP PHP_CodeSniffer_File::getFilename怎么用?PHP PHP_CodeSniffer_File::getFilename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PHP_CodeSniffer_File
的用法示例。
在下文中一共展示了PHP_CodeSniffer_File::getFilename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param integer $stackPtr The position of the current token in the
* stack passed in $tokens.
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$decName = $phpcsFile->findNext(T_STRING, $stackPtr);
$fileName = dirname($phpcsFile->getFilename());
$GnPosition = strrpos($fileName, DIRECTORY_SEPARATOR . 'GN');
if (false === $GnPosition) {
return;
}
$fileName = substr($fileName, $GnPosition + 1);
$fileName .= DIRECTORY_SEPARATOR . basename($phpcsFile->getFilename());
$fileName = substr($fileName, 0, strrpos($fileName, '.'));
$className = $fileName;
$className = substr($className, strpos($className, '_'));
$className = substr($className, strpos($className, DIRECTORY_SEPARATOR) + 1);
$fileName = str_replace(DIRECTORY_SEPARATOR, '_', $fileName);
$className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
if (strpos($fileName, '__') === false) {
$className = $fileName;
}
if ($tokens[$decName]['content'] !== $fileName and $tokens[$decName]['content'] !== $className) {
$name = ucfirst($tokens[$stackPtr]['content']);
$file .= '"' . $tokens[$stackPtr]['content'] . ' ' . $className . '".';
$phpcsFile->addEvent('MATCH_CLASS_NAME', array('name' => $name, 'file' => $file), $stackPtr);
}
}
示例2: getInfoFile
/**
* Determines the info file a file might be associated with.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
*
* @return string|false The project info file name or false if it could not
* be derived.
*/
public static function getInfoFile(PHP_CodeSniffer_File $phpcsFile)
{
// Cache the project name per file as this might get called often.
static $cache;
if (isset($cache[$phpcsFile->getFilename()]) === true) {
return $cache[$phpcsFile->getFilename()];
}
$pathParts = pathinfo($phpcsFile->getFilename());
// Search for an info file.
$dir = $pathParts['dirname'];
do {
$infoFiles = glob("{$dir}/*.info.yml");
if (empty($infoFiles) === true) {
$infoFiles = glob("{$dir}/*.info");
}
// Go one directory up if we do not find an info file here.
$dir = dirname($dir);
} while (empty($infoFiles) && $dir != dirname($dir));
// No info file found, so we give up.
if (empty($infoFiles) === true) {
$cache[$phpcsFile->getFilename()] = false;
return false;
}
// Sort the info file names and take the shortest info file.
usort($infoFiles, array('DrupalPractice_Project', 'compareLength'));
$infoFile = $infoFiles[0];
$cache[$phpcsFile->getFilename()] = $infoFile;
return $infoFile;
}
示例3: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @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
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// We want to run this method only once per file, so we remember if this has
// been called already.
static $called = array();
if (isset($called[$phpcsFile->getFilename()]) === false) {
$called[$phpcsFile->getFilename()] = true;
// Retrieve the raw file content, as the tokens do not work consistently
// for different file types (CSS and javascript files have additional
// artifical tokens at the end for example).
$filename = $phpcsFile->getFilename();
// file_get_contents requires a file path, but some programs will pass
// in info via STDIN. Change the filename to something file_get_contents
// will understand.
if ($filename == 'STDIN') {
$filename = 'php://stdin';
}
$content = file_get_contents($filename);
$error = false;
$lastChar = substr($content, -1);
// There must be a \n character at the end of the last token.
if ($lastChar !== $phpcsFile->eolChar) {
$error = true;
} else {
if (substr($content, -2, 1) === $phpcsFile->eolChar) {
$error = true;
}
}
if ($error === true) {
$error = 'Files must end in a single new line character';
$phpcsFile->addError($error, $phpcsFile->numTokens - 1, 'FileEnd');
}
}
//end if
}
示例4: process
/**
* Processes php files and looks for MOODLE_INTERNAL or config.php
* inclusion.
*
* @param PHP_CodeSniffer_File $file The file being scanned.
* @param int $pointer The position in the stack.
*/
public function process(PHP_CodeSniffer_File $file, $pointer)
{
// Special dispensation for behat files.
if (basename(dirname($file->getFilename())) === 'behat') {
return;
}
// Special dispensation for lang files.
if (basename(dirname(dirname($file->getFilename()))) === 'lang') {
return;
}
// We only want to do this once per file.
$prevopentag = $file->findPrevious(T_OPEN_TAG, $pointer - 1);
if ($prevopentag !== false) {
return;
}
// Find where real code is and check from there.
$pointer = $this->get_position_of_relevant_code($file, $pointer);
// OK, we've got to the first bit of relevant code.
if ($this->is_moodle_internal_or_die_check($file, $pointer)) {
// There is a MOODLE_INTERNAL check. This file is good, hurrah!
return;
}
if ($this->is_config_php_incluson($file, $pointer)) {
// We are requiring config.php. This file is good, hurrah!
return;
}
if ($this->is_if_not_moodle_internal_die_check($file, $pointer)) {
// It's an old-skool MOODLE_INTERNAL check. This file is good, hurrah!
return;
}
// Got here because, so something is not right.
$file->addWarning('Expected MOODLE_INTERNAL check or config.php inclusion', $pointer);
}
示例5: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param integer $stackPtr The position of the current token in the
* stack passed in $tokens.
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$decName = $phpcsFile->findNext(T_STRING, $stackPtr);
$fileName = dirname($phpcsFile->getFilename());
$GnPosition = strrpos($fileName, DIRECTORY_SEPARATOR . 'GN');
if (false === $GnPosition) {
return;
}
$fileName = substr($fileName, $GnPosition + 1);
$fileName .= DIRECTORY_SEPARATOR . basename($phpcsFile->getFilename());
$fileName = substr($fileName, 0, strrpos($fileName, '.'));
$className = $fileName;
$className = substr($className, strpos($className, '_'));
$className = substr($className, strpos($className, DIRECTORY_SEPARATOR) + 1);
$fileName = str_replace(DIRECTORY_SEPARATOR, '_', $fileName);
$className = str_replace(DIRECTORY_SEPARATOR, '_', $className);
if (strpos($fileName, '__') === false) {
$className = $fileName;
}
if ($tokens[$decName]['content'] !== $fileName and $tokens[$decName]['content'] !== $className) {
$name = ucfirst($tokens[$stackPtr]['content']);
$file .= '"' . $tokens[$stackPtr]['content'] . ' ' . $className . '".';
$error = "La classe (ou interface) {$name} ne doit pas être different du nom de fichier source {$file}" . $phpcsFile->addError($error, $stackPtr, 'FilenameMatchClassname');
}
}
示例6: processFunction
/**
* Process this function definition.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the function name in the stack.
* name in the stack.
* @param int $functionPtr The position of the function keyword in the stack.
* keyword in the stack.
*
* @return void
*/
public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr)
{
$fileExtension = strtolower(substr($phpcsFile->getFilename(), -7));
// Only check in *.install files.
if ($fileExtension !== 'install') {
return;
}
$fileName = substr(basename($phpcsFile->getFilename()), 0, -8);
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['content'] !== $fileName . '_install' && $tokens[$stackPtr]['content'] !== $fileName . '_requirements') {
return;
}
// This check only applies to Drupal 7, not Drupal 8.
if (DrupalPractice_Project::getCoreVersion($phpcsFile) !== '7.x') {
return;
}
// Search in the function body for t() calls.
$string = $phpcsFile->findNext(T_STRING, $tokens[$functionPtr]['scope_opener'], $tokens[$functionPtr]['scope_closer']);
while ($string !== false) {
if ($tokens[$string]['content'] === 't' || $tokens[$string]['content'] === 'st') {
$opener = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $string + 1, null, true);
if ($opener !== false && $tokens[$opener]['code'] === T_OPEN_PARENTHESIS) {
$error = 'Do not use t() or st() in installation phase hooks, use $t = get_t() to retrieve the appropriate localization function name';
$phpcsFile->addError($error, $string, 'TranslationFound');
}
}
$string = $phpcsFile->findNext(T_STRING, $string + 1, $tokens[$functionPtr]['scope_closer']);
}
//end while
}
示例7: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param integer $stackPtr The position of the current token in the stack passed in $tokens.
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
if (isset($this->_processed[$phpcsFile->getFilename()])) {
return;
}
$filename = $phpcsFile->getFilename();
$this->_uses = array();
$next = $stackPtr;
while ($next !== false) {
$this->_checkUseToken($phpcsFile, $next);
$next = $phpcsFile->findNext(T_USE, $next + 1);
}
// Prevent multiple uses in the same file from entering
$this->_processed[$phpcsFile->getFilename()] = true;
foreach ($this->_uses as $scope => $used) {
$defined = $sorted = array_keys($used);
natcasesort($sorted);
$sorted = array_values($sorted);
if ($sorted === $defined) {
continue;
}
foreach ($defined as $i => $name) {
if ($name !== $sorted[$i]) {
$error = 'Use classes must be in alphabetical order.';
$phpcsFile->addError($error, $used[$name], 'UseInAlphabeticalOrder', array());
}
}
}
}
示例8: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @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
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// If short open tags are off, then any short open tags will be converted
// to inline_html tags so we can just ignore them.
// If its on, then we want to ban the use of them.
$option = ini_get('short_open_tag');
// Ini_get returns a string "0" if short open tags is off.
if ($option === '0') {
return;
}
if (!isset($this->files_cache[$phpcsFile->getFilename()]) && !$phpcsFile->findNext(T_OPEN_TAG, $stackPtr + 1) && !$phpcsFile->findNext(T_OPEN_TAG_WITH_ECHO, $stackPtr + 1) && $phpcsFile->findNext(T_CLOSE_TAG, $stackPtr)) {
$error = 'Файл имеет только один открывающий PHP-тэг, но имеет закрывающий PHP-тэг.';
$phpcsFile->addError($this->getReqPrefix('REQ.PHP.2.1.1') . $error, $stackPtr);
}
$this->files_cache[$phpcsFile->getFilename()] = true;
$tokens = $phpcsFile->getTokens();
$openTag = $tokens[$stackPtr];
if ($openTag['content'] === '<?') {
$error = 'Short PHP opening tag used. Found "' . $openTag['content'] . '" Expected "<?php".';
$phpcsFile->addError($this->getReqPrefix('REQ.PHP.2.1.2') . $error, $stackPtr);
}
if ($openTag['code'] === T_OPEN_TAG_WITH_ECHO) {
$nextVar = $tokens[$phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $stackPtr + 1, null, true)];
$error = 'Short PHP opening tag used with echo. Found "';
$error .= $openTag['content'] . ' ' . $nextVar['content'] . ' ..." but expected "<?php echo ' . $nextVar['content'] . ' ...".';
$phpcsFile->addError($this->getReqPrefix('REQ.PHP.2.1.2') . $error, $stackPtr);
}
}
示例9: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param integer $stackPtr The position of the current token in the stack passed in $tokens.
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
if (isset($this->_processed[$phpcsFile->getFilename()])) {
return;
}
$tokens = $phpcsFile->getTokens();
$isClosure = $phpcsFile->findPrevious(array(T_CLOSURE), $stackPtr - 1, null, false, null, true);
if ($isClosure) {
return;
}
// Only one USE declaration allowed per statement.
$next = $phpcsFile->findNext(array(T_COMMA, T_SEMICOLON), $stackPtr + 1);
if ($tokens[$next]['code'] === T_COMMA) {
$error = 'There must be one USE keyword per declaration';
$phpcsFile->addError($error, $stackPtr, 'MultipleDeclarations');
}
$uses = array();
$next = $stackPtr;
while (true) {
$content = '';
$end = $phpcsFile->findNext(array(T_SEMICOLON, T_OPEN_CURLY_BRACKET), $next);
$useTokens = array_slice($tokens, $next, $end - $next, true);
foreach ($useTokens as $index => $token) {
if ($token['code'] === T_STRING || $token['code'] === T_NS_SEPARATOR) {
$content .= $token['content'];
}
}
// Check for class scoping on use. Traits should be
// ordered independently.
$scope = 0;
if (!empty($token['conditions'])) {
$scope = key($token['conditions']);
}
$uses[$scope][$content] = $index;
$next = $phpcsFile->findNext(T_USE, $end);
if (!$next) {
break;
}
}
// Prevent multiple uses in the same file from entering
$this->_processed[$phpcsFile->getFilename()] = true;
$ordered = TRUE;
foreach ($uses as $scope => $used) {
$defined = $sorted = array_keys($used);
natcasesort($sorted);
$sorted = array_values($sorted);
if ($sorted === $defined) {
continue;
}
foreach ($defined as $i => $name) {
if ($name !== $sorted[$i]) {
$ordered = FALSE;
}
}
}
if (!$ordered) {
$error = 'Usings must be in alphabetical order';
$phpcsFile->addError($error, $stackPtr, 'UseInAlphabeticalOrder', array());
}
}
示例10: processFunction
/**
* Process this function definition.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the function name in the stack.
* name in the stack.
* @param int $functionPtr The position of the function keyword in the stack.
* keyword in the stack.
*
* @return void
*/
public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr)
{
$fileExtension = strtolower(substr($phpcsFile->getFilename(), -6));
// Only check in *.module files.
if ($fileExtension !== 'module') {
return;
}
$fileName = substr(basename($phpcsFile->getFilename()), 0, -7);
$tokens = $phpcsFile->getTokens();
if ($tokens[$stackPtr]['content'] !== $fileName . '_menu') {
return;
}
// Search in the function body for t() calls.
$string = $phpcsFile->findNext(T_STRING, $tokens[$functionPtr]['scope_opener'], $tokens[$functionPtr]['scope_closer']);
while ($string !== false) {
if ($tokens[$string]['content'] === 't') {
$opener = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, $string + 1, null, true);
if ($opener !== false && $tokens[$opener]['code'] === T_OPEN_PARENTHESIS) {
$error = 'Do not use t() in hook_menu()';
$phpcsFile->addError($error, $string, 'TFound');
}
}
$string = $phpcsFile->findNext(T_STRING, $string + 1, $tokens[$functionPtr]['scope_closer']);
}
//end while
}
示例11: process
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
if (false !== strpos($phpcsFile->getFilename(), 'model') || false !== strpos($phpcsFile->getFilename(), 'form') || false !== strpos($phpcsFile->getFilename(), 'filter')) {
return null;
}
$tokens = $phpcsFile->getTokens();
$className = $phpcsFile->findNext(T_STRING, $stackPtr);
$name = trim($tokens[$className]['content']);
// "op" prefix
if (0 !== strpos($name, 'op')) {
$error = ucfirst($tokens[$stackPtr]['content']) . ' name must begin with "op" prefix';
$phpcsFile->addError($error, $stackPtr);
}
// "Interface" suffix
if ($tokens[$stackPtr]['code'] === T_INTERFACE && !preg_match('/Interface$/', $name)) {
$error = ucfirst($tokens[$stackPtr]['content']) . ' name must end with "Interface"';
$phpcsFile->addError($error, $stackPtr);
}
// stripped prefix
if (0 === strpos($name, 'op')) {
$name = substr($name, 2);
}
if (!PHP_CodeSniffer::isCamelCaps($name, true, true, false)) {
$error = ucfirst($tokens[$stackPtr]['content']) . ' name is not in camel caps format';
$phpcsFile->addError($error, $stackPtr);
}
}
示例12: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @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
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
// Only run this sniff once per info file.
$end = count($phpcsFile->getTokens()) + 1;
$fileExtension = strtolower(substr($phpcsFile->getFilename(), -4));
if ($fileExtension !== 'info') {
return $end;
}
$tokens = $phpcsFile->getTokens();
$contents = file_get_contents($phpcsFile->getFilename());
$info = Drupal_Sniffs_InfoFiles_ClassFilesSniff::drupalParseInfoFormat($contents);
if (isset($info['name']) === false) {
$error = '"name" property is missing in the info file';
$phpcsFile->addError($error, $stackPtr, 'Name');
}
if (isset($info['description']) === false) {
$error = '"description" property is missing in the info file';
$phpcsFile->addError($error, $stackPtr, 'Description');
}
if (isset($info['core']) === false) {
$error = '"core" property is missing in the info file';
$phpcsFile->addError($error, $stackPtr, 'Core');
} else {
if ($info['core'] === '7.x' && isset($info['php']) === true && $info['php'] <= '5.2') {
$error = 'Drupal 7 core already requires PHP 5.2';
$ptr = Drupal_Sniffs_InfoFiles_ClassFilesSniff::getPtr('php', $info['php'], $phpcsFile);
$phpcsFile->addError($error, $ptr, 'D7PHPVersion');
}
}
return $end;
}
示例13: process
/**
* Processes this sniff, when one of its tokens is encountered.
*
* @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
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
if (in_array($phpcsFile->getFilename(), $this->visitedFiles)) {
return;
}
$encoding = mb_detect_encoding(file_get_contents($phpcsFile->getFilename()), 'UTF-8, ASCII, ISO-8859-1', true);
if ($encoding !== 'UTF-8') {
$error = 'Files must use UTF-8 character set; but ' . $encoding . ' found.';
$phpcsFile->addError($error, $stackPtr);
}
}
示例14: process
/**
* Processes this test, when one of its tokens is encountered.
*
* @param PHP_CodeSniffer_File $phpcsFile All the tokens found in the document.
* @param int $stackPtr The position of the current token in
* the stack passed in $tokens.
*
* @return void
*/
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
if ($this->currentFile !== $phpcsFile->getFilename()) {
$this->classCount = 0;
$this->currentFile = $phpcsFile->getFilename();
}
$this->classCount++;
if ($this->classCount > 1) {
$phpcsFile->addError('Multiple classes defined in a single file', $stackPtr);
}
return;
}
示例15: processFunction
/**
* Process this function definition.
*
* @param PHP_CodeSniffer_File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the function
* name in the stack.
* @param int $functionPtr The position of the function
* keyword in the stack.
*
* @return void
*/
public function processFunction(PHP_CodeSniffer_File $phpcsFile, $stackPtr, $functionPtr)
{
$fileExtension = strtolower(substr($phpcsFile->getFilename(), -6));
// Only check in *.module files.
if ($fileExtension !== 'module') {
return;
}
$tokens = $phpcsFile->getTokens();
$fileName = substr(basename($phpcsFile->getFilename()), 0, -7);
if ($tokens[$stackPtr]['content'] === $fileName . '_install' || $tokens[$stackPtr]['content'] === $fileName . '_uninstall' || $tokens[$stackPtr]['content'] === $fileName . '_requirements' || $tokens[$stackPtr]['content'] === $fileName . '_schema' || $tokens[$stackPtr]['content'] === $fileName . '_enable' || $tokens[$stackPtr]['content'] === $fileName . '_disable') {
$error = '%s() is an installation hook and must be declared in an install file';
$data = array($tokens[$stackPtr]['content']);
$phpcsFile->addError($error, $stackPtr, 'InstallHook', $data);
}
}