Test Failed
Pull Request — master (#507)
by Wilmer
03:18
created

CommentController::isAjaxRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog;
6
7
use App\Blog\Comment\CommentService;
8
use Psr\Http\Message\ResponseInterface as Response;
9
use Psr\Http\Message\ServerRequestInterface as Request;
10
use Yiisoft\Data\Paginator\PaginatorInterface;
11
use Yiisoft\Router\CurrentRoute;
12
use Yiisoft\Yii\View\ViewRenderer;
13
14
final class CommentController
15
{
16
    private ViewRenderer $viewRenderer;
17 1
18
    public function __construct(ViewRenderer $viewRenderer)
19 1
    {
20
        $this->viewRenderer = $viewRenderer->withControllerName('blog/comments');
21
    }
22 1
23
    public function index(Request $request, CommentService $commentService, CurrentRoute $currentRoute): Response
24 1
    {
25 1
        $body = $request->getParsedBody();
26
        $paginator = $commentService->getFeedPaginator();
27
28
        $pageSize = (int) $currentRoute->getArgument(
29 1
            'pagesize',
30
            $body['pageSize'] ?? (string) PaginatorInterface::DEFAULT_PAGE_SIZE,
31
        );
32
33 1
        $paginator = $paginator->withPageSize($pageSize);
34
35
        if ($currentRoute->getArgument('page') !== null) {
36 1
            $paginator = $paginator
37
                ->withNextPageToken((string) $currentRoute->getArgument('page'))
38 1
                ->withPageSize($pageSize);
39
        }
40
41
        return $this->viewRenderer->render('index', ['paginator' => $paginator]);
42
    }
43
}
44