Passed
Pull Request — master (#4)
by
unknown
01:39
created

TimestampedMapper   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 24
ccs 0
cts 15
cp 0
c 1
b 0
f 0
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A queueCreate() 0 11 1
A queueUpdate() 0 9 1
1
<?php
2
3
namespace Yiisoft\Yii\Cycle\Mapper;
4
5
use Cycle\Annotated\Annotation\Column;
6
use Cycle\Annotated\Annotation\Table;
7
use Cycle\ORM\Command\ContextCarrierInterface;
8
use Cycle\ORM\Command\Database\Update;
9
use Cycle\ORM\Heap\Node;
10
use Cycle\ORM\Heap\State;
11
use Cycle\ORM\Mapper\Mapper;
12
13
/**
14
 * @Table(
15
 *      columns={"created_at": @Column(type="datetime"), "updated_at": @Column(type="datetime")}
16
 * )
17
 */
18
class TimestampedMapper extends Mapper
19
{
20
    public function queueCreate($entity, Node $node, State $state): ContextCarrierInterface
21
    {
22
        $cmd = parent::queueCreate($entity, $node, $state);
23
24
        $state->register('created_at', new \DateTimeImmutable(), true);
25
        $cmd->register('created_at', new \DateTimeImmutable(), true);
26
27
        $state->register('updated_at', new \DateTimeImmutable(), true);
28
        $cmd->register('updated_at', new \DateTimeImmutable(), true);
29
30
        return $cmd;
31
    }
32
33
    public function queueUpdate($entity, Node $node, State $state): ContextCarrierInterface
34
    {
35
        /** @var Update $cmd */
36
        $cmd = parent::queueUpdate($entity, $node, $state);
37
38
        $state->register('updated_at', new \DateTimeImmutable(), true);
39
        $cmd->registerAppendix('updated_at', new \DateTimeImmutable());
40
41
        return $cmd;
42
    }
43
}
44