Passed
Push — master ( 26b8fa...536a9f )
by Marc
02:20
created

FbpDefinition::toYaml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * This file is part of the phpflo\phpflo-fbp package.
4
 *
5
 * (c) Marc Aschmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace PhpFlo\Fbp;
12
13
use PhpFlo\Common\DefinitionInterface;
14
use PhpFlo\Common\FbpDefinitionsInterface;
15
16
/**
17
 * Class FbpDefinition
18
 *
19
 * @package PhpFlo\Fbp
20
 * @author Marc Aschmann <[email protected]>
21
 */
22
class FbpDefinition implements DefinitionInterface, FbpDefinitionsInterface
23
{
24
    /**
25
     * @var array
26
     */
27
    private $schema;
28
29
    /**
30
     * FbpDefinition constructor.
31
     *
32
     * @param array $definition
33
     */
34 8
    public function __construct(array $definition = [])
35
    {
36 8
        $this->schema = [
37 8
            self::PROPERTIES_LABEL => [
38 8
                'name' => '',
39 8
            ],
40 8
            self::INITIALIZERS_LABEL => [],
41 8
            self::PROCESSES_LABEL => [],
42 8
            self::CONNECTIONS_LABEL => [],
43
        ];
44
45 8
        $this->definition($definition);
46 8
    }
47
48
    /**
49
     * @param array $definition
50
     * @return $this
51
     */
52 8
    public function definition(array $definition)
53
    {
54 8
        $this->schema = array_replace_recursive(
55 8
            $this->schema,
56
            $definition
57 8
        );
58
59 8
        return $this;
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function properties()
66
    {
67
        return $this->schema[self::PROPERTIES_LABEL];
68
    }
69
70
    /**
71
     * @return array
72
     */
73
    public function initializers()
74
    {
75
        return $this->schema[self::INITIALIZERS_LABEL];
76
    }
77
78
    /**
79
     * @return array
80
     */
81
    public function processes()
82
    {
83
        return $this->schema[self::PROCESSES_LABEL];
84
    }
85
86
    /**
87
     * @return array
88
     */
89
    public function connections()
90
    {
91
        return $this->schema[self::CONNECTIONS_LABEL];
92
    }
93
94
    /**
95
     * @return string
96
     */
97
    public function name()
98
    {
99
        return $this->schema[self::PROPERTIES_LABEL]['name'];
100
    }
101
102
    /**
103
     * @return array
104
     */
105 8
    public function toArray()
106
    {
107 8
        return $this->schema;
108
    }
109
110
    /**
111
     * @return string
112
     */
113 1
    public function toJson()
114
    {
115 1
        return FbpDumper::toJson($this->schema);
116
    }
117
118
    /**
119
     * @return string
120
     */
121 1
    public function toYaml()
122
    {
123 1
        return FbpDumper::toYaml($this->schema);
124
    }
125
126
    /**
127
     * @return string
128
     */
129
    public function toFbp()
130
    {
131
        return FbpDumper::toFbp($this->schema);
132
    }
133
}
134