Passed
Pull Request — master (#59)
by Alexander
26:34 queued 11:31
created

PostController::getId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace App\Blog\Post;
4
5
use App\Controller;
6
use App\Blog\Entity\Post;
7
use Cycle\ORM\ORMInterface;
8
use Psr\Http\Message\ResponseInterface as Response;
9
use Psr\Http\Message\ServerRequestInterface as Request;
10
11
final class PostController extends Controller
12
{
13
    protected function getId(): string
14
    {
15
        return 'blog/post';
16
    }
17
18
    public function index(Request $request, ORMInterface $orm): Response
19
    {
20
        $postRepo = $orm->getRepository(Post::class);
21
        $slug = $request->getAttribute('slug', null);
22
23
        $item = $postRepo->fullPostPage($slug);
0 ignored issues
show
Bug introduced by
The method fullPostPage() does not exist on Cycle\ORM\RepositoryInterface. It seems like you code against a sub-type of Cycle\ORM\RepositoryInterface such as App\Blog\Post\PostRepository. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        /** @scrutinizer ignore-call */ 
24
        $item = $postRepo->fullPostPage($slug);
Loading history...
24
        if ($item === null) {
25
            return $this->responseFactory->createResponse(404);
26
        }
27
28
        return $this->render('index', ['item' => $item]);
29
    }
30
31
32
    public function allPosts(Request $request, ORMInterface $orm)
33
    {
34
        /** @var PostRepository $postRepo */
35
        $postRepo = $orm->getRepository(Post::class);
36
37
        $dataReader = $postRepo->findAllPreloaded();
38
39
        $data = [
40
            'dataReader' => $dataReader,
41
        ];
42
        return $this->render('allPosts', $data);
43
    }
44
}
45