Skip to content

Commit 091c3e9

Browse files
Allow set enums (#10)
* Allow set enums * Remove support for PHP 7.3
1 parent 0a1b591 commit 091c3e9

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
strategy:
2020
matrix:
2121
php-version:
22-
- '7.3'
22+
- '7.4'
2323

2424
steps:
2525
-
@@ -52,7 +52,7 @@ jobs:
5252
strategy:
5353
matrix:
5454
php-version:
55-
- '7.3'
55+
- '7.4'
5656

5757
steps:
5858
-
@@ -85,7 +85,6 @@ jobs:
8585
strategy:
8686
matrix:
8787
php-version:
88-
- '7.3'
8988
- '7.4'
9089
- '8.0'
9190

lib/Definition.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ class Definition
2424
*/
2525
private $types;
2626

27+
/**
28+
* @var array<mixed>
29+
*/
30+
private array $enum = [];
31+
2732
/**
2833
* @var string|null
2934
*/
@@ -32,14 +37,16 @@ class Definition
3237
/**
3338
* @param mixed $defaultValue
3439
* @param array<string> $types
40+
* @param array<mixed> $enum
3541
*/
36-
public function __construct(string $name, $defaultValue, bool $required, ?string $description, array $types)
42+
public function __construct(string $name, $defaultValue, bool $required, ?string $description, array $types, array $enum)
3743
{
3844
$this->name = $name;
3945
$this->defaultValue = $defaultValue;
4046
$this->required = $required;
4147
$this->types = $types;
4248
$this->description = $description;
49+
$this->enum = $enum;
4350
}
4451

4552
/**
@@ -63,6 +70,14 @@ public function defaultValue()
6370
return $this->defaultValue;
6471
}
6572

73+
/**
74+
* @return array<mixed>
75+
*/
76+
public function enum(): array
77+
{
78+
return $this->enum;
79+
}
80+
6681
public function name(): string
6782
{
6883
return $this->name;

lib/Resolver.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class Resolver
3131
*/
3232
private $descriptions = [];
3333

34+
/**
35+
* @var array<string,array<int,mixed>>
36+
*/
37+
private $enums = [];
38+
3439
/**
3540
* @var bool
3641
*/
@@ -67,6 +72,14 @@ public function setDefaults(array $defaults): void
6772
$this->defaults = array_merge($this->defaults, $defaults);
6873
}
6974

75+
/**
76+
* @param array<string,array<int,mixed>> $enums
77+
*/
78+
public function setEnums(array $enums): void
79+
{
80+
$this->enums = $enums;
81+
}
82+
7083
/**
7184
* @param array<string,string> $typeMap
7285
*/
@@ -200,7 +213,8 @@ public function definitions(): Definitions
200213
$this->defaults[$key] ?? null,
201214
in_array($key, $this->required),
202215
$this->descriptions[$key] ?? null,
203-
isset($this->types[$key]) ? [$this->types[$key]] : []
216+
isset($this->types[$key]) ? [$this->types[$key]] : [],
217+
$this->enums[$key] ?? [],
204218
);
205219
}
206220

tests/Unit/ResolverTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,16 +172,17 @@ public function testReturnsDefinition(): void
172172
$resolver->setTypes([
173173
'two' => 'int',
174174
]);
175+
$resolver->setEnums(['two' => [2]]);
175176

176177
$definitions = $resolver->definitions();
177178

178179
self::assertEquals(
179-
new Definition('two', 2, true, 'The number two', ['int']),
180+
new Definition('two', 2, true, 'The number two', ['int'], [2]),
180181
$definitions->get('two')
181182
);
182183

183184
self::assertEquals(
184-
new Definition('four', 'hello', false, null, []),
185+
new Definition('four', 'hello', false, null, [], []),
185186
$definitions->get('four')
186187
);
187188
}

0 commit comments

Comments
 (0)