Skip to content

Commit 590f204

Browse files
committed
Add ValueObject factory
1 parent 103869f commit 590f204

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

src/ValueObjectFactory.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
/**
4+
* @see https://github.com/open-code-modeling/json-schema-to-php-ast for the canonical source repository
5+
* @copyright https://github.com/open-code-modeling/json-schema-to-php-ast/blob/master/COPYRIGHT.md
6+
* @license https://github.com/open-code-modeling/json-schema-to-php-ast/blob/master/LICENSE.md MIT License
7+
*/
8+
9+
declare(strict_types=1);
10+
11+
namespace OpenCodeModeling\JsonSchemaToPhpAst;
12+
13+
use OpenCodeModeling\JsonSchemaToPhp\Type\IntegerType;
14+
use OpenCodeModeling\JsonSchemaToPhp\Type\StringType;
15+
use OpenCodeModeling\JsonSchemaToPhp\Type\TypeDefinition;
16+
use OpenCodeModeling\JsonSchemaToPhpAst\ValueObject\IntegerFactory;
17+
use OpenCodeModeling\JsonSchemaToPhpAst\ValueObject\StringFactory;
18+
use PhpParser\NodeVisitor;
19+
use PhpParser\Parser;
20+
21+
final class ValueObjectFactory
22+
{
23+
private StringFactory $stringFactory;
24+
private IntegerFactory $integerFactory;
25+
26+
public function __construct(Parser $parser, bool $typed)
27+
{
28+
$this->stringFactory = new StringFactory($parser, $typed);
29+
$this->integerFactory = new IntegerFactory($parser, $typed);
30+
}
31+
32+
/**
33+
* @param TypeDefinition $typeDefinition
34+
* @return array<NodeVisitor>
35+
*/
36+
public function nodeVisitors(TypeDefinition $typeDefinition): array
37+
{
38+
switch (true) {
39+
case $typeDefinition instanceof StringType:
40+
return $this->stringFactory->nodeVisitors($typeDefinition);
41+
case $typeDefinition instanceof IntegerType:
42+
return $this->integerFactory->nodeVisitors($typeDefinition);
43+
default:
44+
// TODO throw exception
45+
return [];
46+
}
47+
}
48+
}

0 commit comments

Comments
 (0)