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

ImportProductReviewsAttachments   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 10
dl 0
loc 22
rs 10
c 1
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A response() 0 4 1
A handle() 0 3 1
A __construct() 0 5 1
1
<?php
2
3
namespace GeminiLabs\SiteReviews\Integrations\WooCommerce\Commands;
4
5
use GeminiLabs\SiteReviews\Commands\AbstractCommand;
6
use GeminiLabs\SiteReviews\Database\ImportManager;
7
use GeminiLabs\SiteReviews\Defaults\ImportResultDefaults;
8
use GeminiLabs\SiteReviews\Request;
9
10
class ImportProductReviewsAttachments extends AbstractCommand
11
{
12
    protected int $limit;
13
    protected int $offset;
14
    protected array $importResult;
15
16
    public function __construct(Request $request)
17
    {
18
        $this->limit = max(1, $request->cast('per_page', 'int'));
19
        $this->offset = $this->limit * (max(1, $request->cast('page', 'int')) - 1);
20
        $this->importResult = glsr(ImportResultDefaults::class)->defaults();
21
    }
22
23
    public function handle(): void
24
    {
25
        $this->importResult = glsr(ImportManager::class)->importAttachments($this->limit, $this->offset);
26
    }
27
28
    public function response(): array
29
    {
30
        return wp_parse_args($this->importResult, [
31
            'message' => _x('Imported %d attachments', 'admin-text', 'site-reviews'),
32
        ]);
33
    }
34
}
35