Completed
Push — master ( 2cde75...6c52d6 )
by Arne
02:04
created

VaultConfiguration::setTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Storeman;
4
5
use Symfony\Component\Validator\Constraints as Assert;
6
use Symfony\Component\Validator\Mapping\ClassMetadata;
7
use Zend\Stdlib\ArraySerializableInterface;
8
9
class VaultConfiguration implements ArraySerializableInterface
10
{
11
    /**
12
     * An arbitrary user-defined title that helps to identity a vault by some user-specific information.
13
     *
14
     * @var string
15
     */
16
    protected $title;
17
18
    /**
19
     * Identifier for the vault adapter to use.
20
     *
21
     * @var string
22
     */
23
    protected $adapter;
24
25
    /**
26
     * Identifier for the lock adapter to use.
27
     *
28
     * @var string
29
     */
30
    protected $lockAdapter = 'storage';
31
32
    /**
33
     * Identifier for the index merger to be used.
34
     *
35
     * @var string
36
     */
37
    protected $indexMerger = 'standard';
38
39
    /**
40
     * Identifier for the conflict handler to use.
41
     *
42
     * @var string
43
     */
44
    protected $conflictHandler = 'panicking';
45
46
    /**
47
     * Identifier for the operation list builder to use.
48
     *
49
     * @var string
50
     */
51
    protected $operationListBuilder = 'standard';
52
53
    /**
54
     * Map with additional storageAdapter- or lockAdapter-specific settings.
55
     *
56
     * @var array
57
     */
58
    protected $settings = [];
59
60
    public function __construct(string $storageAdapter = 'unknown')
61
    {
62
        $this->setAdapter($storageAdapter);
63
        $this->setTitle($storageAdapter);
64
    }
65
66
    public function getTitle(): string
67
    {
68
        return $this->title;
69
    }
70
71
    public function setTitle(string $title): VaultConfiguration
72
    {
73
        $this->title = $title;
74
75
        return $this;
76
    }
77
78
    public function getAdapter(): string
79
    {
80
        return $this->adapter;
81
    }
82
83
    public function setAdapter(string $adapter): VaultConfiguration
84
    {
85
        $this->adapter = $adapter;
86
87
        return $this;
88
    }
89
90
    public function getLockAdapter(): string
91
    {
92
        return $this->lockAdapter;
93
    }
94
95
    public function setLockAdapter(string $lockAdapter): VaultConfiguration
96
    {
97
        $this->lockAdapter = $lockAdapter;
98
99
        return $this;
100
    }
101
102
    public function getIndexMerger(): string
103
    {
104
        return $this->indexMerger;
105
    }
106
107
    public function setIndexMerger(string $indexMerger): VaultConfiguration
108
    {
109
        $this->indexMerger = $indexMerger;
110
111
        return $this;
112
    }
113
114
    public function getConflictHandler(): string
115
    {
116
        return $this->conflictHandler;
117
    }
118
119
    public function setConflictHandler(string $conflictHandler): VaultConfiguration
120
    {
121
        $this->conflictHandler = $conflictHandler;
122
123
        return $this;
124
    }
125
126
    public function getOperationListBuilder(): string
127
    {
128
        return $this->operationListBuilder;
129
    }
130
131
    public function setOperationListBuilder(string $operationListBuilder): VaultConfiguration
132
    {
133
        $this->operationListBuilder = $operationListBuilder;
134
135
        return $this;
136
    }
137
138
    public function getSettings(): array
139
    {
140
        return $this->settings;
141
    }
142
143
    public function getSetting(string $name)
144
    {
145
        return isset($this->settings[$name]) ? $this->settings[$name] : null;
146
    }
147
148
    public function setSettings(array $settings): VaultConfiguration
149
    {
150
        $this->settings = $settings;
151
152
        return $this;
153
    }
154
155
    public function setSetting(string $name, $value): VaultConfiguration
156
    {
157
        $this->settings[$name] = $value;
158
159
        return $this;
160
    }
161
162
    /**
163
     * {@inheritdoc}
164
     */
165
    public function exchangeArray(array $array)
166
    {
167
        if ($diff = array_diff(array_keys($array), array_keys($this->getArrayCopy())))
168
        {
169
            throw new \InvalidArgumentException("Invalid index(es): " . implode(',', $diff));
170
        }
171
172
        foreach ($array as $key => $value)
173
        {
174
            // using setter to prevent skipping validation
175
            call_user_func([$this, 'set' . ucfirst($key)], $value);
176
        }
177
    }
178
179
    /**
180
     * {@inheritdoc}
181
     */
182
    public function getArrayCopy()
183
    {
184
        return get_object_vars($this);
185
    }
186
187
    public static function loadValidatorMetadata(ClassMetadata $metadata)
188
    {
189
        $metadata->addPropertyConstraint('title', new Assert\NotBlank());
190
        //$metadata->addPropertyConstraint('adapter', new Assert\Choice(['choices' => StorageAdapterFactory::getProvidedServiceNames()]));
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
191
        //$metadata->addPropertyConstraint('lockAdapter', new Assert\Choice(['choices' => LockAdapterFactory::getProvidedServiceNames()]));
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
192
        //$metadata->addPropertyConstraint('indexMerger', new Assert\Choice(['choices' => IndexMergerFactory::getProvidedServiceNames()]));
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
193
        //$metadata->addPropertyConstraint('conflictHandler', new Assert\Choice(['choices' => ConflictHandlerFactory::getProvidedServiceNames()]));
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
194
        //$metadata->addPropertyConstraint('operationListBuilder', new Assert\Choice(['choices' =>< OperationListBuilderFactory::getProvidedServiceNames()]));
0 ignored issues
show
Unused Code Comprehensibility introduced by
66% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
195
    }
196
}
197