Completed
Push — master ( fef923...c0df34 )
by Rafael
03:03
created

AccessorWriter::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 3
1
<?php
2
3
/**
4
 * LICENSE: This file is subject to the terms and conditions defined in
5
 * file 'LICENSE', which is part of this source code package.
6
 *
7
 * @copyright 2016 Copyright(c) - All rights reserved.
8
 */
9
10
namespace Rafrsr\LibArray2Object\Writer;
11
12
use Symfony\Component\PropertyAccess\PropertyAccessor;
13
use Symfony\Component\PropertyAccess\PropertyAccessorBuilder;
14
15
/**
16
 * Class AccessorWriter
17
 */
18
class AccessorWriter implements PropertyWriterInterface
19
{
20
21
    /**
22
     * @var PropertyAccessor
23
     */
24
    protected $accessor;
25
26
    /**
27
     * AccessorWriter constructor.
28
     *
29
     * @param PropertyAccessorBuilder|null $builder
30
     */
31
    public function __construct(PropertyAccessorBuilder $builder = null)
32
    {
33
        if (!$builder) {
34
            $builder = new PropertyAccessorBuilder();
35
        }
36
37
        $this->accessor = $builder->getPropertyAccessor();
38
    }
39
40
41
    /**
42
     * @inheritDoc
43
     */
44
    public function isWritable($object, $propertyPath)
45
    {
46
        return $this->accessor->isWritable($object, $propertyPath);
47
    }
48
49
    /**
50
     * @inheritDoc
51
     */
52
    public function setValue(&$object, $propertyPath, $value)
53
    {
54
        $this->accessor->setValue($object, $propertyPath, $value);
55
    }
56
}