Compact   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 7
dl 0
loc 26
ccs 7
cts 7
cp 1
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
#[\AllowDynamicProperties]
13
class Compact extends \ArrayIterator implements \JsonSerializable
14
{
15
    /**
16
     *  Construct Compact according to argument if present
17
     *
18
     * @param array|object $candidate The candidate to be made into Compact
19
     */
20 2
    public function __construct($candidate = null)
21
    {
22 2
        $candidate = $candidate ?? [];
23
        //ArrayIterator options --> Array indices can be accessed as properties in read/write.
24 2
        parent::__construct(
25
        /** @scrutinizer ignore-type */
26 2
        $candidate, \ArrayIterator::STD_PROP_LIST | \ArrayIterator::ARRAY_AS_PROPS);
27
    }
28
29
    /**
30
     * Provides the correct ouput for Json Serialization
31
     *
32
     * @return array
33
     */
34 1
    public function jsonSerialize(): array
35
    {
36 1
        $prop = get_object_vars($this);
37 1
        return count($prop) > 0 ? $prop : iterator_to_array($this);
38
    }
39
}
40