public static function Project::getInfoFile in Coder 8.2
Same name and namespace in other branches
- 8.3 coder_sniffer/DrupalPractice/Project.php \DrupalPractice\Project::getInfoFile()
- 8.3.x coder_sniffer/DrupalPractice/Project.php \DrupalPractice\Project::getInfoFile()
Determines the info file a file might be associated with.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
Return value
string|false The project info file name or false if it could not be derived.
4 calls to Project::getInfoFile()
- Project::getCoreVersion in coder_sniffer/
DrupalPractice/ Project.php - Determines the Drupal core version a file might be associated with.
- Project::getName in coder_sniffer/
DrupalPractice/ Project.php - Determines the project short name a file might be associated with.
- ProjectUnitTest::testInfoFileDetection in coder_sniffer/
DrupalPractice/ Test/ ProjectDetection/ ProjectUnitTest.php - Tests the extending classes Sniff class.
- ProjectUnitTest::testInfoFileNestedDetection in coder_sniffer/
DrupalPractice/ Test/ ProjectDetection/ ProjectUnitTest.php - Tests the extending classes Sniff class.
File
- coder_sniffer/
DrupalPractice/ Project.php, line 72
Class
- Project
- Helper class to retrieve project information like module/theme name for a file.
Namespace
DrupalPracticeCode
public static function getInfoFile(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) === true && $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(
__NAMESPACE__ . '\\Project',
'compareLength',
));
$infoFile = $infoFiles[0];
$cache[$phpcsFile
->getFilename()] = $infoFile;
return $infoFile;
}