Completed
Pull Request — 2.0 (#506)
by Roman
18:39
created

Address   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 252
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 70.4%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 31
c 3
b 1
f 1
lcom 1
cbo 7
dl 0
loc 252
ccs 88
cts 125
cp 0.704
rs 9.8

21 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 12 1
B getFrontEndFields() 0 26 3
B getRequiredFields() 0 21 6
A getName() 0 12 1
A toString() 0 13 1
A getTitle() 0 4 1
A forTemplate() 0 4 1
A setProvince() 0 4 1
A setTerritory() 0 4 1
A setIsland() 0 4 1
A setPostCode() 0 4 1
A setZipCode() 0 4 1
A setStreet() 0 4 1
A setStreet2() 0 4 1
A setAddress2() 0 4 1
A setInstitution() 0 4 1
A setBusiness() 0 4 1
A setOrganisation() 0 4 1
A setOrganization() 0 4 1
A validate() 0 12 3
A getCountryField() 0 21 2
1
<?php
2
3
/**
4
 * Address model using a generic format for storing international addresses.
5
 *
6
 * Typical Address Hierarcy:
7
 *    Continent
8
 *    Country
9
 *    State / Province / Territory (Island?)
10
 *    District / Suburb / County / City
11
 *        Code / Zip (may cross over the above)
12
 *    Street / Road - name + type: eg Gandalf Cresent
13
 *    (Premises/Building/Unit/Suite)
14
 *        (Floor/Level/Side/Wing)
15
 *    Number / Entrance / Room
16
 *    Person(s), Company, Department
17
 *
18
 * Collection of international address formats:
19
 *
20
 * @see http://bitboost.com/ref/international-address-formats.html
21
 *      xAL address standard:
22
 * @see https://www.oasis-open.org/committees/ciq/ciq.html#6
23
 *      Universal Postal Union addressing standards:
24
 * @see http://www.upu.int/nc/en/activities/addressing/standards.html
25
 */
26
class Address extends DataObject
27
{
28
    private static $db              = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
29
        'Country'    => 'ShopCountry',
30
        //level1: Country = ISO 2-character country code
31
        'State'      => 'Varchar(100)',
32
        //level2: Locality, Administrative Area, State, Province, Region, Territory, Island
33
        'City'       => 'Varchar(100)',
34
        //level3: Dependent Locality, City, Suburb, County, District
35
        'PostalCode' => 'Varchar(20)',
36
        //code: ZipCode, PostCode (could cross above levels within a country)
37
38
        'Address'      => 'Varchar(255)',
39
        //Number + type of thoroughfare/street. P.O. box
40
        'AddressLine2' => 'Varchar(255)',
41
        //Premises, Apartment, Building. Suite, Unit, Floor, Level, Side, Wing.
42
43
        'Company' => 'Varchar(100)',
44
        //Business, Organisation, Group, Institution.
45
46
        'FirstName' => 'Varchar(100)',
47
        //Individual, Person, Contact, Attention
48
        'Surname'   => 'Varchar(100)',
49
        'Phone'     => 'Varchar(100)',
50
    );
51
52
    private static $has_one         = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
53
        'Member' => 'Member',
54
    );
55
56
    private static $casting         = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
57
        'Country' => 'ShopCountry',
58
    );
59
60
    private static $required_fields = array(
61
        'Country',
62
        'State',
63
        'City',
64
        'Address',
65
    );
66
67
    private static $summary_fields  = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
68
        'toString' => 'Address',
69
    );
70
71
    public function getCMSFields()
72
    {
73
        $fields = parent::getCMSFields();
74
        $fields->addFieldToTab(
75
            "Root.Main",
76
            $this->getCountryField(),
77
            'State'
78
        );
79
        $fields->removeByName("MemberID");
80
81
        return $fields;
82
    }
83
84 5
    public function getFrontEndFields($params = null)
85
    {
86 5
        $fields = new FieldList(
87 5
            $this->getCountryField(),
88 5
            $addressfield = TextField::create('Address', _t('Address.db_Address', 'Address')),
89
            $address2field =
90 5
                TextField::create('AddressLine2', _t('Address.db_AddressLine2', 'Address Line 2 (optional)')),
91 5
            $cityfield = TextField::create('City', _t('Address.db_City', 'City')),
92 5
            $statefield = TextField::create('State', _t('Address.db_State', 'State')),
93 5
            $postcodefield = TextField::create('PostalCode', _t('Address.db_PostalCode', 'Postal Code')),
94 5
            $phonefield = TextField::create('Phone', _t('Address.db_Phone', 'Phone Number'))
95 5
        );
96 5
        if (isset($params['addfielddescriptions']) && !empty($params['addfielddescriptions'])) {
97 2
            $addressfield->setDescription(
98 2
                _t("Address.AddressHint", "street / thoroughfare number, name, and type or P.O. Box")
99 2
            );
100 2
            $address2field->setDescription(
101 2
                _t("Address.AddressLine2Hint", "premises, building, apartment, unit, floor")
102 2
            );
103 2
            $cityfield->setDescription(_t("Address.CityHint", "or suburb, county, district"));
104 2
            $statefield->setDescription(_t("Address.StateHint", "or province, territory, island"));
105 2
        }
106
107 5
        $this->extend('updateFormFields', $fields);
108 5
        return $fields;
109
    }
110
111 5
    public function getCountryField()
