TagController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A index() 0 20 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog\Tag;
6
7
use App\Blog\Post\PostRepository;
8
use Psr\Http\Message\ResponseFactoryInterface;
0 ignored issues
show
Bug introduced by
The type Psr\Http\Message\ResponseFactoryInterface 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 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...
10
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...
11
use Yiisoft\Router\CurrentRoute;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Router\CurrentRoute 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
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...
13
14
final class TagController
15
{
16
    private const POSTS_PER_PAGE = 10;
17
    private ViewRenderer $viewRenderer;
18
19
    public function __construct(ViewRenderer $viewRenderer)
20
    {
21
        $this->viewRenderer = $viewRenderer->withControllerName('blog/tag');
22
    }
23
24
    public function index(CurrentRoute $currentRoute, TagRepository $tagRepository, PostRepository $postRepository, ResponseFactoryInterface $responseFactory): Response
25
    {
26
        $label = $currentRoute->getArgument('label');
27
        $pageNum = (int) $currentRoute->getArgument('page', '1');
28
        $item = $tagRepository->findByLabel($label);
29
30
        if ($item === null) {
31
            return $responseFactory->createResponse(404);
32
        }
33
        // preloading of posts
34
        $paginator = (new OffsetPaginator($postRepository->findByTag($item->getId())))
35
            ->withPageSize(self::POSTS_PER_PAGE)
36
            ->withCurrentPage($pageNum);
37
38
        $data = [
39
            'item' => $item,
40
            'paginator' => $paginator,
41
        ];
42
43
        return $this->viewRenderer->render('index', $data);
44
    }
45
}
46