Passed
Pull Request — master (#753)
by Maxim
17:58
created

PhpSerializer::deserialize()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Queue;
6
7
use Spiral\Queue\Exception\SerializationException;
8
9
final class PhpSerializer implements SerializerInterface
10
{
11 2
    public function serialize(array $payload): string
12
    {
13 2
        $result = \serialize($payload);
14
15 2
        if ($result === false) {
16
            throw new SerializationException('Failed to serialize data.');
17
        }
18
19 2
        return $result;
20
    }
21
22 2
    public function deserialize(string $payload): array
23
    {
24 2
        $result = \unserialize($payload);
25
26 2
        if ($result === false) {
27
            throw new SerializationException('Failed to unserialize data.');
28
        }
29
30 2
        return $result;
31
    }
32
}
33