SubSellerIdColumn::getSourceOptions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 17
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 27
rs 9.7
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
declare(strict_types=1);
10
11
namespace Getnet\SplitExampleMagento\Block\Adminhtml\System\Form\Field\Column;
12
13
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...
14
use Magento\Framework\Api\FilterBuilder;
15
use Magento\Framework\Api\SearchCriteriaBuilder;
16
use Magento\Framework\View\Element\Context;
17
use Magento\Framework\View\Element\Html\Select;
18
19
/**
20
 * Class SubSellerIdColumn - Create Field to Sub Seller Id Column.
21
 */
22
class SubSellerIdColumn extends Select
23
{
24
    /**
25
     * @var SubSellerRepositoryInterface
26
     */
27
    protected $subSellerRepository;
28
29
    /**
30
     * @var SearchCriteriaBuilder
31
     */
32
    protected $searchCriteria;
33
34
    /**
35
     * @var FilterBuilder
36
     */
37
    protected $filterBuilder;
38
39
    /**
40
     * Constructor.
41
     *
42
     * @param Context                      $context
43
     * @param SubSellerRepositoryInterface $subSellerRepository
44
     * @param SearchCriteriaBuilder        $searchCriteria
45
     * @param FilterBuilder                $filterBuilder
46
     * @param array                        $data
47
     */
48
    public function __construct(
49
        Context $context,
50
        SubSellerRepositoryInterface $subSellerRepository,
51
        SearchCriteriaBuilder $searchCriteria,
52
        FilterBuilder $filterBuilder,
53
        array $data = []
54
    ) {
55
        parent::__construct($context, $data);
56
        $this->subSellerRepository = $subSellerRepository;
57
        $this->searchCriteria = $searchCriteria;
58
        $this->filterBuilder = $filterBuilder;
59
    }
60
61
    /**
62
     * Set "name" for <select> element.
63
     *
64
     * @param string $value
65
     *
66
     * @return void
67
     */
68
    public function setInputName($value)
69
    {
70
        return $this->setName($value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->setName($value) also could return the type Getnet\SplitExampleMagen...rIdColumn|array|boolean which is incompatible with the documented return type void.
Loading history...
Bug introduced by
The method setName() does not exist on Getnet\SplitExampleMagen...olumn\SubSellerIdColumn. 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

70
        return $this->/** @scrutinizer ignore-call */ setName($value);
Loading history...
71
    }
72
73
    /**
74
     * Set "id" for <select> element.
75
     *
76
     * @param string $value
77
     *
78
     * @return void
79
     */
80
    public function setInputId($value)
81
    {
82
        return $this->setId($value);
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->setId($value) returns the type Getnet\SplitExampleMagen...olumn\SubSellerIdColumn which is incompatible with the documented return type void.
Loading history...
83
    }
84
85
    /**
86
     * Render block HTML.
87
     *
88
     * @return string
89
     */
90
    public function _toHtml(): string
91
    {
92
        if (!$this->getOptions()) {
93
            $this->setOptions($this->getSourceOptions());
94
        }
95
96
        return parent::_toHtml();
97
    }
98
99
    /**
100
     * Get Options.
101
     *
102
     * @return array
103
     */
104
    public function getSourceOptions(): array
105
    {
106
        $sellers = [];
107
        $sellers[] = [
108
            'value' => 'any',
109
            'label' => __('Any Sub Seller'),
110
        ];
111
        $searchCriteria = $this->searchCriteria->addFilters(
112
            [
113
                $this->filterBuilder->setField('status')->setValue(4)->setConditionType('neq')->create(),
114
            ]
115
        )->create();
116
        $subSellers = $this->subSellerRepository->getList($searchCriteria);
117
118
        foreach ($subSellers->getItems() as $subSeller) {
119
            $sellers[] = [
120
                'value' => $subSeller->getIdExt(),
121
                'label' => sprintf(
122
                    '%s - Code: %s - Email: %s',
123
                    $subSeller->getLegalName(),
124
                    $subSeller->getCode(),
125
                    $subSeller->getEmail()
126
                ),
127
            ];
128
        }
129
130
        return $sellers;
131
    }
132
}
133