Serialize::unpack()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 3
rs 10
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