Skip to content

Commit

Permalink
added Structure::getShape() [Closes #35]
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 5, 2024
1 parent 0ef091e commit 8de8c4e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
14 changes: 10 additions & 4 deletions src/Schema/Elements/Structure.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ final class Structure implements Schema


/**
* @param Schema[] $items
* @param Schema[] $shape
*/
public function __construct(array $items)
public function __construct(array $shape)
{
(function (Schema ...$items) {})(...array_values($items));
$this->items = $items;
(function (Schema ...$items) {})(...array_values($shape));
$this->items = $shape;
$this->castTo('object');
$this->required = true;
}
Expand Down Expand Up @@ -83,6 +83,12 @@ public function extend(array|self $shape): self
}


public function getShape(): array
{
return $this->items;
}


/********************* processing ****************d*g**/


Expand Down
6 changes: 3 additions & 3 deletions src/Schema/Expect.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public static function anyOf(mixed ...$set): AnyOf


/**
* @param Schema[] $items
* @param Schema[] $shape
*/
public static function structure(array $items): Structure
public static function structure(array $shape): Structure
{
return new Structure($items);
return new Structure($shape);
}


Expand Down
8 changes: 8 additions & 0 deletions tests/Schema/Expect.structure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -516,3 +516,11 @@ test('extend', function () {
$schema->extend(Expect::structure(['a' => Expect::int(), 'c' => Expect::int()])),
);
});


test('getShape', function () {
Assert::equal(
['a' => Expect::int(), 'b' => Expect::string()],
Expect::structure(['a' => Expect::int(), 'b' => Expect::string()])->getShape(),
);
});

0 comments on commit 8de8c4e

Please sign in to comment.