Completed
Push — master ( 4a6b89...c84e82 )
by Andrii
17:16 queued 14s
created

ClosureEncoder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 4
dl 0
loc 24
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A supports() 0 3 1
A encode() 0 3 1
A getDefaultOptions() 0 3 1
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\utils;
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