Passed
Pull Request — master (#80)
by Dmitriy
11:08
created

ObjectEncoder::supports()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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