ListAction   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 23
ccs 4
cts 4
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http\Action\Post;
6
7
use App\Model\Post\PostRepository;
8
use HttpSoft\Basis\Response\PrepareJsonDataTrait;
9
use HttpSoft\Response\JsonResponse;
10
use Psr\Http\Message\ResponseInterface;
11
use Psr\Http\Message\ServerRequestInterface;
12
use Psr\Http\Server\RequestHandlerInterface;
13
14
final class ListAction implements RequestHandlerInterface
15
{
16
    use PrepareJsonDataTrait;
17
18
    /**
19
     * @var PostRepository
20
     */
21
    private PostRepository $posts;
22
23
    /**
24
     * @param PostRepository $posts
25
     */
26 2
    public function __construct(PostRepository $posts)
27
    {
28 2
        $this->posts = $posts;
29
    }
30
31
    /**
32
     * {@inheritDoc}
33
     */
34 2
    public function handle(ServerRequestInterface $request): ResponseInterface
35
    {
36 2
        return new JsonResponse($this->prepareJsonData($this->posts->findAll()));
37
    }
38
}
39