GetSubForumController::__invoke()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 6
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 10
rs 10
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