CategoryTreeResponder::success()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 16
rs 9.8333
cc 3
nc 4
nop 1
1
<?php
2
declare(strict_types=1);
3
4
/**
5
 * Api Class
6
 * @category    Ticaje
7
 * @author      Max Demian <[email protected]>
8
 */
9
10
namespace Ticaje\AeSdk\Api\Artifact\Responder\Get;
11
12
use Ticaje\Contract\Patterns\Interfaces\Pool\WorkerInterface;
13
use Ticaje\Contract\Patterns\Interfaces\Decorator\Responder\ResponseInterface as ContractResponseInterface;
14
15
use Ticaje\AeSdk\Api\Interfaces\ApiResponderInterface;
16
use Ticaje\AeSdk\Api\Artifact\Responder\Responder;
17
18
/**
19
 * Class CategoryTreeResponder
20
 * @package Ticaje\AeSdk\Api\Artifact\Responder
21
 */
22
class CategoryTreeResponder implements ApiResponderInterface, WorkerInterface
23
{
24
    use Responder;
0 ignored issues
show
Bug introduced by
The trait Ticaje\AeSdk\Api\Artifact\Responder\Responder requires the property $msg which is not provided by Ticaje\AeSdk\Api\Artifac...t\CategoryTreeResponder.
Loading history...
25
26
    private $count;
0 ignored issues
show
introduced by
The private property $count is not used, and could be removed.
Loading history...
27
28
    private $categories = [];
0 ignored issues
show
introduced by
The private property $categories is not used, and could be removed.
Loading history...
29
30
    /**
31
     * @inheritDoc
32
     */
33
    public function process(ContractResponseInterface $response): ApiResponderInterface
34
    {
35
        $content = json_decode($response->getContent());
36
        isset($content->error_response) ? $this->error($content->error_response) : $this->success($content->aliexpress_solution_seller_category_tree_query_response);
37
        return $this;
38
    }
39
40
    protected function success(\stdClass $response)
41
    {
42
        $itemsCount = 0;
43
        $items = null;
44
        if (isset($response->children_category_list)) {
45
            $data = $response->children_category_list;
46
            $itemsCount = count($data->category_info);
47
            $items = $data->category_info;
48
        }
49
        $message = $itemsCount ? "{$itemsCount} categories fetched successfully" : 'No categories found with such criteria';
50
        $this
51
            ->setSuccess(1)
0 ignored issues
show
Bug introduced by
The method setSuccess() does not exist on Ticaje\AeSdk\Api\Artifac...t\CategoryTreeResponder. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
            ->/** @scrutinizer ignore-call */ 
52
              setSuccess(1)
Loading history...
52
            ->setCount($itemsCount)
0 ignored issues
show
Bug introduced by
The method setCount() does not exist on Ticaje\AeSdk\Api\Artifac...t\CategoryTreeResponder. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
            ->/** @scrutinizer ignore-call */ setCount($itemsCount)
Loading history...
53
            ->setCategories($items)
0 ignored issues
show
Bug introduced by
The method setCategories() does not exist on Ticaje\AeSdk\Api\Artifac...t\CategoryTreeResponder. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
            ->/** @scrutinizer ignore-call */ setCategories($items)
Loading history...
54
            ->setCode(200)
0 ignored issues
show
Bug introduced by
The method setCode() does not exist on Ticaje\AeSdk\Api\Artifac...t\CategoryTreeResponder. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

54
            ->/** @scrutinizer ignore-call */ setCode(200)
Loading history...
55
            ->setMessage($message);
0 ignored issues
show
Bug introduced by
The method setMessage() does not exist on Ticaje\AeSdk\Api\Artifac...t\CategoryTreeResponder. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
            ->/** @scrutinizer ignore-call */ setMessage($message);
Loading history...
56
    }
57
}
58