Passed
Push — master ( 3581f7...005bcc )
by De Cramer
05:10 queued 03:31
created

SimpleHttpOperationFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 42
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configureValidator() 0 22 1
A build() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Oliverde8\Component\PhpEtl\Builder\Factories\Transformer;
6
7
use Oliverde8\Component\PhpEtl\Builder\Factories\AbstractFactory;
8
use Oliverde8\Component\PhpEtl\ChainOperation\ChainOperationInterface;
9
use Oliverde8\Component\PhpEtl\ChainOperation\Transformer\SimpleHttpOperation;
10
use Symfony\Component\HttpClient\HttpClient;
0 ignored issues
show
Bug introduced by
The type Symfony\Component\HttpClient\HttpClient was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Symfony\Component\Validator\Constraint;
12
use Symfony\Component\Validator\Constraints as Assert;
13
14
class SimpleHttpOperationFactory extends AbstractFactory
15
{
16
    protected function build(string $operation, array $options): ChainOperationInterface
17
    {
18
        if (!class_exists(HttpClient::class)) {
19
            throw new \LogicException("You can not used SimpleHttpOperation as symfony/http-client is not installed");
20
        }
21
22
        $httpClient = HttpClient::create($options['options']);
23
24
        return new SimpleHttpOperation(
25
            $httpClient,
26
            $options['method'],
27
            $options['url'],
28
            $options['response_is_json'] ?? false,
29
            $options['option_key'] ?? null,
30
            $options['response_key'] ?? null,
31
        );
32
    }
33
34
    protected function configureValidator(): Constraint
35
    {
36
        return new Assert\Collection([
37
            'method' => [
38
                new Assert\Choice(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD']),
39
                new Assert\NotBlank(),
40
            ],
41
            'url' => [
42
                new Assert\Type(["type" => "string"]),
43
                new Assert\NotBlank(),
44
            ],
45
            'response_is_json' => [
46
                new Assert\Type(["type" => "boolean"]),
47
            ],
48
            'option_key' => [
49
                new Assert\Type(["type" => "string"]),
50
            ],
51
            'response_key' => [
52
                new Assert\Type(["type" => "string"]),
53
            ],
54
            'options' => [
55
                new Assert\Type(["type" => "array"]),
56
            ],
57
        ]);
58
    }
59
}