Passed
Pull Request — master (#115)
by Dmitriy
23:50 queued 08:56
created

PostController::index()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 2
1
<?php
2
3
namespace App\Blog\Post;
4
5
use App\ViewRenderer;
6
use Psr\Http\Message\ResponseInterface as Response;
7
use Psr\Http\Message\ServerRequestInterface as Request;
8
9
final class PostController
10
{
11
    private ViewRenderer $viewRenderer;
12
13
    public function __construct(ViewRenderer $viewRenderer)
14
    {
15
        $this->viewRenderer = $viewRenderer->withControllerName('blog/post');
16
    }
17
18
    public function index(Request $request, PostRepository $postRepository): Response
19
    {
20
        $slug = $request->getAttribute('slug', null);
21
        $item = $postRepository->fullPostPage($slug);
22
        if ($item === null) {
23
            return $this->responseFactory->createResponse(404);
0 ignored issues
show
Bug Best Practice introduced by
The property responseFactory does not exist on App\Blog\Post\PostController. Did you maybe forget to declare it?
Loading history...
24
        }
25
26
        return $this->viewRenderer->render('index', ['item' => $item]);
27
    }
28
}
29