HasCustomFields::getCustomFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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