ValueObject   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 76
Duplicated Lines 19.74 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 95%

Importance

Changes 5
Bugs 0 Features 0
Metric Value
wmc 8
c 5
b 0
f 0
lcom 0
cbo 1
dl 15
loc 76
ccs 19
cts 20
cp 0.95
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A __get() 7 9 2
A __set() 8 12 2
A __isset() 0 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
namespace Marek\Toggable\API\Toggl\Values;
4
5
use Marek\Toggable\API\Exception\PropertyNotFoundException;
6
7
/**
8
 * Class ValueObject
9
 * @package Marek\Toggable\API\Toggl\Values
10
 */
11
abstract class ValueObject
12
{
13
    /**
14
     * Construct object optionally with a set of properties.
15
     *
16
     * Readonly properties values must be set using $properties as they are not writable anymore
17
     * after object has been created.
18
     *
19
     * @param array $properties
20
     *
21
     * @throws \Marek\Toggable\API\Exception\PropertyNotFoundException
22
     */
23 387
    public function __construct(array $properties = array())
24
    {
25 387
        foreach ($properties as $property => $value) {
26 339
            if (property_exists($this, $property)) {
27 338
                $this->$property = $value;
28 338
            } else {
29 1
                throw new PropertyNotFoundException($property, get_class($this));
30
            }
31 387
        }
32 387
    }
33
34
35
    /**
36
     * @param $property
37
     *
38
     * @return mixed
39
     *
40
     * @throws \Marek\Toggable\API\Exception\PropertyNotFoundException
41
     * @throws \Marek\Toggable\API\Exception\PropertyReadOnlyException
42
     */
43 48 View Code Duplication
    public function __get($property)
0 ignored issues
show
Duplication introduced by
This method 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...
44
    {
45 48
        if (property_exists($this, $property)) {
46
47 47
            return $this->$property;
48
49
        }
50 1
        throw new PropertyNotFoundException($property, get_class($this));
51
    }
52
53
    /**
54
     * @param $property
55
     * @param $value
56
     *
57
     * @return mixed
58
     *
59
     * @throws \Marek\Toggable\API\Exception\PropertyNotFoundException
60
     * @throws \Marek\Toggable\API\Exception\PropertyReadOnlyException
61
     */
62 13 View Code Duplication
    public function __set($property, $value)
0 ignored issues
show
Duplication introduced by
This method 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...
63
    {
64 13
        if (property_exists($this, $property)) {
65
66 13
            $this->$property = $value;
67
68 13
        } else {
69
70
            throw new PropertyNotFoundException($property, get_class($this));
71
72
        }
73 13
    }
74
75
    /**
76
     * Magic isset function handling isset() to non public properties
77
     *
78
     * @param string $property
79
     *
80
     * @return boolean
81
     */
82 14
    public function __isset($property)
83
    {
84 14
        return !empty($this->$property);
85
    }
86
}
87