You are here

public function ProjectCollector::loadProject in Upgrade Rector 8

Returns a single extension based on type and machine name.

Parameters

string $type: One of 'module' or 'theme' or 'profile' to signify the type of the extension.

string $project_machine_name: Machine name for the extension.

Return value

\Drupal\Core\Extension\Extension A project if exists.

Throws

\InvalidArgumentException If the type was not one of the allowed ones.

\Drupal\Core\Extension\Exception\UnknownExtensionException If there was no extension with the given name.

File

src/ProjectCollector.php, line 195

Class

ProjectCollector
Collects projects collated for the purposes of upgrade rector.

Namespace

Drupal\upgrade_rector

Code

public function loadProject(string $type, string $project_machine_name) {
  if (!in_array($type, $this->allowedTypes)) {
    throw new InvalidArgumentException(sprintf('"%s" is not a valid type. Valid types are module, profile and theme.', $type));
  }
  if ($type === 'module') {
    return $this->moduleExtensionList
      ->get($project_machine_name);
  }
  if ($type === 'profile') {
    return $this->profileExtensionList
      ->get($project_machine_name);
  }
  return $this->themeExtensionList
    ->get($project_machine_name);
}