Completed
Push — master ( a12db9...82664b )
by Julito
86:55 queued 55:35
created

ArrayToIdentifierTransformer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 4
lcom 0
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 10 2
A reverseTransform() 0 10 2
1
<?php
2
/* For licensing terms, see /license.txt */
3
4
namespace Chamilo\SettingsBundle\Transformer;
5
6
use Sylius\Bundle\SettingsBundle\Transformer\ParameterTransformerInterface;
7
8
/**
9
 * Object to identifier transformer.
10
 *
11
 * @author Julio Montoya
12
 */
13
class ArrayToIdentifierTransformer implements ParameterTransformerInterface
14
{
15
    /**
16
     * {@inheritdoc}
17
     */
18
    public function transform($value)
19
    {
20
        if (!is_array($value)) {
21
            return '';
22
        }
23
24
        $value = implode(',', $value);
25
26
        return $value;
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function reverseTransform($value)
33
    {
34
        if (empty($value)) {
35
            return [];
36
        }
37
38
        $value = explode(',', $value);
39
40
        return $value;
41
    }
42
}
43