Shortcut config

master
Anton Smirnov 8 months ago
parent 29d6ae470c
commit 30458a277f

@ -38,11 +38,21 @@ final class Config
public static function fromArray(array $config): self
{
$licenses = $config['licenses'] ?? [];
if ($licenses !== [] && array_is_list($licenses)) {
$licenses = ['allowed' => $licenses];
}
$packages = $config['packages'] ?? [];
if ($packages !== [] && array_is_list($packages)) {
$packages = ['allowed' => $packages];
}
return new self(
ConfigHelper::valueToArray($config['licenses']['allowed'] ?? ['*']),
$config['licenses']['allow-empty'] ?? false,
ConfigHelper::valueToArray($config['licenses']['forbidden'] ?? []),
ConfigHelper::valueToArray($config['packages']['allowed'] ?? []),
ConfigHelper::valueToArray($licenses['allowed'] ?? ['*']),
$licenses['allow-empty'] ?? false,
ConfigHelper::valueToArray($licenses['forbidden'] ?? []),
ConfigHelper::valueToArray($packages['allowed'] ?? []),
$config['enforced'] ?? true
);
}

@ -44,4 +44,20 @@ class ConfigTest extends TestCase
Config::fromArray(['licenses' => ['allowed' => ['MIT' => 'MIT', 123 => 123]]]);
}
public function testLicenseShortcutsEquivalence(): void
{
$config1 = Config::fromArray(['licenses' => ['allowed' => ['MIT', 'BSD-2-Clause', 'GPL-*']]]);
$config2 = Config::fromArray(['licenses' => ['MIT', 'BSD-2-Clause', 'GPL-*']]);
self::assertEquals($config1, $config2);
}
public function testPackageShortcutsEquivalence(): void
{
$config1 = Config::fromArray(['packages' => ['allowed' => ['foo/bar', 'foo/baz', 'bar/*']]]);
$config2 = Config::fromArray(['packages' => ['foo/bar', 'foo/baz', 'bar/*']]);
self::assertEquals($config1, $config2);
}
}

Loading…
Cancel
Save