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

SimpleHttpOperationWithClientFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A configureValidator() 0 22 1
A build() 0 9 1
1
<?php
2
3
namespace Oliverde8\Component\PhpEtl\Builder\Factories\Transformer;
4
5
use Oliverde8\Component\PhpEtl\Builder\Factories\AbstractFactory;
6
use Oliverde8\Component\PhpEtl\ChainOperation\ChainOperationInterface;
7
use Oliverde8\Component\PhpEtl\ChainOperation\Transformer\SimpleHttpOperation;
8
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...
9
use Symfony\Component\Validator\Constraint;
10
use Symfony\Component\Validator\Constraints as Assert;
11
use Symfony\Contracts\HttpClient\HttpClientInterface;
0 ignored issues
show
Bug introduced by
The type Symfony\Contracts\HttpClient\HttpClientInterface 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...
12
13
class SimpleHttpOperationWithClientFactory extends AbstractFactory
14
{
15
    private HttpClientInterface $httpClient;
16
17
    /**
18
     * @param HttpClientInterface $httpClient
19
     */
20
    public function __construct(string $operation, HttpClientInterface $httpClient)
21
    {
22
        $this->httpClient = $httpClient;
23
24
        parent::__construct($operation, SimpleHttpOperation::class);
25
    }
26
27
    protected function build(string $operation, array $options): ChainOperationInterface
28
    {
29
        return new SimpleHttpOperation(
30
            $this->httpClient,
31
            $options['method'],
32
            $options['url'],
33
            $options['response_is_json'] ?? false,
34
            $options['option_key'] ?? null,
35
            $options['response_key'] ?? null,
36
        );
37
    }
38
39
    protected function configureValidator(): Constraint
40
    {
41
        return new Assert\Collection([
42
            'method' => [
43
                new Assert\Choice(['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'HEAD']),
44
                new Assert\NotBlank(),
45
            ],
46
            'url' => [
47
                new Assert\Type(["type" => "string"]),
48
                new Assert\NotBlank(),
49
            ],
50
            'response_is_json' => [
51
                new Assert\Type(["type" => "boolean"]),
52
            ],
53
            'option_key' => [
54
                new Assert\Type(["type" => "string"]),
55
            ],
56
            'response_key' => [
57
                new Assert\Type(["type" => "string"]),
58
            ],
59
            'options' => [
60
                new Assert\Type(["type" => "array"]),
61
            ],
62
        ]);
63
    }
64
}