Methods::toOptionArray()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 7
cts 7
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 2
1
<?php
2
3
namespace Meanbee\MagentoRoyalmail\Model\Config\Source;
4
5
use \Magento\Framework\Option\ArrayInterface;
6
use Meanbee\MagentoRoyalmail\Model\Carrier;
7
8
/**
9
 * Class Methods Backend system config field renderer
10
 */
11
class Methods implements ArrayInterface
12
{
13
14
    /**
15
     * @var Carrier $carrier
16
     */
17
    protected $carrier;
18
19 2
    public function __construct(Carrier $carrier)
20
    {
21 2
        $this->carrier = $carrier;
22 2
    }
23
24
    /**
25
     * Sets the option array for the small and medium
26
     * parcel option in admin section of the extension
27
     *
28
     * @return array
29
     */
30 2
    public function toOptionArray()
31
    {
32 2
        $methods = $this->carrier->getMethods();
33
34 2
        $options = [];
35 2
        foreach ($methods as $value => $label) {
36 2
            $options[] = ['value' => $value, 'label' => $label];
37 2
        }
38
39 2
        return $options;
40
    }
41
42
    /**
43
     * Get options in "key-value" format
44
     *
45
     * @return array
46
     */
47
    public function toArray()
48
    {
49 1
        return array_map(function ($array) {
50 1
            return [$array['value'] => $array['label']];
51 1
        }, $this->toOptionArray());
52
    }
53
}
54