Serialize   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A unpack() 0 13 3
A pack() 0 3 1
1
<?php
2
3
namespace kalanis\UploadPerPartes\Target\Local\DrivingFile\DataEncoders;
4
5
6
use kalanis\UploadPerPartes\Uploader\Data;
7
use kalanis\UploadPerPartes\UploadException;
8
9
10
/**
11
 * Class Serialize
12
 * @package kalanis\UploadPerPartes\ServerData\DataModifiers
13
 * Driver file - format into serialized string
14
 */
15
class Serialize extends AEncoder
16
{
17 5
    public function unpack(string $content): Data
18
    {
19 5
        $data = @unserialize($content, [
20 5
            'allowed_classes' => [Data::class],
21
            'max_depth' => 2,
22
        ]);
23 5
        if (false === $data) {
24 1
            throw new UploadException($this->getUppLang()->uppIncomingDataCannotDecode());
25
        }
26 4
        if (!$data instanceof Data) {
27 1
            throw new UploadException($this->getUppLang()->uppIncomingDataCannotDecode());
28
        }
29 3
        return $data->clear();
30
    }
31
32 3
    public function pack(Data $data): string
33
    {
34 3
        return strval(serialize($data));
35
    }
36
}
37