Skip to content

Commit

Permalink
Cleanup of phpstan-baseline.neon ignored errors
Browse files Browse the repository at this point in the history
  • Loading branch information
theimbender authored and alcohol committed Sep 18, 2023
1 parent f1e92c6 commit 501da22
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 369 deletions.
244 changes: 0 additions & 244 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,261 +1,17 @@
parameters:
ignoreErrors:
-
message: "#^Only booleans are allowed in &&, mixed given on the left side\\.$#"
count: 1
path: src/Builder/ArchiveBuilder.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 4
path: src/Builder/PackagesBuilder.php

-
message: "#^Dynamic call to static method Composer\\\\Json\\\\JsonFile\\:\\:encode\\(\\)\\.$#"
count: 1
path: src/Builder/PackagesBuilder.php

-
message: "#^Only booleans are allowed in an if condition, int\\<min, 2\\> given\\.$#"
count: 1
path: src/Builder/PackagesBuilder.php

-
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
count: 1
path: src/Builder/PackagesBuilder.php

-
message: "#^Only booleans are allowed in a negated boolean, string\\|null given\\.$#"
count: 1
path: src/Builder/WebBuilder.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 2
path: src/Console/Command/AddCommand.php

-
message: "#^Only booleans are allowed in a negated boolean, Composer\\\\Repository\\\\Vcs\\\\VcsDriverInterface\\|null given\\.$#"
count: 1
path: src/Console/Command/AddCommand.php

-
message: "#^Only booleans are allowed in a negated boolean, mixed given\\.$#"
count: 2
path: src/Console/Command/BuildCommand.php

-
message: "#^Only booleans are allowed in \\|\\|, mixed given on the right side\\.$#"
count: 1
path: src/Console/Command/BuildCommand.php

-
message: "#^Only booleans are allowed in &&, string\\|null given on the left side\\.$#"
count: 1
path: src/Console/Command/InitCommand.php

-
message: "#^Strict comparison using \\!\\=\\= between '' and non\\-falsy\\-string will always evaluate to true\\.$#"
count: 1
path: src/Console/Command/InitCommand.php

-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 1
path: src/Console/Command/PurgeCommand.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: src/Console/Command/PurgeCommand.php

-
message: "#^Foreach overwrites \\$file with its value variable\\.$#"
count: 2
path: src/Console/Command/PurgeCommand.php

-
message: "#^Only booleans are allowed in a negated boolean, int given\\.$#"
count: 1
path: src/Console/Command/PurgeCommand.php

-
message: "#^Only booleans are allowed in a negated boolean, string\\|null given\\.$#"
count: 1
path: src/Console/Command/PurgeCommand.php

-
message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#"
count: 1
path: src/Console/Command/PurgeCommand.php

-
message: "#^Call to function in_array\\(\\) requires parameter \\#3 to be set\\.$#"
count: 5
path: src/PackageSelection/PackageSelection.php

-
message: "#^Call to function is_string\\(\\) with string will always evaluate to true\\.$#"
count: 1
path: src/PackageSelection/PackageSelection.php

-
message: "#^Casting to bool something that's already bool\\.$#"
count: 1
path: src/PackageSelection/PackageSelection.php

-
message: "#^Only booleans are allowed in &&, string given on the left side\\.$#"
count: 1
path: src/PackageSelection/PackageSelection.php

-
message: "#^Only booleans are allowed in a negated boolean, int\\<0, max\\> given\\.$#"
count: 1
path: src/PackageSelection/PackageSelection.php

-
message: "#^Only booleans are allowed in a ternary operator condition, string given\\.$#"
count: 1
path: src/PackageSelection/PackageSelection.php

-
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
count: 2
path: src/PackageSelection/PackageSelection.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 2
path: tests/Builder/ArchiveBuilderHelperTest.php

