Config::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 0
nc 1
nop 15
dl 0
loc 17
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\LazyJsonPages\Data;
6
7
use Cerbero\LazyJsonPages\Paginations\Pagination;
8
use Cerbero\LazyJsonPages\Services\RateLimits;
9
use Closure;
10
11
/**
12
 * The configuration
13
 *
14
 * @property-read class-string<Pagination> $pagination
15
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<Pagination> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<Pagination>.
Loading history...
16
final class Config
17
{
18
    /**
19
     * The configuration options.
20
     */
21
    public const OPTION_PAGE_NAME = 'pageName';
22
    public const OPTION_PAGE_IN_PATH = 'pageInPath';
23
    public const OPTION_FIRST_PAGE = 'firstPage';
24
    public const OPTION_TOTAL_PAGES_KEY = 'totalPagesKey';
25
    public const OPTION_TOTAL_ITEMS_KEY = 'totalItemsKey';
26
    public const OPTION_CURSOR_KEY = 'cursorKey';
27
    public const OPTION_LAST_PAGE_KEY = 'lastPageKey';
28
    public const OPTION_OFFSET_KEY = 'offsetKey';
29
    public const OPTION_HAS_LINK_HEADER = 'hasLinkHeader';
30
    public const OPTION_PAGINATION = 'pagination';
31
    public const OPTION_RATE_LIMITS = 'rateLimits';
32
    public const OPTION_ASYNC = 'async';
33
    public const OPTION_ATTEMPTS = 'attempts';
34
    public const OPTION_BACKOFF = 'backoff';
35
    public const OPTION_ITEMS_POINTER = 'itemsPointer';
36
37
    /**
38
     * Instantiate the class.
39
     */
40 50
    public function __construct(
41
        public readonly string $itemsPointer,
42
        public readonly string $pageName = 'page',
43
        public readonly int $firstPage = 1,
44
        public readonly ?string $pageInPath = null,
45
        public readonly ?string $totalPagesKey = null,
46
        public readonly ?string $totalItemsKey = null,
47
        public readonly ?string $cursorKey = null,
48
        public readonly ?string $lastPageKey = null,
49
        public readonly ?string $offsetKey = null,
50
        public readonly bool $hasLinkHeader = false,
51
        public readonly ?string $pagination = null,
52
        public readonly ?RateLimits $rateLimits = null,
53
        public readonly int $async = 1,
54
        public readonly int $attempts = 3,
55
        public readonly ?Closure $backoff = null,
56 50
    ) {}
57
}
58