Passed
Pull Request — master (#49)
by
unknown
13:21
created

BlogController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 15
c 1
b 0
f 0
dl 0
loc 25
rs 9.7666
cc 1
nc 1
nop 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog;
6
7
use App\Blog\Archive\ArchiveRepository;
8
use App\Controller;
9
use App\Blog\Entity\Post;
10
use App\Blog\Entity\Tag;
11
use App\Blog\Post\PostRepository;
12
use App\Blog\Tag\TagRepository;
13
use Cycle\ORM\ORMInterface;
14
use Psr\Http\Message\ResponseInterface as Response;
15
use Psr\Http\Message\ServerRequestInterface as Request;
16
use Yiisoft\Data\Paginator\OffsetPaginator;
17
18
final class BlogController extends Controller
19
{
20
    private const POSTS_PER_PAGE = 3;
21
    private const POPULAR_TAGS_COUNT = 10;
22
23
    protected function getId(): string
24
    {
25
        return 'blog';
26
    }
27
28
    public function index(Request $request, ORMInterface $orm, ArchiveRepository $archiveRepo): Response
29
    {
30
        /** @var PostRepository $postRepo */
31
        $postRepo = $orm->getRepository(Post::class);
32
        /** @var TagRepository $postRepo */
33
        $tagRepo = $orm->getRepository(Tag::class);
34
35
        $pageNum = (int)$request->getAttribute('page', 1);
36
37
        $dataReader = $postRepo->findAllPreloaded();
0 ignored issues
show
Bug introduced by
The method findAllPreloaded() does not exist on App\Blog\Tag\TagRepository. Did you maybe mean findAll()? ( Ignorable by Annotation )

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

37
        /** @scrutinizer ignore-call */ 
38
        $dataReader = $postRepo->findAllPreloaded();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
38
39
        $paginator = (new OffsetPaginator($dataReader))
40
            ->withPageSize(self::POSTS_PER_PAGE)
41
            ->withCurrentPage($pageNum);
42
43
        $data = [
44
            'paginator' => $paginator,
45
            'archive' => $archiveRepo->getFullArchive()->withLimit(12),
46
            'tags' => $tagRepo->getTagMentions(self::POPULAR_TAGS_COUNT),
0 ignored issues
show
Bug introduced by
The method getTagMentions() does not exist on Cycle\ORM\RepositoryInterface. It seems like you code against a sub-type of Cycle\ORM\RepositoryInterface such as App\Blog\Tag\TagRepository. ( Ignorable by Annotation )

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

46
            'tags' => $tagRepo->/** @scrutinizer ignore-call */ getTagMentions(self::POPULAR_TAGS_COUNT),
Loading history...
47
        ];
48
        $output = $this->render(__FUNCTION__, $data);
49
50
        $response = $this->responseFactory->createResponse();
51
        $response->getBody()->write($output);
52
        return $response;
53
    }
54
}
55