AccessorWriter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 37
loc 37
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 8 8 2
A isWritable() 4 4 1
A setValue() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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