-
message: "#^AnonymousClassdd4f4d5d0a10081f3f8b9c19006facf2\\:\\:__construct\\(\\) does not call parent constructor from Composer\\\\Package\\\\Archiver\\\\ArchiveManager\\.$#"
count: 1
path: tests/Builder/ArchiveBuilderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 2
path: tests/Builder/ArchiveBuilderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:returnCallback\\(\\)\\.$#"
count: 1
path: tests/Builder/ArchiveBuilderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:returnValue\\(\\)\\.$#"
count: 1
path: tests/Builder/ArchiveBuilderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayHasKey\\(\\)\\.$#"
count: 1
path: tests/Builder/PackagesBuilderDumpTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertArrayNotHasKey\\(\\)\\.$#"
count: 1
path: tests/Builder/PackagesBuilderDumpTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 3
path: tests/Builder/PackagesBuilderDumpTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#"
count: 1
path: tests/Builder/PackagesBuilderDumpTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\)\\.$#"
count: 2
path: tests/Builder/PackagesBuilderDumpTest.php

-
message: "#^Only booleans are allowed in a negated boolean, string\\|null given\\.$#"
count: 1
path: tests/Builder/PackagesBuilderDumpTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertFalse\\(\\)\\.$#"
count: 1
path: tests/Builder/WebBuilderDumpTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertMatchesRegularExpression\\(\\)\\.$#"
count: 6
path: tests/Builder/WebBuilderDumpTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 3
path: tests/Builder/WebBuilderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertInstanceOf\\(\\)\\.$#"
count: 1
path: tests/Builder/WebBuilderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 3
path: tests/Builder/WebBuilderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEmpty\\(\\)\\.$#"
count: 3
path: tests/PackageSelection/PackageSelectionLoadTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotEmpty\\(\\)\\.$#"
count: 3
path: tests/PackageSelection/PackageSelectionLoadTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertNotInstanceOf\\(\\)\\.$#"
count: 1
path: tests/PackageSelection/PackageSelectionLoadTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 2
path: tests/PackageSelection/PackageSelectionLoadTest.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1
path: tests/PackageSelection/PackageSelectionTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertEquals\\(\\)\\.$#"
count: 6
path: tests/PackageSelection/PackageSelectionTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:assertSame\\(\\)\\.$#"
count: 2
path: tests/PackageSelection/PackageSelectionTest.php

-
message: "#^Implicit array creation is not allowed \\- variable \\$data does not exist\\.$#"
count: 1
path: tests/PackageSelection/PackageSelectionTest.php

-
message: "#^Implicit array creation is not allowed \\- variable \\$repo does not exist\\.$#"
count: 1
path: tests/PackageSelection/PackageSelectionTest.php

-
message: "#^Offset 'url' on array\\{package\\: array\\} on left side of \\?\\? does not exist\\.$#"
count: 1
path: tests/PackageSelection/PackageSelectionTest.php

-
message: "#^Variable \\$filterPackages on left side of \\?\\? always exists and is always null\\.$#"
count: 1
path: tests/PackageSelection/PackageSelectionTest.php
2 changes: 1 addition & 1 deletion src/Builder/ArchiveBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function dump(array $packages): void
$progressBar = null;
$hasStarted = false;
$verbosity = $this->output->getVerbosity();
$renderProgress = $this->input->getOption('stats') && OutputInterface::VERBOSITY_NORMAL == $verbosity;
$renderProgress = (bool) $this->input->getOption('stats') && OutputInterface::VERBOSITY_NORMAL == $verbosity;

