Test Failed
Push — develop ( 5be0e5...3f5c00 )
by Paul
14:23
created

ImportReviews::createReader()   A

Complexity

Conditions 6
Paths 9

Size

Total Lines 23
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 23
ccs 0
cts 15
cp 0
rs 9.0777
c 0
b 0
f 0
cc 6
nc 9
nop 1
crap 42
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Commands;
4
5
use GeminiLabs\SiteReviews\Database\ImportManager;
6
use GeminiLabs\SiteReviews\Defaults\ImportResultDefaults;
7
use GeminiLabs\SiteReviews\Request;
8
9
class ImportReviews extends AbstractCommand
10
{
11
    protected int $limit;
12
    protected int $offset;
13
    protected array $importResult;
14
15
    public function __construct(Request $request)
16
    {
17
        $this->limit = max(1, $request->cast('per_page', 'int'));
18
        $this->offset = $this->limit * (max(1, $request->cast('page', 'int')) - 1);
19
        $this->importResult = glsr(ImportResultDefaults::class)->defaults();
20
    }
21
22
    public function handle(): void
23
    {
24
        $this->importResult = glsr(ImportManager::class)->import($this->limit, $this->offset);
25
    }
26
27
    public function response(): array
28
    {
29
        return wp_parse_args($this->importResult, [
30
            'message' => _x('Processed %d of %d reviews', 'admin-text', 'site-reviews'),
31
        ]);
32
    }
33
}
34