112
    {
113 5
        $countries = SiteConfig::current_site_config()->getCountriesList();
114 5
        if (count($countries) == 1) {
115
            //field name is Country_readonly so it's value doesn't get updated
116 3
            return ReadonlyField::create(
117 3
                "Country_readonly",
118 3
                _t('Address.db_Country', 'Country'),
119 3
                array_pop($countries)
120 3
            );
121
        }
122 2
        $field = DropdownField::create(
123 2
            "Country",
124 2
            _t('Address.db_Country', 'Country'),
125
            $countries
126 2
        )->setHasEmptyDefault(true);
127
128 2
        $this->extend('updateCountryField', $field);
129
130 2
        return $field;
131
    }
132
133
    /**
134
     * Get an array of data fields that must be populated for model to be valid.
135
     * Required fields can be customised via self::$required_fields
136
     */
137 16
    public function getRequiredFields()
138
    {
139 16
        $fields = self::config()->required_fields;
140
        //hack to allow overriding arrays in ss config
141 16
        if (self::$required_fields != $fields) {
142
            foreach (self::$required_fields as $requirement) {
143
                if (($key = array_search($requirement, $fields)) !== false) {
144
                    unset($fields[$key]);
145
                }
146
            }
147
        }
148
        //set nicer keys for easier processing
149 16
        $fields = array_combine($fields, $fields);
150 16
        $this->extend('updateRequiredFields', $fields);
151
        //don't require country if shop config only specifies a single country
152 16
        if (isset($fields['Country']) && SiteConfig::current_site_config()->getSingleCountry()) {
153 3
            unset($fields['Country']);
154 3
        }
155
156 16
        return $fields;
157
    }
158
159
    /**
160
     * Get full name associated with this Address
161
     */
162 5
    public function getName()
163
    {
164 5
        return implode(
165 5
            ' ',
166 5
            array_filter(
167
                array(
168 5
                    $this->FirstName,
0 ignored issues
show
Documentation introduced by
The property FirstName does not exist on object<Address>. 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...
169 5
                    $this->Surname,
0 ignored issues
show
Documentation introduced by
The property Surname does not exist on object<Address>. 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...
170
                )
171 5
            )
172 5
        );
173
    }
174
175
    /**
176
     * Convert address to a single string.
177
     */
178 3
    public function toString($separator = ", ")
179
    {
180
        $fields = array(
181 3
            $this->Address,
0 ignored issues
show
Documentation introduced by
The property Address does not exist on object<Address>. 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...
182 3
            $this->AddressLine2,
0 ignored issues
show
Documentation introduced by
The property AddressLine2 does not exist on object<Address>. 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...
183 3
            $this->City,
0 ignored issues
show
Documentation introduced by
The property City does not exist on object<Address>. 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...
184 3
            $this->State,
0 ignored issues
show
Documentation introduced by
The property State does not exist on object<Address>. 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...
185 3
            $this->PostalCode,
0 ignored issues
show
Documentation introduced by
The property PostalCode does not exist on object<Address>. 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...
186 3
            $this->Country,
0 ignored issues
show
Documentation introduced by
The property Country does not exist on object<Address>. 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...
187 3
        );
188 3
        $this->extend('updateToString', $fields);
189 3
        return implode($separator, array_filter($fields));
190
    }
191
192
    public function getTitle()
193
    {
194
        return $this->toString();
195
    }
196
197 3
    public function forTemplate()
198
    {
199 3
        return $this->renderWith('Address');
200
    }
201
202
    /**
203
     * Add alias setters for fields which are synonymous
204
     */
205 17
    public function setProvince($val)
206
    {
207 17
        $this->State = $val;
0 ignored issues
show
Documentation introduced by
The property State does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
208 17
    }
209
210 17
    public function setTerritory($val)
211
    {
212 17
        $this->State = $val;
0 ignored issues
show
Documentation introduced by
The property State does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
213 17
    }
214
215
    public function setIsland($val)
216
    {
217
        $this->State = $val;
0 ignored issues
show
Documentation introduced by
The property State does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
218
    }
219
220 23
    public function setPostCode($val)
221
    {
222 23
        $this->PostalCode = $val;
0 ignored issues
show
Documentation introduced by
The property PostalCode does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
223 23
    }
224
225 17
    public function setZipCode($val)
226
    {
227 17
        $this->PostalCode = $val;
0 ignored issues
show
Documentation introduced by
The property PostalCode does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
228 17
    }
229
230
    public function setStreet($val)
231
    {
232
        $this->Address = $val;
0 ignored issues
show
Documentation introduced by
The property Address does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
233
    }
234
235
    public function setStreet2($val)
236
    {
237
        $this->AddressLine2 = $val;
0 ignored issues
show
Documentation introduced by
The property AddressLine2 does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
238
    }
239
240 23
    public function setAddress2($val)
241
    {
242 23
        $this->AddressLine2 = $val;
0 ignored issues
show
Documentation introduced by
The property AddressLine2 does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
243 23
    }
244
245
    public function setInstitution($val)
246
    {
247
        $this->Company = $val;
0 ignored issues
show
Documentation introduced by
The property Company does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
248
    }
249
250
    public function setBusiness($val)
251
    {
252
        $this->Company = $val;
0 ignored issues
show
Documentation introduced by
The property Company does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
253
    }
254
255
    public function setOrganisation($val)
256
    {
257
        $this->Company = $val;
0 ignored issues
show
Documentation introduced by
The property Company does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
258
    }
259
260
    public function setOrganization($val)
261
    {
262
        $this->Company = $val;
0 ignored issues
show
Documentation introduced by
The property Company does not exist on object<Address>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
263
    }
264
265 15
    function validate()
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
266
    {
267 15
        $result = parent::validate();
268
269 15
        foreach ($this->getRequiredFields() as $requirement) {
270 15
            if (empty($this->$requirement)) {
271 1
                $result->error("Address Model validate function - missing required field: $requirement");
272 1
            }
273 15
        }
274
275 15
        return $result;
276
    }
277
}
278