Passed
Pull Request — master (#108)
by Dmitriy
14:16
created

ArchiveController::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
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Blog\Archive;
4
5
use App\Blog\Entity\Tag;
6
use App\Blog\Tag\TagRepository;
7
use App\Controller;
8
use Cycle\ORM\ORMInterface;
9
use Psr\Http\Message\ResponseInterface as Response;
10
use Psr\Http\Message\ServerRequestInterface as Request;
11
use Yiisoft\Data\Paginator\OffsetPaginator;
12
13
final class ArchiveController extends Controller
14
{
15
    protected static ?string $controllerName = 'blog/archive';
16
17
    private const POSTS_PER_PAGE = 3;
18
    private const POPULAR_TAGS_COUNT = 10;
19
20
    public function index(ArchiveRepository $archiveRepo): Response
21
    {
22
        return $this->render('index', ['archive' => $archiveRepo->getFullArchive()]);
23
    }
24
25
    public function monthlyArchive(Request $request, ORMInterface $orm, ArchiveRepository $archiveRepo): Response
26
    {
27
        /** @var TagRepository $postRepo */
28
        $tagRepo = $orm->getRepository(Tag::class);
29
30
        $pageNum = (int)$request->getAttribute('page', 1);
31
        $year = $request->getAttribute('year', null);
32
        $month = $request->getAttribute('month', null);
33
34
        $dataReader = $archiveRepo->getMonthlyArchive($year, $month);
35
        $paginator = (new OffsetPaginator($dataReader))
36
            ->withPageSize(self::POSTS_PER_PAGE)
37
            ->withCurrentPage($pageNum);
38
39
        $data = [
40
            'year' => $year,
41
            'month' => $month,
42
            'paginator' => $paginator,
43
            'archive' => $archiveRepo->getFullArchive()->withLimit(12),
44
            '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

44
            'tags' => $tagRepo->/** @scrutinizer ignore-call */ getTagMentions(self::POPULAR_TAGS_COUNT),
Loading history...
45
        ];
46
        return $this->render('monthly-archive', $data);
47
    }
48
49
    public function yearlyArchive(Request $request, ArchiveRepository $archiveRepo): Response
50
    {
51
        $year = $request->getAttribute('year', null);
52
53
        $data = [
54
            'year' => $year,
55
            'items' => $archiveRepo->getYearlyArchive($year),
56
        ];
57
        return $this->render('yearly-archive', $data);
58
    }
59
}
60