ItemService::getCommand()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 13
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 15
ccs 0
cts 15
cp 0
crap 2
rs 9.8333
1
<?php
2
namespace App\Service;
3
4
use App\Entity\Item;
5
use App\DTO\ItemDTO;
6
use App\Command\CommandInterface;
7
use App\Command\CreateItemCommand;
8
use App\Command\UpdateItemCommand;
9
use Ramsey\Uuid\Uuid;
10
use App\Traits\CommandInstanceTrait;
11
12
class ItemService
13
{
14
    use CommandInstanceTrait;
15
16
    /**
17
     * @param Item $item
18
     * @return ItemDTO
19
     */
20
    public function fillItemDTO(Item $item): ItemDTO
21
    {
22
        return new ItemDTO(
23
            $item->getId()->toString(),
24
            $item->getName(),
25
            $item->getCategory()->getId()->toString(),
26
            $item->getYear(),
27
            $item->getFormat(),
28
            $item->getAuthor(),
29
            $item->getPublisher(),
30
            $item->getDescription(),
31
            $item->getStore(),
32
            $item->getUrl(),
33
            $item->getCollections()->toArray()
34
        );
35
    }
36
37
    /**
38
     * @param ItemDTO $itemDTO
39
     * @return CreateItemCommand|UpdateItemCommand
40
     */
41
    public function getCommand(ItemDTO $itemDTO):  CommandInterface
42
    {
43
        $command = $this->getCommandInstance($itemDTO->getId(), 'Item');
44
        return $command->newInstanceArgs([
45
            $itemDTO->getId() ?? Uuid::uuid4(),
46
            $itemDTO->getName(),
47
            $itemDTO->getCategoryId(),
48
            $itemDTO->getYear(),
49
            $itemDTO->getFormat(),
50
            $itemDTO->getAuthor(),
51
            $itemDTO->getPublisher(),
52
            $itemDTO->getDescription(),
53
            $itemDTO->getStore(),
54
            $itemDTO->getUrl(),
55
            $itemDTO->getCollections()
56
        ]);
57
    }
58
}