Skip to content

Commit

Permalink
Merge pull request #9 from arnedesmedt/master
Browse files Browse the repository at this point in the history
add default and examples to annotations
  • Loading branch information
codeliner authored Jun 30, 2020
2 parents 5e89296 + 6a9caf4 commit c9edcf7
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/AnnotatedType.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ interface AnnotatedType extends Type
public function entitled(string $title);

public function describedAs(string $description);

public function withDefault($default);

public function withExamples(...$examples);
}
55 changes: 55 additions & 0 deletions src/Type/HasAnnotations.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ trait HasAnnotations
*/
protected $description;

/**
* @var mixed
*/
protected $default;

/**
* @var array<mixed>
*/
protected $examples;

public function entitled(string $title): self
{
$cp = clone $this;
Expand Down Expand Up @@ -51,6 +61,43 @@ public function description(): ?string
return $this->description;
}

/**
* @param mixed $default
*/
public function withDefault($default): self
{
$cp = clone $this;

$cp->default = $default;

return $cp;
}

/**
* @return mixed
*/
public function defaultValue()
{
return $this->default;
}

public function withExamples(...$examples): self
{
$cp = clone $this;

$cp->examples = $examples;

return $cp;
}

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

public function annotations(): array
{
$annotations = [];
Expand All @@ -63,6 +110,14 @@ public function annotations(): array
$annotations['description'] = $this->description;
}

if (null !== $this->default) {
$annotations['default'] = $this->default;
}

if (null !== $this->examples) {
$annotations['examples'] = $this->examples;
}

return $annotations;
}
}

0 comments on commit c9edcf7

Please sign in to comment.