From 509c0fffbed65b41bfafc4717b6d784fbba1bf96 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 2 Jun 2022 21:05:00 +0200 Subject: [PATCH 1/3] Include phpstan rules file, closes #10813 --- .gitattributes | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 2ee43db45..a929b3528 100644 --- a/.gitattributes +++ b/.gitattributes @@ -15,4 +15,5 @@ .travis.yml export-ignore appveyor.yml export-ignore phpunit.xml.dist export-ignore -/phpstan/ export-ignore +/phpstan/* export-ignore +/phpstan/rules.neon -export-ignore \ No newline at end of file From 3b204cb6f27e75e3fd0e7e5672fa4b2c86181d6d Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Thu, 2 Jun 2022 12:55:21 +0200 Subject: [PATCH 2/3] Specify optional array keys in `ConfigReturnTypeExtension` --- src/Composer/PHPStan/ConfigReturnTypeExtension.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Composer/PHPStan/ConfigReturnTypeExtension.php b/src/Composer/PHPStan/ConfigReturnTypeExtension.php index fc1de219e..574d7f921 100644 --- a/src/Composer/PHPStan/ConfigReturnTypeExtension.php +++ b/src/Composer/PHPStan/ConfigReturnTypeExtension.php @@ -123,19 +123,23 @@ final class ConfigReturnTypeExtension implements DynamicMethodReturnTypeExtensio if (isset($def['properties'])) { $keyNames = []; $valTypes = []; + $optionalKeys = []; + $propIndex = 0; foreach ($def['properties'] as $propName => $propdef) { $keyNames[] = new ConstantStringType($propName); $valType = $this->parseType($propdef, $path.'.'.$propName); if (!isset($def['required']) || !in_array($propName, $def['required'], true)) { $valType = TypeCombinator::addNull($valType); + $optionalKeys[] = $propIndex; } $valTypes[] = $valType; + $propIndex++; } if ($addlPropType !== null) { $types[] = new ArrayType(TypeCombinator::union(new StringType(), ...$keyNames), TypeCombinator::union($addlPropType, ...$valTypes)); } else { - $types[] = new ConstantArrayType($keyNames, $valTypes); + $types[] = new ConstantArrayType($keyNames, $valTypes, [0], $optionalKeys); } } else { $types[] = new ArrayType(new StringType(), $addlPropType ?? new MixedType()); From a0b78962315d4fd225c7ca25d46354e3cd7dd161 Mon Sep 17 00:00:00 2001 From: Anatoly Pashin Date: Fri, 3 Jun 2022 15:43:37 +1000 Subject: [PATCH 3/3] Fix processing null config value in DiagnoseCommand Fixes #10814 --- src/Composer/Config.php | 13 ++++++------- src/Composer/IO/BaseIO.php | 12 ++++++------ tests/Composer/Test/ConfigTest.php | 18 ++++++++++++++++++ 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/Composer/Config.php b/src/Composer/Config.php index 166d9cbf6..5a0ded2a1 100644 --- a/src/Composer/Config.php +++ b/src/Composer/Config.php @@ -76,13 +76,12 @@ class Config 'use-github-api' => true, 'lock' => true, 'platform-check' => 'php-only', - // valid keys without defaults (auth config stuff): - // bitbucket-oauth - // github-oauth - // gitlab-oauth - // gitlab-token - // http-basic - // bearer + 'bitbucket-oauth' => array(), + 'github-oauth' => array(), + 'gitlab-oauth' => array(), + 'gitlab-token' => array(), + 'http-basic' => array(), + 'bearer' => array(), ); /** @var array */ diff --git a/src/Composer/IO/BaseIO.php b/src/Composer/IO/BaseIO.php index 56715b709..d53d0b097 100644 --- a/src/Composer/IO/BaseIO.php +++ b/src/Composer/IO/BaseIO.php @@ -114,12 +114,12 @@ abstract class BaseIO implements IOInterface */ public function loadConfiguration(Config $config) { - $bitbucketOauth = $config->get('bitbucket-oauth') ?: array(); - $githubOauth = $config->get('github-oauth') ?: array(); - $gitlabOauth = $config->get('gitlab-oauth') ?: array(); - $gitlabToken = $config->get('gitlab-token') ?: array(); - $httpBasic = $config->get('http-basic') ?: array(); - $bearerToken = $config->get('bearer') ?: array(); + $bitbucketOauth = $config->get('bitbucket-oauth'); + $githubOauth = $config->get('github-oauth'); + $gitlabOauth = $config->get('gitlab-oauth'); + $gitlabToken = $config->get('gitlab-token'); + $httpBasic = $config->get('http-basic'); + $bearerToken = $config->get('bearer'); // reload oauth tokens from config if available diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index 201fa7832..855f4c2ef 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/tests/Composer/Test/ConfigTest.php @@ -390,4 +390,22 @@ class ConfigTest extends TestCase $this->assertEquals('COMPOSER_HTACCESS_PROTECT', $result); } + + public function testGetDefaultsToAnEmptyArray(): void + { + $config = new Config; + $keys = [ + 'bitbucket-oauth', + 'github-oauth', + 'gitlab-oauth', + 'gitlab-token', + 'http-basic', + 'bearer', + ]; + foreach ($keys as $key) { + $value = $config->get($key); + $this->assertIsArray($value); + $this->assertCount(0, $value); + } + } }