Skip to content

Commit 8de8c4e

Browse files
committed
added Structure::getShape() [Closes #35]
1 parent 0ef091e commit 8de8c4e

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

src/Schema/Elements/Structure.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ final class Structure implements Schema
3131

3232

3333
/**
34-
* @param Schema[] $items
34+
* @param Schema[] $shape
3535
*/
36-
public function __construct(array $items)
36+
public function __construct(array $shape)
3737
{
38-
(function (Schema ...$items) {})(...array_values($items));
39-
$this->items = $items;
38+
(function (Schema ...$items) {})(...array_values($shape));
39+
$this->items = $shape;
4040
$this->castTo('object');
4141
$this->required = true;
4242
}
@@ -83,6 +83,12 @@ public function extend(array|self $shape): self
8383
}
8484

8585

86+
public function getShape(): array
87+
{
88+
return $this->items;
89+
}
90+
91+
8692
/********************* processing ****************d*g**/
8793

8894

src/Schema/Expect.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ public static function anyOf(mixed ...$set): AnyOf
5656

5757

5858
/**
59-
* @param Schema[] $items
59+
* @param Schema[] $shape
6060
*/
61-
public static function structure(array $items): Structure
61+
public static function structure(array $shape): Structure
6262
{
63-
return new Structure($items);
63+
return new Structure($shape);
6464
}
6565

6666

tests/Schema/Expect.structure.phpt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,11 @@ test('extend', function () {
516516
$schema->extend(Expect::structure(['a' => Expect::int(), 'c' => Expect::int()])),
517517
);
518518
});
519+
520+
521+
test('getShape', function () {
522+
Assert::equal(
523+
['a' => Expect::int(), 'b' => Expect::string()],
524+
Expect::structure(['a' => Expect::int(), 'b' => Expect::string()])->getShape(),
525+
);
526+
});

0 commit comments

Comments
 (0)