RoundingRule   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
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 52
ccs 16
cts 16
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 14 2
1
<?php
2
3
namespace Meanbee\MagentoRoyalmail\Model\Config\Source;
4
5
use \Magento\Framework\Option\ArrayInterface;
6
use Meanbee\MagentoRoyalmail\Model\Rounder;
7
8
/**
9
 * Class RoundingRule Backend system config array field renderer
10
 */
11
class RoundingRule implements ArrayInterface
12
{
13
    const NONE = 'none';
14
    const POUND = 'pound';
15
    const POUND_UP = 'pound-up';
16
    const POUND_DOWN = 'pound-down';
17
    const FIFTY = 'fifty';
18
    const FIFTY_UP = 'fifty_up';
19
    const FIFTY_DOWN = 'fifty_down';
20
21
    /**
22
     * @var $rounder Rounder
23
     */
24
    protected $rounder;
25
26 2
    public function __construct(Rounder $rounder)
27
    {
28 2
        $this->rounder = $rounder;
29 2
    }
30
31
    /**
32
     * Get list of rounding rule options
33
     *
34
     * @return array
35
     */
36 2
    public function toOptionArray()
37
    {
38 2
        $options = [];
39
40 2
        $rules = $this->rounder->getRoundingRules();
41 2
        foreach ($rules as $rule => $name) {
42 2
            $options[] = [
43 2
                'value' => $rule,
44 2
                'label' => __($name)
45 2
            ];
46 2
        }
47
48 2
        return $options;
49
    }
50
51
    /**
52
     * Get options in "key-value" format
53
     *
54
     * @return array
55
     */
56
    public function toArray()
57
    {
58 1
        return array_map(function ($array) {
59 1
            return [$array['value'] => $array['label']];
60 1
        }, $this->toOptionArray());
61
    }
62
}
63