Skip to content

Commit

Permalink
fix PHPStan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Dec 2, 2024
1 parent 761d99a commit c13e854
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/Helper/BoxConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use function file_exists;
use function getcwd;
use function is_bool;
use function is_string;
use function realpath;

/**
Expand Down Expand Up @@ -86,19 +87,26 @@ public function __construct(
}

// @link https://box-project.github.io/box/configuration/#base-path-base-path
$assocConfig[self::BASE_PATH_KEY] = $this->retrieveBasePath($this->configPath, $assocConfig);
// @phpstan-ignore-next-line
$assocConfig[self::BASE_PATH_KEY] = $this->retrieveBasePath($this->configPath, $assocConfig) ?: '.';

$composerJsonPath = $assocConfig[self::BASE_PATH_KEY] . '/composer.json';

if (file_exists($composerJsonPath)) {
/** @var array<string, mixed> $decodedComposerJson */
$decodedComposerJson = $json->decodeFile($composerJsonPath, true);
$firstBin = current((array) ($decodedComposerJson['bin'] ?? []));
}


$main = $assocConfig[self::MAIN_KEY] ?? null;

// @link https://box-project.github.io/box/configuration/#main-main
if (false !== $assocConfig[self::MAIN_KEY]) {
if (false !== $main) {
$assocConfig[self::MAIN_KEY] = $this->retrieveMainScriptPath(
// @phpstan-ignore argument.type
$assocConfig,
// @phpstan-ignore argument.type
$firstBin ?? null
);
}
Expand Down Expand Up @@ -169,7 +177,7 @@ private function getConfigPath(IO $io): ?string
/**
* @param array{base-path?: string|null} $assocConfig
*/
private function retrieveBasePath(?string $file, array $assocConfig): string
private function retrieveBasePath(?string $file, array $assocConfig): false|string
{
if (null === $file) {
return getcwd();
Expand All @@ -179,7 +187,13 @@ private function retrieveBasePath(?string $file, array $assocConfig): string
return realpath(dirname($file));
}

$basePath = trim($assocConfig[self::BASE_PATH_KEY]);
$basePath = $assocConfig[self::BASE_PATH_KEY];

if (!is_string($basePath)) {
return false;
}

$basePath = trim($basePath);

Assert::directory(
$basePath,
Expand Down Expand Up @@ -228,5 +242,4 @@ private function normalizePath(string $file, string $basePath): string
{
return Path::makeAbsolute(trim($file), $basePath);
}

}

0 comments on commit c13e854

Please sign in to comment.