Issues (867)

blog/src/Blog/CommentController.php (8 issues)

1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog;
6
7
use App\Blog\Comment\CommentRepository;
8
use Psr\Http\Message\ResponseInterface as Response;
0 ignored issues
show
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 Psr\Http\Message\ServerRequestInterface as Request;
0 ignored issues
show
The type Psr\Http\Message\ServerRequestInterface 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
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\Data\Paginator\PageToken;
0 ignored issues
show
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...
12
use Yiisoft\Input\Http\Attribute\Parameter\Body;
0 ignored issues
show
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...
13
use Yiisoft\Input\Http\Attribute\Parameter\Query;
0 ignored issues
show
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...
14
use Yiisoft\Router\HydratorAttribute\RouteArgument;
0 ignored issues
show
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...
15
use Yiisoft\Yii\View\Renderer\ViewRenderer;
0 ignored issues
show
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...
16
17
final class CommentController
18
{
19
    private const COMMENTS_FEED_PER_PAGE = 10;
20
    private ViewRenderer $viewRenderer;
21
22
    public function __construct(ViewRenderer $viewRenderer)
23
    {
24
        $this->viewRenderer = $viewRenderer->withControllerName('blog/comments');
25
    }
26
27
    public function index(
28
        Request $request,
29
        CommentRepository $repository,
30
        #[Body] ?array $body,
31
        #[Query('sort')] ?string $sortOrder = null,
32
        #[RouteArgument('page')] int $page = 1,
33
        #[RouteArgument('pagesize')] int $pageSize = null,
34
    ): Response {
35
        $dataReader = $repository
36
            ->findAll()
37
            ->withSort($repository->getSort()
38
                ->withOrderString($sortOrder ?? 'id'));
39
40
        if ($pageSize === null) {
41
            $pageSize = (int) ($body['pageSize'] ?? self::COMMENTS_FEED_PER_PAGE);
42
        }
43
        $paginator = (new OffsetPaginator($dataReader));
44
        $paginator = $paginator->withToken(PageToken::next((string) $page))->withPageSize($pageSize);
45
46
47
        if ($this->isAjaxRequest($request)) {
48
            return $this->viewRenderer->renderPartial('_comments', ['data' => $paginator]);
49
        }
50
51
        return $this->viewRenderer->render('index', ['data' => $paginator]);
52
    }
53
54
    private function isAjaxRequest(Request $request): bool
55
    {
56
        return $request->getHeaderLine('X-Requested-With') === 'XMLHttpRequest';
57
    }
58
}
59