Completed
Push — master ( 3dee16...2bf36e )
by Andy
02:57
created

Membership   A

Complexity

Total Complexity 23

Size/Duplication

Total Lines 128
Duplicated Lines 5.47 %

Coupling/Cohesion

Components 2
Dependencies 1

Test Coverage

Coverage 95.45%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 23
c 1
b 0
f 0
lcom 2
cbo 1
dl 7
loc 128
ccs 42
cts 44
cp 0.9545
rs 10

20 Methods

Rating   Name   Duplication   Size   Complexity  
A __toString() 0 4 1
A getRole() 0 4 1
A getPersonId() 0 4 1
A getPerson() 0 4 1
A getOrganizationId() 0 4 1
A getOrganization() 0 4 1
A getAreaId() 0 4 1
A getArea() 0 4 1
A getLegislativePeriodId() 0 4 1
A getLegislativePeriod() 0 4 1
A getOnBehalfOfId() 0 4 1
A getOnBehalfOf() 0 4 1
A getPostId() 0 4 1
A getPost() 0 4 1
A getStartDate() 0 5 1
A getEndDate() 0 5 1
A getKeyForHash() 0 6 1
A getCurrent() 0 4 1
A currentAt() 0 4 2
A equals() 7 7 3

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 EveryPolitician\EveryPoliticianPopolo\Objects;
4
5
class Membership extends PopoloObject
6
{
7
    protected $properties = [
8
        'role',
9
        'personId',
10
        'person',
11
        'organizationId',
12
        'organization',
13
        'areaId',
14
        'area',
15
        'legislativePeriodId',
16
        'legislativePeriod',
17
        'onBehalfOfId',
18
        'onBehalfOf',
19
        'postId',
20
        'post',
21
        'startDate',
22
        'endDate',
23
        'current',
24
    ];
25
26 3
    public function __toString()
27
    {
28 3
        return "<Membership: '".$this->personId."' at '".$this->organizationId."'>";
0 ignored issues
show
Documentation introduced by
The property personId does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property organizationId does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
29
    }
30
31 3
    protected function getRole()
32
    {
33 3
        return $this->arrGet($this->data, 'role');
34
    }
35
36 12
    protected function getPersonId()
37
    {
38 12
        return $this->arrGet($this->data, 'person_id');
39
    }
40
41 3
    protected function getPerson()
42
    {
43 3
        return $this->allPopolo->persons->lookupFromKey[$this->personId];
0 ignored issues
show
Documentation introduced by
The property personId does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
44
    }
45
46 9
    protected function getOrganizationId()
47
    {
48 9
        return $this->arrGet($this->data, 'organization_id');
49
    }
50
51 3
    protected function getOrganization()
52
    {
53 3
        return $this->allPopolo->organizations->lookupFromKey[$this->organizationId];
0 ignored issues
show
Documentation introduced by
The property organizationId does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
54
    }
55
56 6
    protected function getAreaId()
57
    {
58 6
        return $this->arrGet($this->data, 'area_id');
59
    }
60
61 3
    protected function getArea()
62
    {
63 3
        return $this->allPopolo->areas->lookupFromKey[$this->areaId];
0 ignored issues
show
Documentation introduced by
The property areaId does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
64
    }
65
66 6
    protected function getLegislativePeriodId()
67
    {
68 6
        return $this->arrGet($this->data, 'legislative_period_id');
69
    }
70
71 3
    protected function getLegislativePeriod()
72
    {
73 3
        return $this->allPopolo->events->lookupFromKey[$this->legislativePeriodId];
0 ignored issues
show
Documentation introduced by
The property legislativePeriodId does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
74
    }
75
76 6
    protected function getOnBehalfOfId()
77
    {
78 6
        return $this->arrGet($this->data, 'on_behalf_of_id');
79
    }
80
81 3
    protected function getOnBehalfOf()
82
    {
83 3
        return $this->allPopolo->organizations->lookupFromKey[$this->onBehalfOfId];
0 ignored issues
show
Documentation introduced by
The property onBehalfOfId does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
84
    }
85
86 6
    protected function getPostId()
87
    {
88 6
        return $this->arrGet($this->data, 'post_id');
89
    }
90
91 3
    protected function getPost()
92
    {
93 3
        return $this->allPopolo->posts->lookupFromKey[$this->postId];
0 ignored issues
show
Documentation introduced by
The property postId does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
94
    }
95
96 12
    protected function getStartDate()
97
    {
98
        // TODO: Mark uses his magical ApproxDate.PAST here
99 12
        return $this->getDate('start_date');
100
    }
101
102 6
    protected function getEndDate()
103
    {
104
        // TODO: Mark uses his magical ApproxDate.FUTURE here
105 6
        return $this->getDate('end_date');
106
    }
107
108 54
    protected function getKeyForHash()
109
    {
110 54
        $sortedData = $this->data;
111 54
        ksort($sortedData);
112 54
        return json_encode($sortedData);
113
    }
114
115
    protected function getCurrent()
116
    {
117
        return $this->currentAt(new \DateTime);
118
    }
119
120 9
    public function currentAt($when)
121
    {
122 9
        return ($when >= $this->startDate && $when <= $this->endDate);
0 ignored issues
show
Documentation introduced by
The property startDate does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Documentation introduced by
The property endDate does not exist on object<EveryPolitician\E...olo\Objects\Membership>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
123
    }
124
125 9 View Code Duplication
    public function equals($other)
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...
126
    {
127 9
        if (is_object($other) && get_class($other) == get_class($this)) {
128 6
            return $this->data == $other->data;
129
        }
130 3
        throw new \BadMethodCallException;
131
    }
132
}
133