public static function Project::getName in Coder 8.2
Same name and namespace in other branches
- 8.3 coder_sniffer/DrupalPractice/Project.php \DrupalPractice\Project::getName()
- 8.3.x coder_sniffer/DrupalPractice/Project.php \DrupalPractice\Project::getName()
Determines the project short name a file might be associated with.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
Return value
string|false Returns the project machine name or false if it could not be derived.
3 calls to Project::getName()
- ClassNameSniff::process in coder_sniffer/
DrupalPractice/ Sniffs/ General/ ClassNameSniff.php - Processes this test, when one of its tokens is encountered.
- FormAlterDocSniff::processFunction in coder_sniffer/
DrupalPractice/ Sniffs/ FunctionDefinitions/ FormAlterDocSniff.php - Process this function definition.
- VariableNameSniff::processFunctionCall in coder_sniffer/
DrupalPractice/ Sniffs/ General/ VariableNameSniff.php - Processes this function call.
File
- coder_sniffer/
DrupalPractice/ Project.php, line 35
Class
- Project
- Helper class to retrieve project information like module/theme name for a file.
Namespace
DrupalPracticeCode
public static function getName(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());
// Module and install files are easy: they contain the project name in the
// file name.
if (isset($pathParts['extension']) === true && ($pathParts['extension'] === 'module' || $pathParts['extension'] === 'install')) {
$cache[$phpcsFile
->getFilename()] = $pathParts['filename'];
return $pathParts['filename'];
}
$infoFile = static::getInfoFile($phpcsFile);
if ($infoFile === false) {
return false;
}
$pathParts = pathinfo($infoFile);
$cache[$phpcsFile
->getFilename()] = $pathParts['filename'];
return $pathParts['filename'];
}