Passed
Push — master ( fb5a5d...3e18cb )
by Andrii
11:39
created

ClosureEncoder::encode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 4
1
<?php
2
/**
3
 * Composer plugin for config assembling
4
 *
5
 * @link      https://github.com/hiqdev/composer-config-plugin
6
 * @package   composer-config-plugin
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2018, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\composer\config;
12
13
use Closure;
14
use Riimu\Kit\PHPEncoder\Encoder\Encoder;
15
use Opis\Closure\ReflectionClosure;
16
17
/**
18
 * Closure encoder for Riimu Kit-PHPEncoder.
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class ClosureEncoder implements Encoder
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function getDefaultOptions()
27
    {
28
        return [];
29
    }
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public function supports($value)
35
    {
36
        return $value instanceof Closure;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     */
42
    public function encode($value, $depth, array $options, callable $encode)
43
    {
44
        return (new ReflectionClosure($value))->getCode();
45
    }
46
}
47