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

ResponseFactory::create()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 9
nc 2
nop 1
dl 0
loc 14
rs 9.9666
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\IO\Http\Blog\GetIndex\Response;
6
7
use App\Infrastructure\Http\Formatter\PaginatorFormatter;
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\Data\Paginator\PaginatorInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Data\Paginator\PaginatorInterface 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\DataResponseFactoryInterface;
0 ignored issues
show
Bug introduced by
The type Yiisoft\DataResponse\DataResponseFactoryInterface 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
12
final class ResponseFactory
13
{
14
    public function __construct(
15
        private DataResponseFactoryInterface $responseFactory,
16
        private PaginatorFormatter $paginatorFormatter,
17
    ) {
18
    }
19
20
    public function create(PaginatorInterface $paginator): ResponseInterface
21
    {
22
        $response = [];
23
        foreach ($paginator->read() as $post) {
24
            $response[] = new Response(
25
                $post->getId(),
26
                $post->getTitle(),
27
                $post->getContent(),
28
            );
29
        }
30
31
        return $this->responseFactory->createResponse([
32
            'posts' => $response,
33
            'paginator' => $this->paginatorFormatter->format($paginator),
34
        ]);
35
    }
36
}
37