ObjectEncoder::encode()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 2
c 2
b 1
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 1
nc 1
nop 4
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Composer\Config\Util;
6
7
use Closure;
8
use Riimu\Kit\PHPEncoder\Encoder\Encoder;
9
10
class ObjectEncoder implements Encoder
11
{
12 24
    public function getDefaultOptions(): array
13
    {
14 24
        return [];
15
    }
16
17 24
    public function supports($value): bool
18
    {
19 24
        return is_object($value) && !$value instanceof Closure;
20
    }
21
22 2
    public function encode($value, $depth, array $options, callable $encode)
23
    {
24 2
        $serializedValue = \Opis\Closure\serialize($value);
25
26 2
        return '\Opis\Closure\unserialize(' . Helper::exportVar($serializedValue) . ')';
27
    }
28
}
29