SerializerFacade::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 *  This file is part of the Micro framework package.
7
 *
8
 *  (c) Stanislau Komar <[email protected]>
9
 *
10
 *  For the full copyright and license information, please view the LICENSE
11
 *  file that was distributed with this source code.
12
 */
13
14
namespace Micro\Library\DTO;
15
16
use Micro\Library\DTO\Object\AbstractDto;
17
use Micro\Library\DTO\Serializer\SerializerFactoryInterface;
18
19
class SerializerFacade implements SerializerFacadeInterface
20
{
21
    /**
22
     * @param SerializerFactoryInterface $serializerFactory
23
     */
24 2
    public function __construct(private SerializerFactoryInterface $serializerFactory)
25
    {
26 2
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31
    public function toArray(AbstractDto $abstractDto, bool $serializeEmptyValues = true): array
32
    {
33
        return $this->serializerFactory->create()->toArray($abstractDto, $serializeEmptyValues);
34
    }
35
36 2
    public function toArrayTransfer(AbstractDto $abstractDto): array
37
    {
38 2
        return $this->serializerFactory->create()->toArrayTransfer($abstractDto);
39
    }
40
41
    /**
42
     * {@inheritDoc}
43
     */
44 2
    public function toJsonTransfer(AbstractDto $abstractDto, int $flags = 0): string
45
    {
46 2
        return $this->serializerFactory->create()->toJsonTransfer($abstractDto, $flags);
47
    }
48
49 2
    public function toJson(AbstractDto $abstractDto, bool $serializeEmptyValues = true, int $flags = 0): string
50
    {
51 2
        return $this->serializerFactory->create()->toJson($abstractDto, $serializeEmptyValues, $flags);
52
    }
53
54
    /**
55
     * @param array<string, mixed> $itemData
56
     *
57
     * @throws Exception\UnserializeException
58
     *
59
     * @return AbstractDto
60
     */
61 2
    public function fromArrayTransfer(array $itemData): AbstractDto
62
    {
63 2
        return $this->serializerFactory->create()->fromArrayTransfer($itemData);
64
    }
65
66
    /**
67
     * {@inheritDoc}
68
     */
69 2
    public function fromJsonTransfer(string $jsonDto): AbstractDto
70
    {
71 2
        return $this->serializerFactory->create()->fromJsonTransfer($jsonDto);
72
    }
73
}
74