Passed
Pull Request — master (#26)
by Yo
01:25
created

ArrayAppendHelperTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 41
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A appendIfValueNotNull() 0 3 1
A appendIfValueHaveSiblings() 0 3 1
A appendIf() 0 7 2
1
<?php
2
namespace Yoanm\JsonRpcHttpServerSwaggerDoc\App\Helper;
3
4
/**
5
 * Class ArrayAppendHelperTrait
6
 */
7
trait ArrayAppendHelperTrait
8
{
9
    /**
10
     * @param string $key
11
     * @param mixed  $value
12
     * @param array  $doc
13
     *
14
     * @return array
15
     */
16 44
    protected function appendIfValueHaveSiblings(string $key, array $value, array $doc = []) : array
17
    {
18 44
        return $this->appendIf((count($value) > 0), $key, $value, $doc);
19
    }
20
21
    /**
22
     * @param string $key
23
     * @param mixed  $value
24
     * @param array  $doc
25
     *
26
     * @return array
27
     */
28 44
    protected function appendIfValueNotNull(string $key, $value, array $doc = []) : array
29
    {
30 44
        return $this->appendIf((null !== $value), $key, $value, $doc);
31
    }
32
33
    /**
34
     * @param bool   $doAppend
35
     * @param string $key
36
     * @param mixed  $value
37
     * @param array  $doc
38
     *
39
     * @return array
40
     */
41 52
    protected function appendIf(bool $doAppend, string $key, $value, array $doc = []) : array
42
    {
43 52
        if (true === $doAppend) {
44 36
            $doc[$key] = $value;
45
        }
46
47 52
        return $doc;
48
    }
49
}
50