Passed
Push — master ( 9a3526...e85357 )
by Alexander
03:52
created

ObjectEncoder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 4
eloc 5
c 2
b 1
f 0
dl 0
loc 17
ccs 7
cts 7
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultOptions() 0 3 1
A encode() 0 5 1
A supports() 0 3 2
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 11
    public function getDefaultOptions(): array
11
    {
12 11
        return [];
13
    }
14
15 11
    public function supports($value): bool
16
    {
17 11
        return is_object($value) && !$value instanceof Closure;
18
    }
19
20 1
    public function encode($value, $depth, array $options, callable $encode)
21
    {
22 1
        $serializedValue = \Opis\Closure\serialize($value);
23
24 1
        return '\Opis\Closure\unserialize(' . Helper::exportVar($serializedValue) . ')';
25
    }
26
}
27