ServiceFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 6
dl 0
loc 14
ccs 7
cts 7
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
namespace ElevenLabs\ApiServiceBundle\Factory;
3
4
use ElevenLabs\Api\Decoder\DecoderInterface;
5
use ElevenLabs\Api\Factory\SchemaFactory;
6
use ElevenLabs\Api\Service\ApiService;
7
use ElevenLabs\Api\Validator\MessageValidator;
8
use Http\Client\HttpClient;
9
use Http\Message\MessageFactory;
10
use Http\Message\UriFactory;
11
use JsonSchema\Validator;
12
use Rize\UriTemplate;
13
use Symfony\Component\Serializer\SerializerInterface;
14
15
/**
16
 * Create an API Service
17
 */
18
class ServiceFactory
19
{
20
    /** @var UriFactory */
21
    private $uriFactory;
22
23
    /** @var UriTemplate */
24
    private $uriTemplate;
25
26
    /** @var MessageFactory */
27
    private $messageFactory;
28
29
    /** @var Validator */
30
    private $validator;
31
32
    /** @var SerializerInterface */
33
    private $serializer;
34
35
    /** @var \ElevenLabs\Api\Decoder\DecoderInterface */
36
    private $decoder;
37
38
    /**
39
     * @param UriFactory $uriFactory
40
     * @param UriTemplate $uriTemplate
41
     * @param MessageFactory $messageFactory
42
     * @param Validator $validator
43
     * @param SerializerInterface $serializer
44
     * @param DecoderInterface $decoder
45
     */
46 5
    public function __construct(
47
        UriFactory $uriFactory,
48
        UriTemplate $uriTemplate,
49
        MessageFactory $messageFactory,
50
        Validator $validator,
51
        SerializerInterface $serializer,
52
        DecoderInterface $decoder
53
    ) {
54 5
        $this->uriFactory = $uriFactory;
55 5
        $this->uriTemplate = $uriTemplate;
56 5
        $this->messageFactory = $messageFactory;
57 5
        $this->validator = $validator;
58 5
        $this->serializer = $serializer;
59 5
        $this->decoder = $decoder;
60 5
    }
61
62
    /**
63
     * @param HttpClient $httpClient
64
     * @param SchemaFactory $schemaFactory
65
     * @param $schemaFile
66
     * @param array $config
67
     *
68
     * @return ApiService
69
     */
70 5
    public function getService(
71
        HttpClient $httpClient,
72
        SchemaFactory $schemaFactory,
73
        $schemaFile,
74
        $config = []
75
    ) {
76 5
        $schema = $schemaFactory->createSchema($schemaFile);
77
78 5
        return new ApiService(
79 5
            $this->uriFactory,
80 5
            $this->uriTemplate,
81 5
            $httpClient,
82 5
            $this->messageFactory,
83 5
            $schema,
84 5
            new MessageValidator($this->validator, $this->decoder),
85 5
            $this->serializer,
86 5
            $config
87
        );
88
    }
89
}
90