Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
94.74% covered (success)
94.74%
18 / 19
66.67% covered (warning)
66.67%
2 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ComponentsBuilderFactory
94.74% covered (success)
94.74%
18 / 19
66.67% covered (warning)
66.67%
2 / 3
4.00
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createComponentsBuilderFactory
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
1
 createComponentsBuilder
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2namespace Apie\SchemaGenerator;
3
4use Apie\SchemaGenerator\Builders\ComponentsBuilder;
5use Apie\SchemaGenerator\Interfaces\SchemaProvider;
6use Apie\SchemaGenerator\SchemaProviders\AliasSchemaProvider;
7use Apie\SchemaGenerator\SchemaProviders\DateTimeSchemaProvider;
8use Apie\SchemaGenerator\SchemaProviders\DateTimeZoneSchemaProvider;
9use Apie\SchemaGenerator\SchemaProviders\DateValueObjectSchemaProvider;
10use Apie\SchemaGenerator\SchemaProviders\ItemHashmapSchemaProvider;
11use Apie\SchemaGenerator\SchemaProviders\ItemListSchemaProvider;
12use Apie\SchemaGenerator\SchemaProviders\ItemSetSchemaProvider;
13use Apie\SchemaGenerator\SchemaProviders\MetadataSchemaProvider;
14use Apie\SchemaGenerator\SchemaProviders\PolymorphicEntitySchemaProvider;
15use Apie\SchemaGenerator\SchemaProviders\SchemaAttributeProvider;
16use Apie\SchemaGenerator\SchemaProviders\StringValueObjectSchemaProvider;
17use Apie\SchemaGenerator\SchemaProviders\UploadedFileSchemaProvider;
18use Apie\SchemaGenerator\SchemaProviders\ValueObjectSchemaProvider;
19use cebe\openapi\spec\Components;
20
21class 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}