Methods   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 43
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A toArray() 0 6 1
A toOptionArray() 0 11 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