Completed
Push — master ( b5c256...44ef4b )
by Will
27:44 queued 24:40
created

Address   A

Complexity

Total Complexity 31

Size/Duplication

Total Lines 259
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 70.87%

Importance

Changes 0
Metric Value
wmc 31
lcom 1
cbo 7
dl 0
loc 259
ccs 90
cts 127
cp 0.7087
rs 9.8
c 0
b 0
f 0

21 Methods

Rating   Name   Duplication   Size   Complexity  
A getCMSFields() 0 12 1
B getFrontEndFields() 0 26 3
A getCountryField() 0 21 2
B getRequiredFields() 0 21 6
A getName() 0 12 1
A toString() 0 15 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
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 $has_many = 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
        'ShippingAddressOrders' => 'Order.ShippingAddress',
58
        'BillingAddressOrders' => 'Order.BillingAddress'
59
    );
60
61
    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...
62
        'Country' => 'ShopCountry',
63
    );
64
65
    private static $required_fields = array(
66
        'Country',
67
        'State',
68
        'City',
69
        'Address',
70
    );
71
72
    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...
73
        'toString' => 'Address',
74
    );
75
76
    public function getCMSFields()
77
    {
78
        $fields = parent::getCMSFields();
79
        $fields->addFieldToTab(
80
            "Root.Main",
81
            $this->getCountryField(),
82
            'State'
83
        );
84
        $fields->removeByName("MemberID");
85
86
        return $fields;
87
    }
88
89 5
    public function getFrontEndFields($params = null)
90
    {
91 5
        $fields = new FieldList(
92 5
            $this->getCountryField(),
93 5
            $addressfield = TextField::create('Address', _t('Address.db_Address', 'Address')),
94
            $address2field =
95 5
                TextField::create('AddressLine2', _t('Address.db_AddressLine2', 'Address Line 2 (optional)')),
96 5
            $cityfield = TextField::create('City', _t('Address.db_City', 'City')),
97 5
            $statefield = TextField::create('State', _t('Address.db_State', 'State')),
98 5
            $postcodefield = TextField::create('PostalCode', _t('Address.db_PostalCode', 'Postal Code')),
99 5
            $phonefield = TextField::create('Phone', _t('Address.db_Phone', 'Phone Number'))
100 5
        );
101 5
        if (isset($params['addfielddescriptions']) && !empty($params['addfielddescriptions'])) {
102 2
            $addressfield->setDescription(
103 2
                _t("Address.AddressHint", "street / thoroughfare number, name, and type or P.O. Box")
104 2
            );
105 2
            $address2field->setDescription(
106 2
                _t("Address.AddressLine2Hint", "premises, building, apartment, unit, floor")
107 2
            );
108 2
            $cityfield->setDescription(_t("Address.CityHint", "or suburb, county, district"));
109 2
            $statefield->setDescription(_t("Address.StateHint", "or province, territory, island"));
110 2
        }
111
112 5
        $this->extend('updateFormFields', $fields);
113 5
        return $fields;
114
    }
115
116 5
    public function getCountryField()
117
    {
118 5
        $countries = SiteConfig::current_site_config()->getCountriesList();
119 5
        if (count($countries) == 1) {
120
            //field name is Country_readonly so it's value doesn't get updated
121 3
            return ReadonlyField::create(
122 3
                "Country_readonly",
123 3
                _t('Address.db_Country', 'Country'),
124 3
                array_pop($countries)
125 3
            );
126
        }
127 2
        $field = DropdownField::create(
128 2
            "Country",
129 2
            _t('Address.db_Country', 'Country'),
130
            $countries
131 2
        )->setHasEmptyDefault(true);
132
133 2
        $this->extend('updateCountryField', $field);
134
135 2
        return $field;
136
    }
137
138
    /**
139
     * Get an array of data fields that must be populated for model to be valid.
140
     * Required fields can be customised via self::$required_fields
141
     */
142 16
    public function getRequiredFields()
143
    {
144 16
        $fields = self::config()->required_fields;
145
        //hack to allow overriding arrays in ss config
146 16
        if (self::$required_fields != $fields) {
147
            foreach (self::$required_fields as $requirement) {
148
                if (($key = array_search($requirement, $fields)) !== false) {
149
                    unset($fields[$key]);
150
                }
151
            }
152
        }
153
        //set nicer keys for easier processing
154 16
        $fields = array_combine($fields, $fields);
155 16
        $this->extend('updateRequiredFields', $fields);
156
        //don't require country if shop config only specifies a single country
157 16
        if (isset($fields['Country']) && SiteConfig::current_site_config()->getSingleCountry()) {
158 3
            unset($fields['Country']);
159 3
        }
160
161 16
        return $fields;
162
    }
163
164
    /**
165
     * Get full name associated with this Address
166
     */
167 11
    public function getName()
168
    {
169 11
        return implode(
170 11
            ' ',
171 11
            array_filter(
172
                array(
173 11
                    $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...
174 11
                    $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...
175
                )
176 11
            )
177 11
        );
178
    }
179
180
    /**
181
     * Convert address to a single string.
182
     */
183 4
    public function toString($separator = ", ")
184
    {
185
        $fields = array(
186 4
            $this->Company,
0 ignored issues
show
Documentation introduced by
The property Company 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 4
            $this->getName(),
188 4
            $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...
189 4
            $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...
190 4
            $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...
191 4
            $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...
192 4
            $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...
193 4
            $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...
194 4
        );
195 4
        $this->extend('updateToString', $fields);
196 4
        return implode($separator, array_filter($fields));
197
    }
198
199
    public function getTitle()
200
    {
201
        return $this->toString();
202
    }
203
204 7
    public function forTemplate()
205
    {
206 7
        return $this->renderWith('Address');
207
    }
208
209
    /**
210
     * Add alias setters for fields which are synonymous
211
     */
212 17
    public function setProvince($val)
213
    {
214 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...
215 17
    }
216
217 17
    public function setTerritory($val)
218
    {
219 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...
220 17
    }
221
222
    public function setIsland($val)
223
    {
224
        $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...
225
    }
226
227 26
    public function setPostCode($val)
228
    {
229 26
        $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...
230 26
    }
231
232 17
    public function setZipCode($val)
233
    {
234 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...
235 17
    }
236
237
    public function setStreet($val)
238
    {
239
        $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...
240
    }
241
242
    public function setStreet2($val)
243
    {
244
        $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...
245
    }
246
247 26
    public function setAddress2($val)
248
    {
249 26
        $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...
250 26
    }
251
252
    public function setInstitution($val)
253
    {
254
        $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...
255
    }
256
257
    public function setBusiness($val)
258
    {
259
        $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...
260
    }
261
262
    public function setOrganisation($val)
263
    {
264
        $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...
265
    }
266
267
    public function setOrganization($val)
268
    {
269
        $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...
270
    }
271
272 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...
273
    {
274 15
        $result = parent::validate();
275
276 15
        foreach ($this->getRequiredFields() as $requirement) {
277 15
            if (empty($this->$requirement)) {
278 1
                $result->error("Address Model validate function - missing required field: $requirement");
279 1
            }
280 15
        }
281
282 15
        return $result;
283
    }
284
}
285