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

PhpSerializer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 22
ccs 8
cts 10
cp 0.8
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A serialize() 0 9 2
A deserialize() 0 9 2
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