UserController   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 15
c 2
b 1
f 0
dl 0
loc 41
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A index() 0 20 2
A profile() 0 12 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\User\Controller;
6
7
use App\User\UserRepository;
8
use Yiisoft\Data\Paginator\PageToken;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Data\Paginator\PageToken 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\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...
10
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...
11
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...
12
use Yiisoft\Data\Reader\Sort;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Data\Reader\Sort 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
use Yiisoft\Input\Http\Attribute\Parameter\Body;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Input\Http\Attribute\Parameter\Body 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...
14
use Yiisoft\Input\Http\Attribute\Parameter\Query;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Input\Http\Attribute\Parameter\Query 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...
15
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...
16
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...
17
18
final class UserController
19
{
20
    public function __construct(private ViewRenderer $viewRenderer)
21
    {
22
        $this->viewRenderer = $viewRenderer->withControllerName('user');
23
    }
24
25
    public function index(
26
        UserRepository $userRepository,
27
        #[Body] ?array $body,
28
        #[Query('sort')] ?string $sortOrder = null,
29
        #[RouteArgument('page')] int $page = 1,
30
        #[RouteArgument('pagesize')] int $pageSize = null,
31
    ): Response {
32
        $dataReader = $userRepository
33
            ->findAll()
34
            ->withSort(Sort::only(['id', 'login'])
35
            ->withOrderString($sortOrder ?? 'id'));
36
37
        if ($pageSize === null) {
38
            $pageSize = (int) ($body['pageSize'] ?? OffSetPaginator::DEFAULT_PAGE_SIZE);
39
        }
40
41
        $paginator = (new OffsetPaginator($dataReader));
42
        $paginator = $paginator->withToken(PageToken::next((string) $page))->withPageSize($pageSize);
43
44
        return $this->viewRenderer->render('index', ['paginator' => $paginator]);
45
    }
46
47
    public function profile(
48
        #[RouteArgument('login')] string $login,
49
        ResponseFactoryInterface $responseFactory,
50
        UserRepository $userRepository
51
    ): Response {
52
        $item = $userRepository->findByLogin($login);
53
54
        if ($item === null) {
55
            return $responseFactory->createResponse(404);
56
        }
57
58
        return $this->viewRenderer->render('profile', ['item' => $item]);
59
    }
60
}
61