PostMapper::queueUpdate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 3
dl 0
loc 13
ccs 0
cts 7
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Blog\Post;
6
7
use App\Blog\Entity\Post;
8
use Cycle\ORM\Command\CommandInterface;
9
use Cycle\ORM\Command\ContextCarrierInterface;
10
use Cycle\ORM\Command\Database\Update;
11
use Cycle\ORM\Context\ConsumerInterface;
12
use Cycle\ORM\Heap\Node;
13
use Cycle\ORM\Heap\State;
14
use Cycle\ORM\Mapper\Mapper;
15
16
final class PostMapper extends Mapper
17
{
18
    /**
19
     * @param Post $entity
20
     */
21
    public function queueUpdate($entity, Node $node, State $state): ContextCarrierInterface
22
    {
23
        /** @var Update $command */
24
        $command = parent::queueUpdate($entity, $node, $state);
25
26
        $now = new \DateTimeImmutable();
27
28
        $state->register('updated_at', $now, true);
29
        $command->registerAppendix('updated_at', $now);
30
31
        $this->touch($entity, $node, $state, $command);
32
33
        return $command;
34
    }
35
36
    /**
37
     * @param Post $entity
38
     */
39
    public function queueDelete($entity, Node $node, State $state): CommandInterface
40
    {
41
        // identify entity as being "deleted"
42
        $state->setStatus(Node::SCHEDULED_DELETE);
43
        $state->decClaim();
44
45
        $command = new Update(
46
            $this->source->getDatabase(),
47
            $this->source->getTable(),
48
            [
49
                'deleted_at' => new \DateTimeImmutable(),
50
                'public' => false,
51
            ]
52
        );
53
54
        // forward primaryKey value from entity state
55
        // this sequence is only required if the entity is created and deleted
56
        // within one transaction
57
        $command->waitScope($this->primaryColumn);
58
        $state->forward(
59
            $this->primaryKey,
60
            $command,
61
            $this->primaryColumn,
62
            true,
63
            ConsumerInterface::SCOPE
64
        );
65
66
        return $command;
67
    }
68
69
    private function touch(Post $entity, Node $node, State $state, ContextCarrierInterface $command)
0 ignored issues
show
Unused Code introduced by
The parameter $node is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

69
    private function touch(Post $entity, /** @scrutinizer ignore-unused */ Node $node, State $state, ContextCarrierInterface $command)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
70
    {
71
        $now = new \DateTimeImmutable();
72
73
        if ($entity->isPublic() && $entity->getPublishedAt() === null) {
74
            $state->register('published_at', $now, true);
75
            $command->register('published_at', $now, true);
76
        }
77
    }
78
}
79