SerializeEncoder::encode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 10
c 0
b 0
f 0
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