FieldsMergeable::mergeStringToField()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 8
cts 8
cp 1
rs 9.9
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 3
1
<?php
2
3
namespace linkprofit\AmoCRM\traits;
4
5
/**
6
 * Class FieldsMergeable
7
 * @package linkprofit\AmoCRM\traits
8
 */
9
trait FieldsMergeable
10
{
11
    /**
12
     * @param $fieldName
13
     * @param $string
14
     */
15 8
    public function mergeStringToField($string, $fieldName)
16
    {
17 8
        $string = (string) $string;
18 8
        $fieldIsSet = mb_strlen($this->$fieldName) > 0 && !is_array($this->$fieldName);
19
20 8
        if (!$fieldIsSet) {
21 8
            $this->$fieldName = $string;
22 8
        } else {
23 6
            $this->$fieldName .= ',' . $string;
24
        }
25
    }
26
}