Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
strategy:
matrix:
php-version:
- '7.3'
- '7.4'

steps:
-
Expand Down Expand Up @@ -52,7 +52,7 @@ jobs:
strategy:
matrix:
php-version:
- '7.3'
- '7.4'

steps:
-
Expand Down Expand Up @@ -85,7 +85,6 @@ jobs:
strategy:
matrix:
php-version:
- '7.3'
- '7.4'
- '8.0'

Expand Down
17 changes: 16 additions & 1 deletion lib/Definition.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class Definition
*/
private $types;

/**
* @var array<mixed>
*/
private array $enum = [];

/**
* @var string|null
*/
Expand All @@ -32,14 +37,16 @@ class Definition
/**
* @param mixed $defaultValue
* @param array<string> $types
* @param array<mixed> $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;
}

/**
Expand All @@ -63,6 +70,14 @@ public function defaultValue()
return $this->defaultValue;
}

/**
* @return array<mixed>
*/
public function enum(): array
{
return $this->enum;
}

public function name(): string
{
return $this->name;
Expand Down
16 changes: 15 additions & 1 deletion lib/Resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class Resolver
*/
private $descriptions = [];

/**
* @var array<string,array<int,mixed>>
*/
private $enums = [];

/**
* @var bool
*/
Expand Down Expand Up @@ -67,6 +72,14 @@ public function setDefaults(array $defaults): void
$this->defaults = array_merge($this->defaults, $defaults);
}

/**
* @param array<string,array<int,mixed>> $enums
*/
public function setEnums(array $enums): void
{
$this->enums = $enums;
}

/**
* @param array<string,string> $typeMap
*/
Expand Down Expand Up @@ -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] ?? [],
);
}

Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/ResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
);
}
Expand Down