AccessorWriter::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Importance

Changes 0
Metric Value
dl 8
loc 8
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/*
4
 * This file is part of the rafrsr/lib-array2object package.
5
 *
6
 * (c) Rafael SR <https://github.com/rafrsr>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Rafrsr\LibArray2Object\Writer;
12
13
use Symfony\Component\PropertyAccess\PropertyAccessor;
14
use Symfony\Component\PropertyAccess\PropertyAccessorBuilder;
15
16
/**
17
 * Class AccessorWriter.
18
 */
19 View Code Duplication
class AccessorWriter implements PropertyWriterInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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
     * {@inheritdoc}
42
     */
43
    public function isWritable($object, $propertyPath)
44
    {
45
        return $this->accessor->isWritable($object, $propertyPath);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function setValue(&$object, $propertyPath, $value)
52
    {
53
        $this->accessor->setValue($object, $propertyPath, $value);
54
    }
55
}
56