HasCustomFields   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 8
c 2
b 1
f 0
dl 0
loc 27
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addCustomField() 0 11 3
A getCustomFields() 0 3 1
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