Passed
Push — master ( 008588...173da8 )
by Marc
02:45
created

FbpDefinition::definition()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 9
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 5
nc 1
nop 1
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 5
    public function __construct(array $definition = [])
35
    {
36 5
        $this->schema = [
37 5
            self::PROPERTIES_LABEL => [
38 5
                'name' => '',
39 5
            ],
40 5
            self::INITIALIZERS_LABEL => [],
41 5
            self::PROCESSES_LABEL => [],
42 5
            self::CONNECTIONS_LABEL => [],
43
        ];
44
45 5
        $this->definition($definition);
46 5
    }
47
48
    /**
49
     * @param array $definition
50
     * @return $this
51
     */
52 5
    public function definition(array $definition)
53
    {
54 5
        $this->schema = array_replace_recursive(
55 5
            $this->schema,
56
            $definition
57 5
        );
58
59 5
        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 array
96
     */
97 5
    public function toArray()
98
    {
99 5
        return $this->schema;
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function toJson()
106
    {
107
        return FbpDumper::toJson($this->schema);
108
    }
109
110
    /**
111
     * @return string
112
     */
113
    public function toYaml()
114
    {
115
        return FbpDumper::toYaml($this->schema);
116
    }
117
118
    /**
119
     * @return string
120
     */
121
    public function toFbp()
122
    {
123
        return FbpDumper::toFbp($this->schema);
124
    }
125
}
126