Completed
Push — master ( 01abf8...56bab1 )
by Andy
02:13
created

Membership::equals()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 3
cts 4
cp 0.75
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 2.0625
1
<?php
2
3
namespace mySociety\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
    ];
24
25 3
    public function __toString()
26
    {
27 3
        return "<Membership: '".$this->personId."' at '".$this->organizationId."'>";
0 ignored issues
show
Documentation introduced by
The property personId does not exist on object<mySociety\EveryPo...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<mySociety\EveryPo...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...
28
    }
29
30 3
    protected function getRole()
31
    {
32 3
        return $this->arrGet($this->data, 'role');
33
    }
34
35 6
    protected function getPersonId()
36
    {
37 6
        return $this->arrGet($this->data, 'person_id');
38
    }
39
40
    protected function getPerson()
41
    {
42
        return $this->allPopolo->persons->lookupFromKey[$this->personId];
0 ignored issues
show
Documentation introduced by
The property personId does not exist on object<mySociety\EveryPo...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...
43
    }
44
45 6
    protected function getOrganizationId()
46
    {
47 6
        return $this->arrGet($this->data, 'organization_id');
48
    }
49
50
    protected function getOrganization()
51
    {
52
        return $this->allPopolo->organizations->lookupFromKey[$this->organizationId];
0 ignored issues
show
Documentation introduced by
The property organizationId does not exist on object<mySociety\EveryPo...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...
53
    }
54
55 3
    protected function getAreaId()
56
    {
57 3
        return $this->arrGet($this->data, 'area_id');
58
    }
59
60
    protected function getArea()
61
    {
62
        return $this->allPopolo->areas->lookupFromKey[$this->areaId];
0 ignored issues
show
Documentation introduced by
The property areaId does not exist on object<mySociety\EveryPo...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...
63
    }
64
65 3
    protected function getLegislativePeriodId()
66
    {
67 3
        return $this->arrGet($this->data, 'legislative_period_id');
68
    }
69
70
    protected function getLegislativePeriod()
71
    {
72
        return $this->allPopolo->events->lookupFromKey[$this->eventId];
0 ignored issues
show
Documentation introduced by
The property eventId does not exist on object<mySociety\EveryPo...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...
73
    }
74
75 3
    protected function getOnBehalfOfId()
76
    {
77 3
        return $this->arrGet($this->data, 'on_behalf_of_id');
78
    }
79
80
    protected function getOnBehalfOf()
81
    {
82
        return $this->allPopolo->organizations->lookupFromKey[$this->onBehalfOfId];
0 ignored issues
show
Documentation introduced by
The property onBehalfOfId does not exist on object<mySociety\EveryPo...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...
83
    }
84
85 3
    protected function getPostId()
86
    {
87 3
        return $this->arrGet($this->data, 'post_id');
88
    }
89
90
    protected function getPost()
91
    {
92
        return $this->allPopolo->posts->lookupFromKey[$this->postId];
0 ignored issues
show
Documentation introduced by
The property postId does not exist on object<mySociety\EveryPo...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...
93
    }
94
95 3
    protected function getStartDate()
96
    {
97
        // TODO: Mark uses his magical ApproxDate.PAST here
98 3
        return $this->getDate('start_date');
99
    }
100
101
    protected function getEndDate()
102
    {
103
        // TODO: Mark uses his magical ApproxDate.FUTURE here
104
        return $this->getDate('end_date');
105
    }
106
107 21
    protected function getKeyForHash()
108
    {
109 21
        $sortedData = $this->data;
110 21
        ksort($sortedData);
111 21
        return json_encode($sortedData);
112
    }
113
114 3 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...
115
    {
116 3
        if (get_class($other) == get_class($this)) {
117 3
            return $this->data == $other->data;
118
        }
119
        throw new \BadMethodCallException;
120
    }
121
}
122