MutatorReference   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 46
wmc 6
lcom 2
cbo 0
ccs 15
cts 15
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 3
A getValue() 0 7 1
A setValue() 0 9 1
A classify() 0 4 1
1
<?php
2
3
namespace Cascade\Mapper\Field\Reference;
4
5
class MutatorReference implements ReferenceInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    private $getter;
11
12
    /**
13
     * @var string
14
     */
15
    private $setter;
16
17
    /**
18
     * @param string $field
19
     * @param null|string $getter
20
     * @param null|string $setter
21
     */
22 10
    public function __construct($field, $getter = null, $setter = null)
23
    {
24 10
        $this->getter = $getter ?: 'get' . $this->classify($field);
25 10
        $this->setter = $setter ?: 'set' . $this->classify($field);
26 10
    }
27
28 3
    public function getValue($instance)
29
    {
30 3
        $getter = $this->getter;
31 3
        $className = get_class($instance);
32
33 3
        return (new \ReflectionMethod($className, $getter))->invoke($instance);
34
    }
35
36 3
    public function setValue($instance, $value)
37
    {
38 3
        $setter = $this->setter;
39 3
        $className = get_class($instance);
40
41 3
        (new \ReflectionMethod($className, $setter))->invoke($instance, $value);
42
43 3
        return $instance;
44
    }
45
46 10
    private function classify($word)
47
    {
48 10
        return str_replace(' ', '', ucwords(strtr($word, '_-', '  ')));
49
    }
50
}
51