Passed
Push — release/1.0.0 ( 02b4c6...f79e53 )
by Yo
01:58 queued 34s
created

ArrayAppendHelperTrait::appendIf()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 4
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Yoanm\JsonRpcHttpServerOpenAPIDoc\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 = [])
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 = [])
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 = [])
42
    {
43 52
        if (true === $doAppend) {
44 35
            $doc[$key] = $value;
45
        }
46
47 52
        return $doc;
48
    }
49
}
50