Test Failed
Push — b0.27.0 ( 7070d1...8acaa0 )
by Sebastian
03:51
created

UuidMapperAbstract   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 2
Metric Value
wmc 4
eloc 7
c 2
b 1
f 2
dl 0
loc 79
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A delete() 0 3 1
A create() 0 3 1
A save() 0 8 2
1
<?php
2
3
/**
4
 * Linna Framework.
5
 *
6
 * @author Sebastian Rapetti <[email protected]>
7
 * @copyright (c) 2018, Sebastian Rapetti
8
 * @license http://opensource.org/licenses/MIT MIT License
9
 */
10
declare(strict_types=1);
11
12
namespace Linna\DataMapper;
13
14
use InvalidArgumentException;
15
16
/**
17
 * Abstract Class for ObjectMapper, uuid version.
18
 */
19
abstract class UuidMapperAbstract
20
{
21
    /**
22
     * Create a new instance of the DomainObject that this
23
     * mapper is responsible for.
24
     *
25
     * @return UuidDomainObjectInterface
26
     */
27
    public function create(): UuidDomainObjectInterface
28
    {
29
        return $this->concreteCreate();
30
    }
31
32
    /**
33
     * Store the DomainObject in persistent storage. Either insert
34
     * or update the store as required.
35
     *
36
     * @param UuidDomainObjectInterface $domainObject
37
     *
38
     * @return void
39
     */
40
    public function save(UuidDomainObjectInterface &$domainObject): void
41
    {
42
        if ($domainObject->getId() === '') {
43
            $this->concreteInsert($domainObject);
44
            return;
45
        }
46
47
        $this->concreteUpdate($domainObject);
48
    }
49
50
    /**
51
     * Delete the DomainObject from persistent storage.
52
     *
53
     * @param UuidDomainObjectInterface $domainObject
54
     *
55
     * @return void
56
     */
57
    public function delete(UuidDomainObjectInterface &$domainObject): void
58
    {
59
        $this->concreteDelete($domainObject);
60
    }
61
62
    /**
63
     * Create a new instance of a DomainObject.
64
     *
65
     * @return UuidDomainObjectInterface
66
     */
67
    abstract protected function concreteCreate(): UuidDomainObjectInterface;
68
69
    /**
70
     * Insert the DomainObject to persistent storage.
71
     *
72
     * @param UuidDomainObjectInterface $domainObject
73
     */
74
    abstract protected function concreteInsert(UuidDomainObjectInterface &$domainObject);
75
76
    /**
77
     * Update the DomainObject in persistent storage.
78
     *
79
     * @param UuidDomainObjectInterface $domainObject
80
     */
81
    abstract protected function concreteUpdate(UuidDomainObjectInterface $domainObject);
82
83
    /**
84
     * Delete the DomainObject from peristent Storage.
85
     *
86
     * @param UuidDomainObjectInterface $domainObject
87
     */
88
    abstract protected function concreteDelete(UuidDomainObjectInterface &$domainObject);
89
90
    /**
91
     * Check for valid domain Object.
92
     *
93
     * @param UuidDomainObjectInterface $domainObject
94
     *
95
     * @throws InvalidArgumentException if the domain object isn't of the type required by mapper
96
     */
97
    abstract protected function checkDomainObjectType(UuidDomainObjectInterface $domainObject);
98
}
99