You are here

public static function Project::getCoreVersion in Coder 8.3.x

Same name and namespace in other branches
  1. 8.3 coder_sniffer/DrupalPractice/Project.php \DrupalPractice\Project::getCoreVersion()
  2. 8.2 coder_sniffer/DrupalPractice/Project.php \DrupalPractice\Project::getCoreVersion()

Determines the Drupal core version a file might be associated with.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:

Return value

int The core version number. Returns 8 by default.

10 calls to Project::getCoreVersion()
ClassFileNameSniff::process in coder_sniffer/Drupal/Sniffs/Classes/ClassFileNameSniff.php
Processes this test, when one of its tokens is encountered.
DbQuerySniff::processFunctionCall in coder_sniffer/DrupalPractice/Sniffs/FunctionCalls/DbQuerySniff.php
Processes this function call.
DisallowLongArraySyntaxSniff::process in coder_sniffer/Drupal/Sniffs/Arrays/DisallowLongArraySyntaxSniff.php
Processes this test, when one of its tokens is encountered.
GetRequestDataSniff::process in coder_sniffer/DrupalPractice/Sniffs/Variables/GetRequestDataSniff.php
Processes this test, when one of its tokens is encountered.
GlobalConstantSniff::process in coder_sniffer/DrupalPractice/Sniffs/Constants/GlobalConstantSniff.php
Processes this test, when one of its tokens is encountered.

... See full list

File

coder_sniffer/DrupalPractice/Project.php, line 248

Class

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

Namespace

DrupalPractice

Code

public static function getCoreVersion(File $phpcsFile) {

  // First check if a config option was passed.
  $coreVersion = Config::getConfigData('drupal_core_version');
  if (empty($coreVersion) === false) {
    return (int) $coreVersion;
  }

  // Try to guess the core version from info files in the file path.
  $infoFile = static::getInfoFile($phpcsFile);
  if ($infoFile === false) {

    // Default to Drupal 8.
    return 8;
  }
  $pathParts = pathinfo($infoFile);

  // Drupal 6 and 7 use the .info file extension.
  if ($pathParts['extension'] === 'info') {
    $infoSettings = ClassFilesSniff::drupalParseInfoFormat(file_get_contents($infoFile));
    if (isset($infoSettings['core']) === true && is_string($infoSettings['core']) === true) {
      return (int) $infoSettings['core'][0];
    }

    // Default to Drupal 7 if there is an info file.
    return 7;
  }

  // Drupal 8 uses the .yml file extension.
  // @todo Revisit for Drupal 9, but I don't want to do YAML parsing
  // for now.
  return 8;
}