protected function DeprecationAnalyzer::findBinPath in Upgrade Status 8.2
Same name and namespace in other branches
- 8.3 src/DeprecationAnalyzer.php \Drupal\upgrade_status\DeprecationAnalyzer::findBinPath()
Finds bin-dir location.
This can be set in composer.json via `bin-dir` config and may not be inside vendor directory.
Return value
string Bin directory path if found.
Throws
\Exception
1 call to DeprecationAnalyzer::findBinPath()
- DeprecationAnalyzer::initEnvironment in src/
DeprecationAnalyzer.php - Initialize the external environment.
File
- src/
DeprecationAnalyzer.php, line 214
Class
Namespace
Drupal\upgrade_statusCode
protected function findBinPath() {
// The bin directory may be found inside the vendor directory.
if (file_exists($this->vendorPath . '/bin/phpstan')) {
return $this->vendorPath . '/bin';
}
else {
$attempted_paths = [
$this->vendorPath . '/bin/phpstan',
];
}
// See if we can locate a custom bin directory based on composer.json
// settings.
$composerFileName = trim(getenv('COMPOSER')) ?: 'composer.json';
$rootComposer = $this->finder
->getComposerRoot() . '/' . $composerFileName;
$json = json_decode(file_get_contents($rootComposer), TRUE);
if (is_null($json)) {
throw new \Exception('Unable to decode composer information from ' . $rootComposer);
}
if (is_array($json) && isset($json['config']['bin-dir'])) {
$binPath = $this->finder
->getComposerRoot() . '/' . $json['config']['bin-dir'];
if (file_exists($binPath . '/phpstan')) {
return $binPath;
}
else {
$attempted_paths[] = $binPath . '/phpstan';
}
}
// Bail here as continuing makes no sense.
throw new \Exception('Vendor binary path not correct or phpstan is not installed there. Did you install Upgrade Status with composer? Checked: ' . join(',', $attempted_paths));
}