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

FbpDefinition   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 54.84%

Importance

Changes 0
Metric Value
dl 0
loc 104
c 0
b 0
f 0
wmc 10
lcom 1
cbo 1
ccs 17
cts 31
cp 0.5484
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A definition() 0 9 1
A properties() 0 4 1
A initializers() 0 4 1
A processes() 0 4 1
A connections() 0 4 1
A toArray() 0 4 1
A toJson() 0 4 1
A toYaml() 0 4 1
A toFbp() 0 4 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