OptionsSeatProperty   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 24
c 1
b 0
f 0
dl 0
loc 71
rs 10
wmc 9

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setOptionsSeat() 0 15 4
A getWeight() 0 3 2
A setWeight() 0 5 1
A getOptionsSeat() 0 14 2
1
<?php
2
3
namespace Daaner\NovaPoshta\Traits;
4
5
use Exception;
6
7
trait OptionsSeatProperty
8
{
9
    protected $OptionsSeat;
10
    protected $Weight;
11
12
    /**
13
     * Параметр груза для каждого места отправления.
14
     * Перебираем значение массива и указываем нужные объемы.
15
     * Если не указывать значение из конфига в 1 кг.
16
     *
17
     * @param  string|array  $OptionsSeat  Указание объемного веса массивом или индексом из массива в конфиге
18
     * @return $this
19
     */
20
    public function setOptionsSeat($OptionsSeat): self
21
    {
22
        $data = config('novaposhta.options_seat');
23
        if (is_array($OptionsSeat) === false) {
24
            $OptionsSeat = explode(',', /** @scrutinizer ignore-type */ $OptionsSeat);
25
        }
26
        foreach ($OptionsSeat as $value) {
27
            try {
28
                $this->OptionsSeat[] = $data[$value];
29
            } catch (Exception $e) {
30
                $this->OptionsSeat[] = $data[1];
31
            }
32
        }
33
34
        return $this;
35
    }
36
37
    /**
38
     * @return void
39
     */
40
    public function getOptionsSeat(): void
41
    {
42
        if (! $this->OptionsSeat) {
43
            $defaultSeat = [
44
                'volumetricVolume' => '1',
45
                'volumetricWidth' => '24',
46
                'volumetricLength' => '17',
47
                'volumetricHeight' => '10',
48
                'weight' => '1',
49
            ];
50
51
            $this->OptionsSeat = $defaultSeat;
52
        }
53
        $this->methodProperties['OptionsSeat'] = $this->OptionsSeat;
54
    }
55
56
    /**
57
     * Устанавливаем вес груза. По умолчанию значение из конфига.
58
     * Не обязательно, если выставляем OptionsSeat, но это не точно.
59
     *
60
     * @param  string  $weight  Вес груза
61
     * @return $this
62
     */
63
    public function setWeight(string $weight): self
64
    {
65
        $this->Weight = $weight;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Установка веса.
72
     *
73
     * @return void
74
     */
75
    public function getWeight(): void
76
    {
77
        $this->methodProperties['Weight'] = $this->Weight ?: config('novaposhta.weight');
78
    }
79
}
80