Base::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 9
ccs 5
cts 5
cp 1
rs 9.6666
cc 1
eloc 7
nc 1
nop 3
crap 1
1
<?php
2
3
namespace GFG\Mapper\Data\Type;
4
5
use GFG\Mapper\Data\MapperInterface;
6
use GFG\Mapper\Data\Manager;
7
8
/**
9
 * Base class for Types
10
 */
11
abstract class Base
12
{
13
    /**
14
     * @var Manager
15
     */
16
    protected $manager;
17
18
    /**
19
     * @var MapperInterface
20
     */
21
    protected $mapper;
22
23
    /**
24
     * @var array specific options for this type
25
     */
26
    protected $options;
27
28
    /**
29
     * @var Manager         $manager
30
     * @var MapperInterface $mapper
31
     * @var array           $options
32
     */
33 10
    public function __construct(
34
        Manager $manager,
35
        MapperInterface $mapper,
36
        array $options
37
    ) {
38 10
        $this->manager = $manager;
39 10
        $this->mapper  = $mapper;
40 10
        $this->options = $options;
41 10
    }
42
43
    /**
44
     * @param string $key Key to be retrived from user-defined mapper
45
     */
46 6
    public function get($key)
47
    {
48 6
        return $this->mapper->get($this->options['prefix'] . '_' . $key);
49
    }
50
51
    /**
52
     * @param array $options
53
     * @return $this
54
     */
55 1
    public function setOptions(array $options)
56
    {
57 1
        $this->options = $options;
58 1
        return $this;
59
    }
60
61
    /**
62
     * @param string $option Option key
63
     * @param mixed $value Option value
64
     */
65 3
    public function setOption($option, $value)
66
    {
67 3
        $this->options[$option] = $value;
68 3
        return $this;
69
    }
70
71
    /**
72
     * @return array
73
     */
74 3
    public function getOptions()
75
    {
76 3
        return $this->options;
77
    }
78
79
    /**
80
     * Every type must run!
81
     * @param mixed $data
82
     * @param string $key
83
     */
84
    abstract public function run(&$data, $key = null);
85
}
86