From e966f414033557aef1b0ad6e0baa17e9f0e8bb7d Mon Sep 17 00:00:00 2001 From: przepompownia Date: Tue, 26 Apr 2022 00:34:00 +0200 Subject: [PATCH 1/2] Allow set enums --- lib/Definition.php | 17 ++++++++++++++++- lib/Resolver.php | 16 +++++++++++++++- tests/Unit/ResolverTest.php | 5 +++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/Definition.php b/lib/Definition.php index ea434bcb..048c90a8 100644 --- a/lib/Definition.php +++ b/lib/Definition.php @@ -24,6 +24,11 @@ class Definition */ private $types; + /** + * @var array + */ + private array $enum = []; + /** * @var string|null */ @@ -32,14 +37,16 @@ class Definition /** * @param mixed $defaultValue * @param array $types + * @param array $enum */ - public function __construct(string $name, $defaultValue, bool $required, ?string $description, array $types) + public function __construct(string $name, $defaultValue, bool $required, ?string $description, array $types, array $enum) { $this->name = $name; $this->defaultValue = $defaultValue; $this->required = $required; $this->types = $types; $this->description = $description; + $this->enum = $enum; } /** @@ -63,6 +70,14 @@ public function defaultValue() return $this->defaultValue; } + /** + * @return array + */ + public function enum(): array + { + return $this->enum; + } + public function name(): string { return $this->name; diff --git a/lib/Resolver.php b/lib/Resolver.php index 6f32bc20..cc9ac397 100644 --- a/lib/Resolver.php +++ b/lib/Resolver.php @@ -31,6 +31,11 @@ class Resolver */ private $descriptions = []; + /** + * @var array> + */ + private $enums = []; + /** * @var bool */ @@ -67,6 +72,14 @@ public function setDefaults(array $defaults): void $this->defaults = array_merge($this->defaults, $defaults); } + /** + * @param array> $enums + */ + public function setEnums(array $enums): void + { + $this->enums = $enums; + } + /** * @param array $typeMap */ @@ -200,7 +213,8 @@ public function definitions(): Definitions $this->defaults[$key] ?? null, in_array($key, $this->required), $this->descriptions[$key] ?? null, - isset($this->types[$key]) ? [$this->types[$key]] : [] + isset($this->types[$key]) ? [$this->types[$key]] : [], + $this->enums[$key] ?? [], ); } diff --git a/tests/Unit/ResolverTest.php b/tests/Unit/ResolverTest.php index 77739440..39fd12bd 100644 --- a/tests/Unit/ResolverTest.php +++ b/tests/Unit/ResolverTest.php @@ -172,16 +172,17 @@ public function testReturnsDefinition(): void $resolver->setTypes([ 'two' => 'int', ]); + $resolver->setEnums(['two' => [2]]); $definitions = $resolver->definitions(); self::assertEquals( - new Definition('two', 2, true, 'The number two', ['int']), + new Definition('two', 2, true, 'The number two', ['int'], [2]), $definitions->get('two') ); self::assertEquals( - new Definition('four', 'hello', false, null, []), + new Definition('four', 'hello', false, null, [], []), $definitions->get('four') ); } From e6feeecc046b864ba29b3832bf189af88eaec466 Mon Sep 17 00:00:00 2001 From: przepompownia Date: Tue, 26 Apr 2022 10:32:35 +0200 Subject: [PATCH 2/2] Remove support for PHP 7.3 --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b5084f4..6594e5d7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: strategy: matrix: php-version: - - '7.3' + - '7.4' steps: - @@ -52,7 +52,7 @@ jobs: strategy: matrix: php-version: - - '7.3' + - '7.4' steps: - @@ -85,7 +85,6 @@ jobs: strategy: matrix: php-version: - - '7.3' - '7.4' - '8.0'