Completed
Push — middleware-wip ( 1bcdac...ffd957 )
by Romain
02:46
created

FormMetadataObject   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 1
dl 0
loc 65
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 8 2
A has() 0 4 1
A set() 0 4 1
A remove() 0 6 2
A getData() 0 4 1
A __toString() 0 4 1
1
<?php
2
/*
3
 * 2017 Romain CANON <[email protected]>
4
 *
5
 * This file is part of the TYPO3 FormZ project.
6
 * It is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License, either
8
 * version 3 of the License, or any later version.
9
 *
10
 * For the full copyright and license information, see:
11
 * http://www.gnu.org/licenses/gpl-3.0.html
12
 */
13
14
namespace Romm\Formz\Domain\Model\DataObject;
15
16
use Romm\Formz\Exceptions\EntryNotFoundException;
17
use TYPO3\CMS\Core\Type\TypeInterface;
18
19
/**
20
 * Store and retrieve arbitrary data using the setter/getter functions.
21
 */
22
class FormMetadataObject implements TypeInterface
23
{
24
    /**
25
     * @var array
26
     */
27
    protected $data = [];
28
29
    /**
30
     * @param string $key
31
     * @return mixed
32
     * @throws EntryNotFoundException
33
     */
34
    public function get($key)
35
    {
36
        if (false === $this->has($key)) {
37
            throw EntryNotFoundException::metadataNotFound($key);
38
        }
39
40
        return $this->data[$key];
41
    }
42
43
    /**
44
     * @param string $key
45
     * @return bool
46
     */
47
    public function has($key)
48
    {
49
        return isset($this->data[$key]);
50
    }
51
52
    /**
53
     * @param string $key
54
     * @param mixed  $value
55
     */
56
    public function set($key, $value)
57
    {
58
        $this->data[$key] = $value;
59
    }
60
61
    /**
62
     * @param string $key
63
     */
64
    public function remove($key)
65
    {
66
        if (isset($this->data[$key])) {
67
            unset($this->data[$key]);
68
        }
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function getData()
75
    {
76
        return $this->data;
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function __toString()
83
    {
84
        return serialize($this);
85
    }
86
}
87