Test Failed
Branch master (bee4a6)
by stéphane
14:37
created

Compact   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 6
dl 0
loc 25
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A jsonSerialize() 0 4 2
1
<?php
2
3
namespace Dallgoot\Yaml\Types;
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
    public function __construct($candidate = null)
20
    {
21
        $candidate = $candidate ?? [];
22
        //ArrayIterator options --> Array indices can be accessed as properties in read/write.
23
        parent::__construct(
24
        /** @scrutinizer ignore-type */
25
        $candidate, \ArrayIterator::STD_PROP_LIST | \ArrayIterator::ARRAY_AS_PROPS);
26
    }
27
28
    /**
29
     * Provides the correct ouput for Json Serialization
30
     *
31
     * @return array
32
     */
33
    public function jsonSerialize(): array
34
    {
35
        $prop = get_object_vars($this);
36
        return count($prop) > 0 ? $prop : iterator_to_array($this);
37
    }
38
}
39