Passed
Pull Request — master (#49)
by
unknown
11:29
created

BlogController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getId() 0 3 1
A index() 0 33 1
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 App\Pagination\PaginationSet;
14
use Cycle\ORM\ORMInterface;
15
use Psr\Http\Message\ResponseInterface as Response;
16
use Psr\Http\Message\ServerRequestInterface as Request;
17
use Yiisoft\Data\Paginator\OffsetPaginator;
18
use Yiisoft\Router\UrlGeneratorInterface;
19
20
final class BlogController extends Controller
21
{
22
    private const POSTS_PER_PAGE = 3;
23
    private const POPULAR_TAGS_COUNT = 10;
24
25
    protected function getId(): string
26
    {
27
        return 'blog';
28
    }
29
30
    public function index(
31
        Request $request,
32
        ORMInterface $orm,
33
        UrlGeneratorInterface $urlGenerator,
34
        ArchiveRepository $archiveRepo
35
    ): Response {
36
        /** @var PostRepository $postRepo */
37
        $postRepo = $orm->getRepository(Post::class);
38
        /** @var TagRepository $postRepo */
39
        $tagRepo = $orm->getRepository(Tag::class);
40
41
        $pageNum = (int)$request->getAttribute('page', 1);
42
43
        $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

43
        /** @scrutinizer ignore-call */ 
44
        $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...
44
        $pageUrlGenerator = fn ($page) => $urlGenerator->generate('blog/index', ['page' => $page]);
45
46
        $paginationSet = new PaginationSet(
0 ignored issues
show
Deprecated Code introduced by
The class App\Pagination\PaginationSet has been deprecated: Should be replaced to a Pagination Widget ( Ignorable by Annotation )

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

46
        $paginationSet = /** @scrutinizer ignore-deprecated */ new PaginationSet(
Loading history...
47
            (new OffsetPaginator($dataReader))
48
                ->withPageSize(self::POSTS_PER_PAGE)
49
                ->withCurrentPage($pageNum),
50
            $pageUrlGenerator
51
        );
52
53
        $data = [
54
            'paginationSet' => $paginationSet,
55
            'archive' => $archiveRepo->getFullArchive()->withLimit(12),
56
            '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

56
            'tags' => $tagRepo->/** @scrutinizer ignore-call */ getTagMentions(self::POPULAR_TAGS_COUNT),
Loading history...
57
        ];
58
        $output = $this->render(__FUNCTION__, $data);
59
60
        $response = $this->responseFactory->createResponse();
61
        $response->getBody()->write($output);
62
        return $response;
63
    }
64
}
65