if ($renderProgress) {
$packageCount = 0;
Expand Down
27 changes: 13 additions & 14 deletions src/Builder/PackagesBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@ class PackagesBuilder extends Builder
{
public const MINIFY_ALGORITHM_V2 = 'composer/2.0';

/** @var string packages.json file name. */
private $filename;
/** @var string included json filename template */
private $includeFileName;
/** packages.json file name. */
private string $filename;
/** included json filename template */
private string $includeFileName;
/** @var list<mixed> */
private $writtenIncludeJsons = [];
/** @var bool */
private $minify;
private array $writtenIncludeJsons = [];
private bool $minify;

/**
* @param array<string, mixed> $config
Expand Down Expand Up @@ -61,7 +60,7 @@ public function dump(array $packages): void
$repo = ['packages' => []];
if (isset($this->config['providers']) && true === $this->config['providers']) {
$providersUrl = 'p/%package%$%hash%.json';
if (!empty($this->config['homepage'])) {
if (isset($this->config['homepage']) && is_string($this->config['homepage'])) {
$repo['providers-url'] = parse_url(rtrim($this->config['homepage'], '/'), PHP_URL_PATH) . '/' . $providersUrl;
} else {
$repo['providers-url'] = $providersUrl;
Expand Down Expand Up @@ -93,13 +92,13 @@ public function dump(array $packages): void

// Composer 2.0 format
$metadataUrl = 'p2/%package%.json';
if (!empty($this->config['homepage'])) {
if (array_key_exists('homepage', $this->config) && false !== filter_var($this->config['homepage'], FILTER_VALIDATE_URL)) {
$repo['metadata-url'] = parse_url(rtrim($this->config['homepage'], '/'), PHP_URL_PATH) . '/' . $metadataUrl;
} else {
$repo['metadata-url'] = $metadataUrl;
}

if (!empty($this->config['available-package-patterns'])) {
if (array_key_exists('available-package-patterns', $this->config) && count($this->config['available-package-patterns']) > 0) {
$repo['available-package-patterns'] = $this->config['available-package-patterns'];
} else {
$repo['available-packages'] = array_keys($packagesByName);
Expand Down Expand Up @@ -154,7 +153,7 @@ private function findReplacements(array $packages, string $replaced): array
$replacements = [];
foreach ($packages as $packageName => $packageConfig) {
foreach ($packageConfig as $versionConfig) {
if (!empty($versionConfig['replace']) && array_key_exists($replaced, $versionConfig['replace'])) {
if (array_key_exists('replace', $versionConfig) && array_key_exists($replaced, $versionConfig['replace'])) {
$replacements[$packageName] = $packageConfig;
break;
}
Expand Down Expand Up @@ -246,7 +245,7 @@ private function dumpPackageIncludeJson(array $packages, string $includesUrl, st
$options |= JSON_PRETTY_PRINT;
}

$contents = $repoJson->encode(array_merge(['packages' => $packages], $additionalMetaData), $options) . "\n";
$contents = $repoJson::encode(array_merge(['packages' => $packages], $additionalMetaData), $options) . "\n";
$hash = hash($hashAlgorithm, $contents);

if (false !== strpos($includesUrl, '%hash%')) {
Expand All @@ -259,7 +258,7 @@ private function dumpPackageIncludeJson(array $packages, string $includesUrl, st
}
}

if ($path) {
if (is_string($path)) {
$this->writeToFile($path, $contents);
$this->output->writeln("<info>Wrote packages to $path</info>");
}
Expand Down Expand Up @@ -296,7 +295,7 @@ private function writeToFile(string $path, string $contents): void
file_put_contents($path, $contents);
break;
} catch (\Exception $e) {
if ($retries) {
if ($retries > 0) {
usleep(500000);
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/WebBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function dump(array $packages): void
$this->output->writeln('Define a "name" property in your json config to name the repository');
}

if (!$this->rootPackage->getHomepage()) {
if (is_null($this->rootPackage->getHomepage())) {
$this->output->writeln('Define a "homepage" property in your json config to configure the repository URL');
}

Expand Down
7 changes: 4 additions & 3 deletions src/Console/Command/AddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$repositoryConfig = ['type' => $vcsDriver, 'url' => $repositoryUrl];

if (!empty($repositoryName)) {
if (is_string($repositoryName) && '' !== $repositoryName) {
$repositoryConfig['name'] = $repositoryName;
}

Expand All @@ -122,12 +122,13 @@ protected function isRepositoryValid(string $repositoryUrl, string $type): bool
$downloader = new HttpDownloader($io, $config);
$repository = new VcsRepository(['url' => $repositoryUrl, 'type' => $type], $io, $config, $downloader);

if (!($driver = $repository->getDriver())) {
$driver = $repository->getDriver();
if (is_null($driver)) {
return false;
}

$information = $driver->getComposerInformation($driver->getRootIdentifier());

return !empty($information['name']);
return isset($information['name']) && is_string($information['name']);
}
}
Loading

0 comments on commit 501da22

Please sign in to comment.