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

Compact   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 5
dl 0
loc 23
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A jsonSerialize() 0 4 2
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