Completed
Branch v1.x-dev (5c2708)
by Benjamin
04:14
created

StringToSkill   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 9
c 1
b 0
f 0
dl 0
loc 29
ccs 0
cts 11
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A reverseTransform() 0 7 3
A transform() 0 7 3
A __construct() 0 3 1
1
<?php
2
3
namespace Obblm\Core\DataTransformer;
4
5
use Obblm\Core\Contracts\RuleHelperInterface;
6
use Obblm\Core\Contracts\SkillInterface;
7
use Symfony\Component\Form\DataTransformerInterface;
8
9
class StringToSkill implements DataTransformerInterface
10
{
11
    private $helper;
12
13
    public function __construct(RuleHelperInterface $helper)
14
    {
15
        $this->helper = $helper;
16
    }
17
18
    /**
19
     * @param mixed $value
20
     * @return SkillInterface|void
21
     */
22
    public function transform($value)
23
    {
24
        if (!$value && !is_string($value)) {
25
            return;
26
        }
27
28
        return $this->helper->getSkill($value);
29
    }
30
31
    public function reverseTransform($value)
32
    {
33
        if (!$value && !($value instanceof SkillInterface)) {
34
            return;
35
        }
36
37
        return $value->getKey();
38
    }
39
}
40