function Project::getName
Same name in this branch
- 11.1.x vendor/phpdocumentor/reflection-common/src/Project.php \phpDocumentor\Reflection\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 vendor/
drupal/ coder/ coder_sniffer/ DrupalPractice/ Sniffs/ General/ ClassNameSniff.php - Processes this test, when one of its tokens is encountered.
- FormAlterDocSniff::processFunction in vendor/
drupal/ coder/ coder_sniffer/ DrupalPractice/ Sniffs/ FunctionDefinitions/ FormAlterDocSniff.php - Process this function definition.
- VariableNameSniff::processFunctionCall in vendor/
drupal/ coder/ coder_sniffer/ DrupalPractice/ Sniffs/ General/ VariableNameSniff.php - Processes this function call.
File
-
vendor/
drupal/ coder/ coder_sniffer/ DrupalPractice/ Project.php, line 36
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 && in_array($pathParts['extension'], [
'install',
'module',
'profile',
'theme',
]) === true) {
$cache[$phpcsFile->getFilename()] = $pathParts['filename'];
return $pathParts['filename'];
}
$infoFile = static::getInfoFile($phpcsFile);
if ($infoFile === false) {
return false;
}
$pathParts = pathinfo($infoFile);
// Info files end in *.info.yml on Drupal 8 and *.info on Drupal 7.
$filename = $pathParts['filename'];
$filename = preg_replace('/\\.info$/', '', $filename);
$cache[$phpcsFile->getFilename()] = $filename;
return $filename;
}