FbpDefinition   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 112
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 112
ccs 33
cts 33
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 1
A definition() 0 9 1
A toArray() 0 4 1
A toJson() 0 4 1
A toYaml() 0 4 1
A properties() 0 4 1
A initializers() 0 4 1
A processes() 0 4 1
A connections() 0 4 1
A name() 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
declare(strict_types=1);
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 10
    public function __construct(array $definition = [])
35
    {
36 10
        $this->schema = [
37 10
            self::PROPERTIES_LABEL => [
38 10
                'name' => '',
39 10
            ],
40 10
            self::INITIALIZERS_LABEL => [],
41 10
            self::PROCESSES_LABEL => [],
42 10
            self::CONNECTIONS_LABEL => [],
43
        ];
44
45 10
        $this->definition($definition);
46 10
    }
47
48
    /**
49
     * @param array $definition
50
     * @return DefinitionInterface
51
     */
52 10
    public function definition(array $definition) : DefinitionInterface
53
    {
54 10
        $this->schema = array_replace_recursive(
55 10
            $this->schema,
56
            $definition
57 10
        );
58
59 10
        return $this;
60
    }
61
62
    /**
63
     * @return array
64
     */
65 1
    public function properties() : array
66
    {
67 1
        return $this->schema[self::PROPERTIES_LABEL];
68
    }
69
70
    /**
71
     * @return array
72
     */
73 1
    public function initializers() : array
74
    {
75 1
        return $this->schema[self::INITIALIZERS_LABEL];
76
    }
77
78
    /**
79
     * @return array
80
     */
81 1
    public function processes() : array
82
    {
83 1
        return $this->schema[self::PROCESSES_LABEL];
84
    }
85
86
    /**
87
     * @return array
88
     */
89 1
    public function connections() : array
90
    {
91 1
        return $this->schema[self::CONNECTIONS_LABEL];
92
    }
93
94
    /**
95
     * @return string
96
     */
97 1
    public function name() : string
98
    {
99 1
        return $this->schema[self::PROPERTIES_LABEL]['name'];
100
    }
101
102
    /**
103
     * @return array
104
     */
105 8
    public function toArray() : array
106
    {
107 8
        return $this->schema;
108
    }
109
110
    /**
111
     * @return string
112
     */
113 1
    public function toJson() : string
114
    {
115 1
        return FbpDumper::toJson($this->schema);
116
    }
117
118
    /**
119
     * @return string
120
     */
121 1
    public function toYaml() : string
122
    {
123 1
        return FbpDumper::toYaml($this->schema);
124
    }
125
126
    /**
127
     * @return string
128
     */
129 1
    public function toFbp() : string
130
    {
131 1
        return FbpDumper::toFbp($this->schema);
132
    }
133
}
134