Completed
Push — master ( 65f7a2...1565b3 )
by Konstantin
07:54 queued 01:51
created

FieldsMergeable::mergeStringToField()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 7

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.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 4
nop 2
crap 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: root
5
 * Date: 15.02.18
6
 * Time: 16:11
7
 */
8
9
namespace linkprofit\AmoCRM\traits;
10
11
trait FieldsMergeable
12
{
13
    /**
14
     * @param $fieldName
15
     * @param $string
16
     */
17 8
    public function mergeStringToField($string, $fieldName)
18
    {
19 8
        $string = (string) $string;
20 8
        $fieldIsSet = mb_strlen($this->$fieldName) > 0 && !is_array($this->$fieldName);
21
22 8
        if (!$fieldIsSet) {
23 8
            $this->$fieldName = $string;
24 8
        } else {
25 6
            $this->$fieldName .= ',' . $string;
26
        }
27
    }
28
}