GetnetSubSellerIdOptions   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 88
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A toOptionArray() 0 3 1
A __construct() 0 10 1
A getSubSellerIdTree() 0 26 3
1
<?php
2
/**
3
 * Copyright © Getnet. All rights reserved.
4
 *
5
 * @author    Bruno Elisei <[email protected]>
6
 * See LICENSE for license details.
7
 */
8
9
namespace Getnet\SplitExampleMagento\Ui\Component\Form\Product;
10
11
use Getnet\SubSellerMagento\Api\SubSellerRepositoryInterface;
0 ignored issues
show
Bug introduced by
The type Getnet\SubSellerMagento\...llerRepositoryInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Magento\Framework\Api\FilterBuilder;
13
use Magento\Framework\Api\SearchCriteriaBuilder;
14
use Magento\Framework\App\RequestInterface;
15
use Magento\Framework\Data\OptionSourceInterface;
16
17
class GetnetSubSellerIdOptions implements OptionSourceInterface
18
{
19
    /**
20
     * @var SubSellerRepositoryInterface
21
     */
22
    protected $subSellerRepository;
23
24
    /**
25
     * @var SearchCriteriaBuilder
26
     */
27
    protected $searchCriteria;
28
29
    /**
30
     * @var FilterBuilder
31
     */
32
    protected $filterBuilder;
33
34
    /**
35
     * @var RequestInterface
36
     */
37
    protected $request;
38
39
    /**
40
     * @var array
41
     */
42
    protected $subSellerIdTree;
43
44
    /**
45
     * Constructor.
46
     *
47
     * @param SubSellerRepositoryInterface $subSellerRepository
48
     * @param SearchCriteriaBuilder        $searchCriteria
49
     * @param FilterBuilder                $filterBuilder
50
     * @param RequestInterface             $request
51
     */
52
    public function __construct(
53
        SubSellerRepositoryInterface $subSellerRepository,
54
        SearchCriteriaBuilder $searchCriteria,
55
        FilterBuilder $filterBuilder,
56
        RequestInterface $request
57
    ) {
58
        $this->subSellerRepository = $subSellerRepository;
59
        $this->searchCriteria = $searchCriteria;
60
        $this->filterBuilder = $filterBuilder;
61
        $this->request = $request;
62
    }
63
64
    /**
65
     * Get Options.
66
     *
67
     * @return array
68
     */
69
    public function toOptionArray(): array
70
    {
71
        return $this->getSubSellerIdTree();
72
    }
73
74
    /**
75
     * Get Options.
76
     *
77
     * @return array
78
     */
79
    public function getSubSellerIdTree(): array
80
    {
81
        if ($this->subSellerIdTree === null) {
82
            $sellers = [];
83
            $searchCriteria = $this->searchCriteria->addFilters(
84
                [
85
                    $this->filterBuilder->setField('id_ext')->setValue(null)->setConditionType('neq')->create(),
86
                ]
87
            )->create();
88
            $subSellers = $this->subSellerRepository->getList($searchCriteria);
89
90
            foreach ($subSellers->getItems() as $subSeller) {
91
                $sellers[$subSeller->getIdExt()] = [
92
                    'value' => $subSeller->getIdExt(),
93
                    'label' => sprintf(
94
                        '%s - Código Interno: %s - Email: %s',
95
                        $subSeller->getLegalName(),
96
                        $subSeller->getCode(),
97
                        $subSeller->getEmail()
98
                    ),
99
                ];
100
            }
101
            $this->subSellerIdTree = $sellers;
102
        }
103
104
        return $this->subSellerIdTree;
105
    }
106
}
107