Total Complexity | 5 |
Total Lines | 60 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | class MethodAccessor implements PropertyAccessorInterface |
||
13 | { |
||
14 | /** |
||
15 | * The getter method name |
||
16 | * |
||
17 | * @var string|null |
||
18 | */ |
||
19 | private $getter; |
||
20 | |||
21 | /** |
||
22 | * The setter method name |
||
23 | * |
||
24 | * @var string|null |
||
25 | */ |
||
26 | private $setter; |
||
27 | |||
28 | /** |
||
29 | * The property name |
||
30 | * |
||
31 | * @var string |
||
32 | */ |
||
33 | private $property; |
||
34 | |||
35 | /** |
||
36 | * Constructor |
||
37 | * |
||
38 | * @param string $class |
||
39 | * @param string $property |
||
40 | * @param string|null $getter Set to false to desactivate |
||
41 | * @param string|null $setter Set to false to desactivate |
||
42 | */ |
||
43 | 22 | public function __construct(string $class, string $property, string $getter = null, string $setter = null) |
|
48 | } |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 6 | public function write($object, $value) |
|
54 | { |
||
55 | 6 | if (!$this->setter) { |
|
56 | 2 | throw new InvalidArgumentException('Could not find setter method for "'.$this->property.'"'); |
|
57 | } |
||
58 | |||
59 | 4 | $object->{$this->setter}($value); |
|
60 | } |
||
61 | |||
62 | /** |
||
63 | * {@inheritdoc} |
||
64 | */ |
||
65 | 8 | public function read($object) |
|
72 | } |
||
73 | } |
||
74 |