You are here

protected function DeprecationAnalyzer::createModifiedNeonFile in Upgrade Status 8.3

Same name and namespace in other branches
  1. 8.2 src/DeprecationAnalyzer.php \Drupal\upgrade_status\DeprecationAnalyzer::createModifiedNeonFile()

Creates the final config file in the temporary directory.

Throws

\Exception If the PHPStan configuration file cannot be written.

1 call to DeprecationAnalyzer::createModifiedNeonFile()
DeprecationAnalyzer::initEnvironment in src/DeprecationAnalyzer.php
Initialize the external environment.

File

src/DeprecationAnalyzer.php, line 579

Class

DeprecationAnalyzer

Namespace

Drupal\upgrade_status

Code

protected function createModifiedNeonFile() {
  $module_path = DRUPAL_ROOT . '/' . drupal_get_path('module', 'upgrade_status');
  $config = file_get_contents($module_path . '/deprecation_testing_template.neon');
  $config = str_replace('parameters:', "parameters:\n\ttmpDir: '" . $this->temporaryDirectory . '/phpstan' . "'\n" . "\tdrupal:\n\t\tdrupal_root: '" . DRUPAL_ROOT . "'", $config);
  if (!class_exists('PHPStan\\ExtensionInstaller\\GeneratedConfig')) {
    $extension_neon = $this->vendorPath . '/mglaman/phpstan-drupal/extension.neon';
    $rules_neon = $this->vendorPath . '/phpstan/phpstan-deprecation-rules/rules.neon';
    if (!file_exists($extension_neon) || !file_exists($rules_neon)) {
      throw new \Exception('Vendor source files were not found. You may need to configure a vendor-dir in composer.json. See https://getcomposer.org/doc/06-config.md#vendor-dir. Missing ' . $extension_neon . ' and ' . $rules_neon . '.');
    }
    $config .= "\nincludes:\n\t- '" . $extension_neon . "'\n\t- '" . $rules_neon . "'\n";
  }
  $success = file_put_contents($this->phpstanNeonPath, $config);
  if (!$success) {
    throw new \Exception('Unable to write configuration for PHPStan to ' . $this->phpstanNeonPath . '.');
  }
}