Passed
Pull Request — master (#87)
by Dmitriy
02:45
created

Action::__invoke()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 3
dl 0
loc 14
ccs 8
cts 8
cp 1
crap 1
rs 10
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Infrastructure\IO\Http\Blog\PostCreate;
6
7
use App\Application\Blog\UseCase\Post\Create\Command;
8
use App\Application\Blog\UseCase\Post\Create\Handler;
9
use App\Infrastructure\IO\Http\Blog\PostCreate\Request\Request;
10
use App\Infrastructure\IO\Http\Blog\PostCreate\Response\ResponseFactory;
11
use OpenApi\Annotations as OA;
12
use Psr\Http\Message\ResponseInterface;
13
14
/**
15
 * @OA\Tag(
16
 *     name="blog",
17
 *     description="Blog"
18
 * )
19
 *
20
 * @OA\Post(
21
 *     tags={"blog"},
22
 *     path="/blog/",
23
 *     summary="Creates a blog post",
24
 *     description="",
25
 *     security={{"ApiKey": {}}},
26
 *     @OA\Response(
27
 *          response="200",
28
 *          description="Success",
29
 *          @OA\JsonContent(
30
 *              ref="#/components/schemas/Response"
31
 *          )
32
 *    ),
33
 *     @OA\RequestBody(
34
 *          required=true,
35
 *          @OA\MediaType(
36
 *              mediaType="application/json",
37
 *              @OA\Schema(ref="#/components/schemas/BlogPostCreate"),
38
 *          ),
39
 *     ),
40
 * )
41
 */
42
final class Action
43
{
44 1
    public function __invoke(
45
        Request $request,
46
        Handler $handler,
47
        ResponseFactory $responseFactory,
48
    ): ResponseInterface {
49 1
        $command = new Command(
50 1
            $request->getTitle(),
51 1
            $request->getText(),
52 1
            $request->getStatus(),
53 1
            $request->getUser(),
54
        );
55 1
        $handler->handle($command);
56
57 1
        return $responseFactory->create();
58
    }
59
}
60