Skip to content

Commit

Permalink
fixed PHPStan errors on level 7
Browse files Browse the repository at this point in the history
  • Loading branch information
llaville committed Jul 31, 2024
1 parent 5feb7ff commit 2c1e51b
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/linters/phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
parameters:
level: 6
level: 7
paths:
- ../../src/
1 change: 1 addition & 0 deletions src/Composer/DefaultStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function build(ManifestOptions $options): ?string
{
$factory = $this->factory;

/** @var string $rawFormat */
$rawFormat = $options->getFormat(true);
$format = $options->getFormat();
$outputFile = $options->getOutputFile();
Expand Down
1 change: 1 addition & 0 deletions src/Composer/Manifest/ConsoleTextManifestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function __invoke(array $content): string
$prefix = '<comment>uses</comment>';
}
$installedPhp['versions'][$req]['prefix'] = $prefix;
/** @var string $constraint */
if ('php' === $req) {
$entries[] = [sprintf('%s%s %s', $prefix, $category, "$req $constraint"), phpversion()];
} elseif (str_starts_with($req, 'ext-')) {
Expand Down
1 change: 1 addition & 0 deletions src/Composer/Manifest/DecorateTextManifestBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function __invoke(array $content): string
$prefix .= 'uses';
}
$installedPhp['versions'][$req]['prefix'] = $prefix;
/** @var string $constraint */
if ('php' === $req) {
$entries[] = sprintf('%s%s %s: <info>%s</info>', $prefix, $category, "$req $constraint", phpversion());
} elseif (str_starts_with($req, 'ext-')) {
Expand Down
1 change: 1 addition & 0 deletions src/Composer/ManifestOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function getFormat(bool $raw = false): string|null|ManifestFormat

public function getFormatDisplay(): string
{
// @phpstan-ignore return.type
return match ($this->getFormat()) {
ManifestFormat::auto => 'AUTO detection mode',
ManifestFormat::plain, ManifestFormat::ansi, ManifestFormat::console => 'TEXT',
Expand Down
11 changes: 9 additions & 2 deletions src/Composer/PostInstallStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public static function postUpdate(Event $event): void

// checks if BOX config file declared exists
if (!empty($configFilePath) && file_exists($configFilePath)) {
$configFilePath = realpath($configFilePath);
$configFilePath = realpath($configFilePath) ? : null;
} else {
// otherwise, try with root base dir package and "box.json.dist" BOX config file
$configFilePath = dirname($vendorDir) . '/box.json.dist';
Expand Down Expand Up @@ -101,7 +101,14 @@ public static function postUpdate(Event $event): void
$boxIO = new IO($arrayInput, new NullOutput());
$manifest = $strategy->build(new ManifestOptions($boxIO));

$stream = new StreamOutput(fopen($source, 'w'));
$resource = fopen($source, 'w');
if (!$resource) {
$message = sprintf('- Unable to write manifest to file "<comment>%s</comment>"', realpath($source));
$io->writeError($message);
continue;
}

$stream = new StreamOutput($resource);
$stream->setDecorated($io->isDecorated());
$stream->write($manifest);
fclose($stream->getStream());
Expand Down
1 change: 1 addition & 0 deletions src/Console/Command/ManifestBuild.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$io->writeln($manifest);
$message = 'Writing results to standard output';
} else {
// @phpstan-ignore argument.type
$stream = new StreamOutput(fopen($outputFile, 'w'));
if (ManifestFormat::ansi === $format) {
$stream->setDecorated(true);
Expand Down
2 changes: 2 additions & 0 deletions src/Console/Command/ManifestStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$configPath = $config->getConfigurationFile();

if ($configPath) {
/** @var null|non-empty-string $shebang */
$shebang = $config->getShebang();

$banner = $config->getStubBannerContents();
Expand Down Expand Up @@ -143,6 +144,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln($stub);
$message = 'Writing stub code to standard output';
} else {
// @phpstan-ignore argument.type
$stream = new StreamOutput(fopen($outputFile, 'w'));
$stream->write($stub);
fclose($stream->getStream());
Expand Down
4 changes: 2 additions & 2 deletions src/Helper/ManifestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function get(array $resources): ?string
$resolved = realpath($resource) ?: (file_exists($resource) ? $resource : null);
}
if ($resolved) {
return file_get_contents($resolved);
return file_get_contents($resolved) ?: null;
}
}

Expand All @@ -81,7 +81,7 @@ public function get(array $resources): ?string
* @param string[]|null $resources
* @param string[][]|null $mapFiles
*/
public function getStubGenerator(string $templatePath = null, array $resources = null, array $mapFiles = null): object
public function getStubGenerator(string $templatePath = null, array $resources = null, array $mapFiles = null): StubGenerator
{
if (null === $templatePath) {
$templatePath = dirname(__DIR__, 2) . '/resources/default_stub.template';
Expand Down
4 changes: 4 additions & 0 deletions src/StubGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function __construct(
}

$template = file_get_contents($templatePath);
// @phpstan-ignore argument.type
$template = ltrim($template, "<?php\n");

$this->stubTemplate = str_replace(
Expand All @@ -48,6 +49,9 @@ public function __construct(
);
}

/**
* @param null|non-empty-string $shebang The shebang line
*/
public function generateStub(
?string $alias = null,
?string $banner = null,
Expand Down

0 comments on commit 2c1e51b

Please sign in to comment.