SerializeEncoder   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 23
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 5 3
A encode() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Frostaly\VarExporter\Encoders;
6
7
use Frostaly\VarExporter\Contracts\EncoderInterface;
8
use Frostaly\VarExporter\Encoder;
9
use Frostaly\VarExporter\Instantiator;
10
11
class SerializeEncoder implements EncoderInterface
12
{
13
    /**
14
     * {@inheritDoc}
15
     */
16
    public function supports(mixed $value): bool
17
    {
18
        return is_object($value)
19
            && method_exists($value, '__serialize')
20
            && method_exists($value, '__unserialize');
21
    }
22
23
    /**
24
     * {@inheritDoc}
25
     *
26
     * @param object $object
27
     */
28
    public function encode(Encoder $encoder, mixed $object): array
29
    {
30
        return [
31
            Instantiator::class . '::unserialize(' . $object::class . '::class, ',
32
            ...$encoder->encode($object->__serialize()),
33
            ')',
34
        ];
35
    }
36
}
37