ApiCrosswordAdapter   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 32
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A construct() 0 16 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Game\Infrastructure\Adapter\Crossword;
6
7
use App\Game\Features\GamePlay\Crossword\ApiClientException;
8
use App\Game\Features\GamePlay\Crossword\CrosswordCriteria;
9
use App\Game\Features\GamePlay\Crossword\CrosswordDto;
10
use App\Game\Features\GamePlay\Crossword\CrosswordInterface;
11
use App\Game\Infrastructure\HttpClient\ResponseDataExtractorInterface;
12
use GuzzleHttp\Psr7\Request;
0 ignored issues
show
Bug introduced by
The type GuzzleHttp\Psr7\Request 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...
13
use Psr\Http\Client\ClientInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Client\ClientInterface 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...
14
use Throwable;
15
16
final class ApiCrosswordAdapter implements CrosswordInterface
17
{
18
    private string $crosswordApiHost;
19
    private ClientInterface $client;
20
    private ResponseDataExtractorInterface $responseDataExtractor;
21
22
    public function __construct(
23
        ClientInterface $client,
24
        ResponseDataExtractorInterface $responseDataExtractor,
25
        string $crosswordApiHost
26
    ) {
27
        $this->client = $client;
28
        $this->crosswordApiHost = $crosswordApiHost;
29
        $this->responseDataExtractor = $responseDataExtractor;
30
    }
31
32
    public function construct(CrosswordCriteria $criteria): CrosswordDto
33
    {
34
        $uri = sprintf(
35
            '%s/construct/%s/%s/%d',
36
            $this->crosswordApiHost,
37
            $criteria->language(),
38
            $criteria->type(),
39
            $criteria->wordCount()
40
        );
41
42
        try {
43
            $response = $this->client->sendRequest(new Request('GET', $uri));
44
45
            return new CrosswordDto($this->responseDataExtractor->extract($response));
46
        } catch (Throwable $exception) {
47
            throw ApiClientException::badRequest($exception->getMessage());
48
        }
49
    }
50
}
51