Passed
Pull Request — master (#572)
by Dmitriy
01:31
created

ApiResponseFormatter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 22
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 9 1
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\Http\Formatter;
6
7
use App\Infrastructure\Http\Response\ApiResponseDataFactory;
8
use Psr\Http\Message\ResponseInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface 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 Yiisoft\DataResponse\DataResponse;
0 ignored issues
show
Bug introduced by
The type Yiisoft\DataResponse\DataResponse 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...
10
use Yiisoft\DataResponse\DataResponseFormatterInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\DataResponse\Dat...ponseFormatterInterface 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 Yiisoft\DataResponse\Formatter\JsonDataResponseFormatter;
0 ignored issues
show
Bug introduced by
The type Yiisoft\DataResponse\For...onDataResponseFormatter 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
final class ApiResponseFormatter implements DataResponseFormatterInterface
14
{
15
    private ApiResponseDataFactory $apiResponseDataFactory;
16
    private JsonDataResponseFormatter $jsonDataResponseFormatter;
17
18
    public function __construct(
19
        ApiResponseDataFactory $apiResponseDataFactory,
20
        JsonDataResponseFormatter $jsonDataResponseFormatter
21
    ) {
22
        $this->apiResponseDataFactory = $apiResponseDataFactory;
23
        $this->jsonDataResponseFormatter = $jsonDataResponseFormatter;
24
    }
25
26
    public function format(DataResponse $dataResponse): ResponseInterface
27
    {
28
        $response = $dataResponse->withData(
29
            $this->apiResponseDataFactory
30
                ->createFromResponse($dataResponse)
31
                ->toArray()
32
        );
33
34
        return $this->jsonDataResponseFormatter->format($response);
35
    }
36
}
37