Merge branch '2.3' into main
commit
8792163676
|
@ -15,4 +15,5 @@
|
||||||
.travis.yml export-ignore
|
.travis.yml export-ignore
|
||||||
appveyor.yml export-ignore
|
appveyor.yml export-ignore
|
||||||
phpunit.xml.dist export-ignore
|
phpunit.xml.dist export-ignore
|
||||||
/phpstan/ export-ignore
|
/phpstan/* export-ignore
|
||||||
|
/phpstan/rules.neon -export-ignore
|
|
@ -76,13 +76,12 @@ class Config
|
||||||
'use-github-api' => true,
|
'use-github-api' => true,
|
||||||
'lock' => true,
|
'lock' => true,
|
||||||
'platform-check' => 'php-only',
|
'platform-check' => 'php-only',
|
||||||
// valid keys without defaults (auth config stuff):
|
'bitbucket-oauth' => array(),
|
||||||
// bitbucket-oauth
|
'github-oauth' => array(),
|
||||||
// github-oauth
|
'gitlab-oauth' => array(),
|
||||||
// gitlab-oauth
|
'gitlab-token' => array(),
|
||||||
// gitlab-token
|
'http-basic' => array(),
|
||||||
// http-basic
|
'bearer' => array(),
|
||||||
// bearer
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/** @var array<string, mixed> */
|
/** @var array<string, mixed> */
|
||||||
|
|
|
@ -114,12 +114,12 @@ abstract class BaseIO implements IOInterface
|
||||||
*/
|
*/
|
||||||
public function loadConfiguration(Config $config)
|
public function loadConfiguration(Config $config)
|
||||||
{
|
{
|
||||||
$bitbucketOauth = $config->get('bitbucket-oauth') ?: array();
|
$bitbucketOauth = $config->get('bitbucket-oauth');
|
||||||
$githubOauth = $config->get('github-oauth') ?: array();
|
$githubOauth = $config->get('github-oauth');
|
||||||
$gitlabOauth = $config->get('gitlab-oauth') ?: array();
|
$gitlabOauth = $config->get('gitlab-oauth');
|
||||||
$gitlabToken = $config->get('gitlab-token') ?: array();
|
$gitlabToken = $config->get('gitlab-token');
|
||||||
$httpBasic = $config->get('http-basic') ?: array();
|
$httpBasic = $config->get('http-basic');
|
||||||
$bearerToken = $config->get('bearer') ?: array();
|
$bearerToken = $config->get('bearer');
|
||||||
|
|
||||||
// reload oauth tokens from config if available
|
// reload oauth tokens from config if available
|
||||||
|
|
||||||
|
|
|
@ -123,19 +123,23 @@ final class ConfigReturnTypeExtension implements DynamicMethodReturnTypeExtensio
|
||||||
if (isset($def['properties'])) {
|
if (isset($def['properties'])) {
|
||||||
$keyNames = [];
|
$keyNames = [];
|
||||||
$valTypes = [];
|
$valTypes = [];
|
||||||
|
$optionalKeys = [];
|
||||||
|
$propIndex = 0;
|
||||||
foreach ($def['properties'] as $propName => $propdef) {
|
foreach ($def['properties'] as $propName => $propdef) {
|
||||||
$keyNames[] = new ConstantStringType($propName);
|
$keyNames[] = new ConstantStringType($propName);
|
||||||
$valType = $this->parseType($propdef, $path.'.'.$propName);
|
$valType = $this->parseType($propdef, $path.'.'.$propName);
|
||||||
if (!isset($def['required']) || !in_array($propName, $def['required'], true)) {
|
if (!isset($def['required']) || !in_array($propName, $def['required'], true)) {
|
||||||
$valType = TypeCombinator::addNull($valType);
|
$valType = TypeCombinator::addNull($valType);
|
||||||
|
$optionalKeys[] = $propIndex;
|
||||||
}
|
}
|
||||||
$valTypes[] = $valType;
|
$valTypes[] = $valType;
|
||||||
|
$propIndex++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($addlPropType !== null) {
|
if ($addlPropType !== null) {
|
||||||
$types[] = new ArrayType(TypeCombinator::union(new StringType(), ...$keyNames), TypeCombinator::union($addlPropType, ...$valTypes));
|
$types[] = new ArrayType(TypeCombinator::union(new StringType(), ...$keyNames), TypeCombinator::union($addlPropType, ...$valTypes));
|
||||||
} else {
|
} else {
|
||||||
$types[] = new ConstantArrayType($keyNames, $valTypes);
|
$types[] = new ConstantArrayType($keyNames, $valTypes, [0], $optionalKeys);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$types[] = new ArrayType(new StringType(), $addlPropType ?? new MixedType());
|
$types[] = new ArrayType(new StringType(), $addlPropType ?? new MixedType());
|
||||||
|
|
|
@ -390,4 +390,22 @@ class ConfigTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals('COMPOSER_HTACCESS_PROTECT', $result);
|
$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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue