Passed
Push — master ( f81cc4...5281ab )
by stéphane
04:50
created

Compact::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Dallgoot\Yaml;
4
5
/**
6
 * This a type that encapsulates a mapping or sequence that are declared as compact/hosrt notation
7
 *
8
 * @author  Stéphane Rebai <[email protected]>
9
 * @license Apache 2.0
10
 * @link    https://github.com/dallgoot/yaml
11
 */
12
class Compact extends \ArrayIterator implements \JsonSerializable
13
{
14
    /**
15
     *  Construct Compact according to argument if present
16
     *
17
     * @param array|object $candidate The candidate to be made into Compact
18
     */
19 2
    public function __construct($candidate = null)
20
    {
21 2
        $candidate = $candidate ?? [];
22
        //ArrayIterator options --> Array indices can be accessed as properties in read/write.
23 2
        parent::__construct($candidate, \ArrayIterator::STD_PROP_LIST|\ArrayIterator::ARRAY_AS_PROPS);
0 ignored issues
show
Bug introduced by
It seems like $candidate can also be of type object; however, parameter $array of ArrayIterator::__construct() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        parent::__construct(/** @scrutinizer ignore-type */ $candidate, \ArrayIterator::STD_PROP_LIST|\ArrayIterator::ARRAY_AS_PROPS);
Loading history...
24 2
    }
25
26
    /**
27
     * Provides the correct ouput for Json Serialization
28
     *
29
     * @return array
30
     */
31 1
    public function jsonSerialize():array
32
    {
33 1
        $prop = get_object_vars($this);
34 1
        return count($prop) > 0 ? $prop : iterator_to_array($this);
35
    }
36
}
37