Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Project.php

function 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.

2 calls to Project::getInfoFile()
Project::getCoreVersion in vendor/drupal/coder/coder_sniffer/DrupalPractice/Project.php
Determines the Drupal core version a file might be associated with.
Project::getName in vendor/drupal/coder/coder_sniffer/DrupalPractice/Project.php
Determines the project short name a file might be associated with.

File

vendor/drupal/coder/coder_sniffer/DrupalPractice/Project.php, line 78

Class

Project
Helper class to retrieve project information like module/theme name for a file.

Namespace

DrupalPractice

Code

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");
        }
        // Filter out directories.
        $infoFiles = array_filter($infoFiles, 'is_file');
        // 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, [
        __NAMESPACE__ . '\\Project',
        'compareLength',
    ]);
    $infoFile = $infoFiles[0];
    $cache[$phpcsFile->getFilename()] = $infoFile;
    return $infoFile;
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal