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

StringToSkill::reverseTransform()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 0
cts 4
cp 0
rs 10
cc 3
nc 2
nop 1
crap 12
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