Completed
Push — middleware-wip-tmp ( d8f2e1 )
by Romain
02:50
created

FormMetadata   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getHash() 0 4 1
A getIdentifier() 0 4 1
A setIdentifier() 0 4 1
A hasIdentifier() 0 4 1
A getData() 0 4 1
A commit() 0 13 2
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;
15
16
use Romm\Formz\Core\Core;
17
use Romm\Formz\Domain\Model\DataObject\FormMetadataObject;
18
use TYPO3\CMS\Extbase\DomainObject\AbstractEntity;
19
use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager;
20
21
/**
22
 * @todo
23
 */
24
class FormMetadata extends AbstractEntity
25
{
26
    /**
27
     * @var string
28
     */
29
    protected $hash;
30
31
    /**
32
     * @var string
33
     */
34
    protected $className;
35
36
    /**
37
     * @var string
38
     */
39
    protected $identifier;
40
41
    /**
42
     * @var \Romm\Formz\Domain\Model\DataObject\FormMetadataObject
43
     */
44
    protected $data;
45
46
    /**
47
     * @param string             $hash
48
     * @param string             $className
49
     * @param string             $identifier
50
     * @param FormMetadataObject $data
51
     */
52
    public function __construct($hash, $className, $identifier, FormMetadataObject $data)
53
    {
54
        $this->hash = $hash;
55
        $this->className = $className;
56
        $this->identifier = $identifier;
57
        $this->data = $data;
58
    }
59
60
    /**
61
     * @return string
62
     */
63
    public function getHash()
64
    {
65
        return $this->hash;
66
    }
67
68
    /**
69
     * @return string
70
     */
71
    public function getIdentifier()
72
    {
73
        return $this->identifier;
74
    }
75
76
    /**
77
     * @param string $identifier
78
     */
79
    public function setIdentifier($identifier)
80
    {
81
        $this->identifier = $identifier;
82
    }
83
84
    /**
85
     * @return bool
86
     */
87
    public function hasIdentifier()
88
    {
89
        return null !== $this->identifier;
90
    }
91
92
    /**
93
     * @return FormMetadataObject
94
     */
95
    public function getData()
96
    {
97
        return $this->data;
98
    }
99
100
    /**
101
     * @todo
102
     */
103
    public function commit()
104
    {
105
        /** @var PersistenceManager $persistenceManager */
106
        $persistenceManager = Core::instantiate(PersistenceManager::class);
107
108
        if (null === $this->getUid()) {
109
            $persistenceManager->add($this);
110
        } else {
111
            $persistenceManager->update($this);
112
        }
113
114
        $persistenceManager->persistAll();
115
    }
116
}
117