From d63218c5686a28a06f3ad21db088b23bb6a95897 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 14 Sep 2022 09:48:44 +0200 Subject: [PATCH 1/2] Fix type error --- src/Composer/Package/Loader/ArrayLoader.php | 2 +- src/Composer/Package/Loader/ValidatingArrayLoader.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Composer/Package/Loader/ArrayLoader.php b/src/Composer/Package/Loader/ArrayLoader.php index 72e0df76a..47b314e33 100644 --- a/src/Composer/Package/Loader/ArrayLoader.php +++ b/src/Composer/Package/Loader/ArrayLoader.php @@ -271,7 +271,7 @@ class ArrayLoader implements LoaderInterface } if (!empty($config['keywords']) && \is_array($config['keywords'])) { - $package->setKeywords($config['keywords']); + $package->setKeywords(array_map('strval', $config['keywords'])); } if (!empty($config['license'])) { diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 1bcd294b5..2977091fc 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -571,7 +571,7 @@ class ValidatingArrayLoader implements LoaderInterface continue; } - if ($regex && !Preg::isMatch('{^'.$regex.'$}u', $value)) { + if ($regex && !Preg::isMatch('{^'.$regex.'$}u', (string) $value)) { $this->warnings[] = $property.'.'.$key.' : invalid value ('.$value.'), must match '.$regex; unset($this->config[$property][$key]); $pass = false; From 21045b942e81177c6d84c14f00e252cecb433564 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Wed, 14 Sep 2022 10:50:52 +0200 Subject: [PATCH 2/2] Fix type errors and update baseline (1854, 99) --- phpstan/baseline.neon | 19 ++------------ .../Package/Loader/ValidatingArrayLoader.php | 26 +++++++++---------- 2 files changed, 15 insertions(+), 30 deletions(-) diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index 9aa2908b1..6bbe0baa4 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -3062,7 +3062,7 @@ parameters: - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 19 + count: 8 path: ../src/Composer/Package/Loader/ValidatingArrayLoader.php - @@ -3095,11 +3095,6 @@ parameters: count: 1 path: ../src/Composer/Package/Loader/ValidatingArrayLoader.php - - - message: "#^Only booleans are allowed in a negated boolean, DateTime\\|null given\\.$#" - count: 1 - path: ../src/Composer/Package/Loader/ValidatingArrayLoader.php - - message: "#^Only booleans are allowed in a negated boolean, int\\<0, max\\> given\\.$#" count: 1 @@ -3107,7 +3102,7 @@ parameters: - message: "#^Only booleans are allowed in a negated boolean, string\\|false given\\.$#" - count: 2 + count: 1 path: ../src/Composer/Package/Loader/ValidatingArrayLoader.php - @@ -3117,16 +3112,6 @@ parameters: - message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#" - count: 2 - path: ../src/Composer/Package/Loader/ValidatingArrayLoader.php - - - - message: "#^Parameter \\#2 \\$subject of static method Composer\\\\Pcre\\\\Preg\\:\\:isMatch\\(\\) expects string, float\\|int\\|string given\\.$#" - count: 1 - path: ../src/Composer/Package/Loader/ValidatingArrayLoader.php - - - - message: "#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#" count: 1 path: ../src/Composer/Package/Loader/ValidatingArrayLoader.php diff --git a/src/Composer/Package/Loader/ValidatingArrayLoader.php b/src/Composer/Package/Loader/ValidatingArrayLoader.php index 2977091fc..4e08191fb 100644 --- a/src/Composer/Package/Loader/ValidatingArrayLoader.php +++ b/src/Composer/Package/Loader/ValidatingArrayLoader.php @@ -47,7 +47,7 @@ class ValidatingArrayLoader implements LoaderInterface public function __construct(LoaderInterface $loader, bool $strictName = true, ?VersionParser $parser = null, int $flags = 0) { $this->loader = $loader; - $this->versionParser = $parser ?: new VersionParser(); + $this->versionParser = $parser ?? new VersionParser(); $this->flags = $flags; if ($strictName !== true) { // @phpstan-ignore-line @@ -69,7 +69,7 @@ class ValidatingArrayLoader implements LoaderInterface $this->errors[] = 'name : '.$err; } - if (!empty($this->config['version'])) { + if (isset($this->config['version'])) { if (!is_scalar($this->config['version'])) { $this->validateString('version'); } else { @@ -85,7 +85,7 @@ class ValidatingArrayLoader implements LoaderInterface } } - if (!empty($this->config['config']['platform'])) { + if (isset($this->config['config']['platform'])) { foreach ((array) $this->config['config']['platform'] as $key => $platform) { if (false === $platform) { continue; @@ -121,7 +121,7 @@ class ValidatingArrayLoader implements LoaderInterface $releaseDate = null; $this->validateString('time'); - if (!empty($this->config['time'])) { + if (isset($this->config['time'])) { try { $releaseDate = new \DateTime($this->config['time'], new \DateTimeZone('UTC')); } catch (\Exception $e) { @@ -131,7 +131,7 @@ class ValidatingArrayLoader implements LoaderInterface } // check for license validity on newly updated branches - if (isset($this->config['license']) && (!$releaseDate || $releaseDate->getTimestamp() >= strtotime('-8days'))) { + if (isset($this->config['license']) && (null === $releaseDate || $releaseDate->getTimestamp() >= strtotime('-8days'))) { if (is_array($this->config['license']) || is_string($this->config['license'])) { $licenses = (array) $this->config['license']; @@ -160,7 +160,7 @@ class ValidatingArrayLoader implements LoaderInterface } } - if ($this->validateArray('authors') && !empty($this->config['authors'])) { + if ($this->validateArray('authors')) { foreach ($this->config['authors'] as $key => $author) { if (!is_array($author)) { $this->errors[] = 'authors.'.$key.' : should be an array, '.gettype($author).' given'; @@ -177,15 +177,15 @@ class ValidatingArrayLoader implements LoaderInterface $this->warnings[] = 'authors.'.$key.'.homepage : invalid value ('.$author['homepage'].'), must be an http/https URL'; unset($this->config['authors'][$key]['homepage']); } - if (isset($author['email']) && !filter_var($author['email'], FILTER_VALIDATE_EMAIL)) { + if (isset($author['email']) && false === filter_var($author['email'], FILTER_VALIDATE_EMAIL)) { $this->warnings[] = 'authors.'.$key.'.email : invalid value ('.$author['email'].'), must be a valid email address'; unset($this->config['authors'][$key]['email']); } - if (empty($this->config['authors'][$key])) { + if (\count($this->config['authors'][$key]) === 0) { unset($this->config['authors'][$key]); } } - if (empty($this->config['authors'])) { + if (\count($this->config['authors']) === 0) { unset($this->config['authors']); } } @@ -301,7 +301,7 @@ class ValidatingArrayLoader implements LoaderInterface } } - if ($this->validateArray('suggest') && !empty($this->config['suggest'])) { + if ($this->validateArray('suggest') && isset($this->config['suggest'])) { foreach ($this->config['suggest'] as $package => $description) { if (!is_string($description)) { $this->errors[] = 'suggest.'.$package.' : invalid value, must be a string describing why the package is suggested'; @@ -310,14 +310,14 @@ class ValidatingArrayLoader implements LoaderInterface } } - if ($this->validateString('minimum-stability') && !empty($this->config['minimum-stability'])) { + if ($this->validateString('minimum-stability') && isset($this->config['minimum-stability'])) { if (!isset(BasePackage::$stabilities[strtolower($this->config['minimum-stability'])]) && $this->config['minimum-stability'] !== 'RC') { $this->errors[] = 'minimum-stability : invalid value ('.$this->config['minimum-stability'].'), must be one of '.implode(', ', array_keys(BasePackage::$stabilities)); unset($this->config['minimum-stability']); } } - if ($this->validateArray('autoload') && !empty($this->config['autoload'])) { + if ($this->validateArray('autoload') && isset($this->config['autoload'])) { $types = ['psr-0', 'psr-4', 'classmap', 'files', 'exclude-from-classmap']; foreach ($this->config['autoload'] as $type => $typeConfig) { if (!in_array($type, $types)) { @@ -334,7 +334,7 @@ class ValidatingArrayLoader implements LoaderInterface } } - if (!empty($this->config['autoload']['psr-4']) && !empty($this->config['target-dir'])) { + if (isset($this->config['autoload']['psr-4']) && isset($this->config['target-dir'])) { $this->errors[] = 'target-dir : this can not be used together with the autoload.psr-4 setting, remove target-dir to upgrade to psr-4'; // Unset the psr-4 setting, since unsetting target-dir might // interfere with other settings.