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

ImportReviews::import()   A

Complexity

Conditions 4
Paths 15

Size

Total Lines 27
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 27
ccs 0
cts 23
cp 0
rs 9.568
cc 4
nc 15
nop 1
crap 20
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