ArchiveController   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 23
c 0
b 0
f 0
dl 0
loc 49
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A index() 0 3 1
A monthlyArchive() 0 23 1
A yearlyArchive() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog\Archive;
6
7
use App\Blog\Tag\TagRepository;
8
use Psr\Http\Message\ResponseInterface as Response;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Yiisoft\Data\Paginator\OffsetPaginator;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Data\Paginator\OffsetPaginator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Yiisoft\Router\HydratorAttribute\RouteArgument;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Router\HydratorAttribute\RouteArgument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Yiisoft\Yii\View\Renderer\ViewRenderer;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Yii\View\Renderer\ViewRenderer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
final class ArchiveController
14
{
15
    private const POSTS_PER_PAGE = 3;
16
    private const POPULAR_TAGS_COUNT = 10;
17
    private ViewRenderer $viewRenderer;
18
19
    public function __construct(ViewRenderer $viewRenderer)
20
    {
21
        $this->viewRenderer = $viewRenderer->withControllerName('blog/archive');
22
    }
23
24
    public function index(ArchiveRepository $archiveRepo): Response
25
    {
26
        return $this->viewRenderer->render('index', ['archive' => $archiveRepo->getFullArchive()]);
27
    }
28
29
    public function monthlyArchive(
30
        TagRepository $tagRepository,
31
        ArchiveRepository $archiveRepo,
32
        #[RouteArgument('page')] int $pageNum = 1,
33
        #[RouteArgument('year')] int $year = 0,
34
        #[RouteArgument('month')] int $month = 0,
35
    ): Response {
36
        $dataReader = $archiveRepo->getMonthlyArchive($year, $month);
37
        $paginator = (new OffsetPaginator($dataReader))
38
            ->withPageSize(self::POSTS_PER_PAGE)
39
            ->withCurrentPage($pageNum);
40
41
        $data = [
42
            'year' => $year,
43
            'month' => $month,
44
            'paginator' => $paginator,
45
            'archive' => $archiveRepo
46
                ->getFullArchive()
47
                ->withLimit(12),
48
            'tags' => $tagRepository->getTagMentions(self::POPULAR_TAGS_COUNT),
49
        ];
50
51
        return $this->viewRenderer->render('monthly-archive', $data);
52
    }
53
54
    public function yearlyArchive(ArchiveRepository $archiveRepo, #[RouteArgument('year')] int $year = 0): Response
55
    {
56
        $data = [
57
            'year' => $year,
58
            'items' => $archiveRepo->getYearlyArchive($year),
59
        ];
60
61
        return $this->viewRenderer->render('yearly-archive', $data);
62
    }
63
}
64