Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.74% |
18 / 19 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
ComponentsBuilderFactory | |
94.74% |
18 / 19 |
|
66.67% |
2 / 3 |
4.00 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
createComponentsBuilderFactory | |
100.00% |
15 / 15 |
|
100.00% |
1 / 1 |
1 | |||
createComponentsBuilder | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 |
1 | <?php |
2 | namespace Apie\SchemaGenerator; |
3 | |
4 | use Apie\SchemaGenerator\Builders\ComponentsBuilder; |
5 | use Apie\SchemaGenerator\Interfaces\SchemaProvider; |
6 | use Apie\SchemaGenerator\SchemaProviders\AliasSchemaProvider; |
7 | use Apie\SchemaGenerator\SchemaProviders\DateTimeSchemaProvider; |
8 | use Apie\SchemaGenerator\SchemaProviders\DateTimeZoneSchemaProvider; |
9 | use Apie\SchemaGenerator\SchemaProviders\DateValueObjectSchemaProvider; |
10 | use Apie\SchemaGenerator\SchemaProviders\ItemHashmapSchemaProvider; |
11 | use Apie\SchemaGenerator\SchemaProviders\ItemListSchemaProvider; |
12 | use Apie\SchemaGenerator\SchemaProviders\ItemSetSchemaProvider; |
13 | use Apie\SchemaGenerator\SchemaProviders\MetadataSchemaProvider; |
14 | use Apie\SchemaGenerator\SchemaProviders\PolymorphicEntitySchemaProvider; |
15 | use Apie\SchemaGenerator\SchemaProviders\SchemaAttributeProvider; |
16 | use Apie\SchemaGenerator\SchemaProviders\StringValueObjectSchemaProvider; |
17 | use Apie\SchemaGenerator\SchemaProviders\UploadedFileSchemaProvider; |
18 | use Apie\SchemaGenerator\SchemaProviders\ValueObjectSchemaProvider; |
19 | use cebe\openapi\spec\Components; |
20 | |
21 | class ComponentsBuilderFactory |
22 | { |
23 | /** |
24 | * @var array<int, SchemaProvider<object>> |
25 | */ |
26 | private array $schemaProviders; |
27 | |
28 | /** |
29 | * @param SchemaProvider<object> $schemaProviders |
30 | */ |
31 | public function __construct(SchemaProvider... $schemaProviders) |
32 | { |
33 | $this->schemaProviders = $schemaProviders; |
34 | } |
35 | |
36 | public static function createComponentsBuilderFactory(): self |
37 | { |
38 | return new self( |
39 | new SchemaAttributeProvider(), |
40 | new AliasSchemaProvider(), |
41 | new UploadedFileSchemaProvider(), |
42 | new ItemListSchemaProvider(), |
43 | new ItemHashmapSchemaProvider(), |
44 | new ItemSetSchemaProvider(), |
45 | new PolymorphicEntitySchemaProvider(), |
46 | new DateTimeSchemaProvider(), |
47 | new DateTimeZoneSchemaProvider(), |
48 | new DateValueObjectSchemaProvider(), |
49 | new StringValueObjectSchemaProvider(), |
50 | new ValueObjectSchemaProvider(), |
51 | new MetadataSchemaProvider(), |
52 | ); |
53 | } |
54 | |
55 | public function createComponentsBuilder(?Components $components = null): ComponentsBuilder |
56 | { |
57 | if ($components) { |
58 | return ComponentsBuilder::createWithExistingComponents($components, ...$this->schemaProviders); |
59 | } |
60 | return new ComponentsBuilder(...$this->schemaProviders); |
61 | } |
62 | } |