Passed
Push — master ( cbde3b...f22511 )
by Abishek R
02:33
created

HasCustomFields::getCustomFields()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Greenlyst\BaseCommerce\Traits;
5
6
7
use Greenlyst\BaseCommerce\LogicException;
8
9
trait HasCustomFields
10
{
11
    private $customFields = [];
12
13
    protected abstract function getCustomFieldPrefix(): string;
14
15
    /**
16
     * @param $value
17
     *
18
     * @throws LogicException
19
     */
20
    public function addCustomField($value)
21
    {
22
        if ($this->getCustomFieldPrefix() === '') {
23
            throw LogicException::noCustomFieldPrefixDefined();
24
        }
25
26
        if (count($this->customFields) == 10) {
27
            throw LogicException::only10CustomFieldsAreAllowed();
28
        }
29
30
        $this->customFields[$this->getCustomFieldPrefix() . '_custom_field' . (count($this->customFields) + 1)] = $value;
31
    }
32
33
    public function getCustomFields()
34
    {
35
        return $this->customFields;
36
    }
37
}