GetSubForumController   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 12
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 10 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace App\Http\Controllers\SubForums;
6
7
use App\Http\Controllers\Controller;
8
use Illuminate\Http\JsonResponse;
9
use TrophyForum\SubForums\Application\Find\FindSubForumQuery;
10
use TrophyForum\SubForums\Application\Find\FindSubForumQueryHandler;
11
use TrophyForum\SubForums\Domain\SubForumNotExist;
12
13
final class GetSubForumController extends Controller
14
{
15
    public function __invoke(string $subForumId): JsonResponse
16
    {
17
        try {
18
            $this->bus->addHandler(FindSubForumQuery::class, FindSubForumQueryHandler::class);
19
20
            return JsonResponse::create(
21
                $this->bus->dispatch(new FindSubForumQuery($subForumId))
22
            );
23
        } catch (SubForumNotExist $e) {
24
            return JsonResponse::create(['message' => $e->getMessage()], 404);
25
        }
26
    }
27
}
28