Skip to content

Commit

Permalink
Support relative paths in extension-installer
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Dec 13, 2020
1 parent 8032d2e commit 0e306c6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ parameters:
count: 1
path: src/Analyser/MutatingScope.php

-
message: "#^Parameter \\#1 \\$argument of class ReflectionClass constructor expects class\\-string\\<PHPStan\\\\ExtensionInstaller\\\\GeneratedConfig\\>\\|PHPStan\\\\ExtensionInstaller\\\\GeneratedConfig, string given\\.$#"
count: 1
path: src/Command/CommandHelper.php

-
message: "#^Parameter \\#1 \\$path of function dirname expects string, string\\|false given\\.$#"
count: 1
path: src/Command/CommandHelper.php

-
message: "#^Anonymous function has an unused use \\$container\\.$#"
count: 2
Expand Down
14 changes: 13 additions & 1 deletion src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,25 @@ public static function begin(
}

if (class_exists('PHPStan\ExtensionInstaller\GeneratedConfig')) {
$generatedConfigReflection = new \ReflectionClass('PHPStan\ExtensionInstaller\GeneratedConfig');
$generatedConfigDirectory = dirname($generatedConfigReflection->getFileName());
foreach (\PHPStan\ExtensionInstaller\GeneratedConfig::EXTENSIONS as $name => $extensionConfig) {
foreach ($extensionConfig['extra']['includes'] ?? [] as $includedFile) {
if (!is_string($includedFile)) {
$errorOutput->writeLineFormatted(sprintf('Cannot include config from package %s, expecting string file path but got %s', $name, gettype($includedFile)));
throw new \PHPStan\Command\InceptionNotSuccessfulException();
}
$includedFilePath = sprintf('%s/%s', $extensionConfig['install_path'], $includedFile);
$includedFilePath = null;
if (isset($extensionConfig['relative_install_path'])) {
$includedFilePath = sprintf('%s/%s/%s', $generatedConfigDirectory, $extensionConfig['relative_install_path'], $includedFile);
if (!file_exists($includedFilePath) || !is_readable($includedFilePath)) {
$includedFilePath = null;
}
}

if ($includedFilePath === null) {
$includedFilePath = sprintf('%s/%s', $extensionConfig['install_path'], $includedFile);
}
if (!file_exists($includedFilePath) || !is_readable($includedFilePath)) {
$errorOutput->writeLineFormatted(sprintf('Config file %s does not exist or isn\'t readable', $includedFilePath));
throw new \PHPStan\Command\InceptionNotSuccessfulException();
Expand Down

0 comments on commit 0e306c6

Please sign in to comment.