CountryPrice::getCountryName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * Holds prices for individual countries for
5
 * Buyables.
6
 *
7
 *
8
 */
9
10
class CountryPrice extends DataObject
11
{
12
13
    // CURRENCY LIST AND STATIC FUNCTIONS
14
15
    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...
16
        'Price' => 'Currency',
17
        'Country' => 'Varchar(2)',
18
        'Currency' => 'Varchar(3)',
19
        'ObjectClass' => 'Varchar',
20
        'ObjectID' => 'Int'
21
    );
22
23
    private static $field_labels = 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...
24
        'Currency' => 'Currency Code',
25
        'Country' => 'Country Code',
26
        'ObjectClass' => 'Buyable Name',
27
        'ObjectID' => 'Buyable ID'
28
    );
29
    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...
30
        'BuyableName' => 'Buyable',
31
        'CountryName' => 'Country',
32
        'FullPrice' => 'Price'
33
    );
34
35
    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...
36
        'BuyableName' => 'Varchar',
37
        'Title' => 'Varchar',
38
        'CountryName' => 'Varchar',
39
        'FullPrice' => 'Varchar'
40
    );
41
42
    private static $indexes = 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...
43
        'Unique' => array(
44
            'type' => 'unique',
45
            'value' => 'Country,ObjectClass,ObjectID'
46
        ),
47
        'Currency' => true
48
    );
49
50
    private static $searchable_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...
51
        'Price' => 'PartialMatchFilter',
52
        'Country' => 'PartialMatchFilter',
53
        'Currency' => 'PartialMatchFilter'
54
    );
55
56
    /**
57
     * caching only variable
58
     * @var EcommerceCountry | null
59
     */
60
    private $_myBuyable = null;
61
62
    /**
63
     * the buyable we relate to
64
     * return DataObject | null
65
     */
66
    public function Buyable()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
67
    {
68
        if (! $this->_myBuyable) {
69
            $className = $this->ObjectClass;
0 ignored issues
show
Documentation introduced by
The property ObjectClass does not exist on object<CountryPrice>. 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...
70
            if (class_exists($this->ObjectClass)) {
0 ignored issues
show
Documentation introduced by
The property ObjectClass does not exist on object<CountryPrice>. 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...
71
                $this->_myBuyable = $className::get()->byID($this->ObjectID);
0 ignored issues
show
Documentation introduced by
The property ObjectID does not exist on object<CountryPrice>. 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...
72
            }
73
        }
74
75
        return $this->_myBuyable;
76
    }
77
78
    /**
79
     * caching only variable
80
     * @var EcommerceCountry | null
81
     */
82
    private $_myCountryObject = null;
83
84
    /**
85
     *
86
     * return EcommerceCountry | null
87
     */
88
    public function CountryObject()
89
    {
90
        if (! $this->_myCountryObject) {
91
            if ($this->Country) {
0 ignored issues
show
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
92
                $this->_myCountryObject =  EcommerceCountry::get()
0 ignored issues
show
Documentation Bug introduced by
It seems like \EcommerceCountry::get()...his->Country))->First() can also be of type object<DataObject>. However, the property $_myCountryObject is declared as type object<EcommerceCountry>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
93
                    ->filter(array("Code" => $this->Country))
0 ignored issues
show
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
94
                    ->First();
95
            }
96
        }
97
98
        return $this->_myCountryObject;
99
    }
100
101
    /**
102
     *
103
     * return EcommerceCountry | null
104
     */
105
    public function CurrencyObject()
106
    {
107
        if ($this->Country) {
0 ignored issues
show
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
108
            return EcommerceCurrency::get()->filter(array("Code" => $this->Currency))->First();
0 ignored issues
show
Documentation introduced by
The property Currency does not exist on object<CountryPrice>. 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...
109
        }
110
    }
111
112
    /**
113
     * casted variable
114
     * @return String
115
     */
116
    public function getBuyableName()
117
    {
118
        if ($obj = $this->Buyable()) {
119
            return $obj->Title;
120
        }
121
        return "ERROR: Object not found";
122
    }
123
124
    /**
125
     * casted variable
126
     * @return String
127
     */
128
    public function getTitle()
129
    {
130
        return $this->getBuyableName()." // ".$this->getCountryName()."// ".$this->getFullPrice();
131
    }
132
133
    /**
134
     * casted variable
135
     * @return String
136
     */
137
    public function getCountryName()
138
    {
139
        return EcommerceCountry::find_title($this->Country);
0 ignored issues
show
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
140
    }
141
142
    /**
143
     * casted variable
144
     * returns nicely formatted price..
145
     * @return String
146
     */
147
    public function getFullPrice()
148
    {
149
        return "$this->Price $this->Currency" . ($this->isObsolete() ? ' (obsolete!)' : '');
0 ignored issues
show
Documentation introduced by
The property Price does not exist on object<CountryPrice>. 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 Currency does not exist on object<CountryPrice>. 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...
150
    }
151
152
    public function getCMSFields()
153
    {
154
        $fields = parent::getCMSFields();
155
        // This works only because only NZ uses NZD
156
        $countries = CountryPrice_EcommerceCountry::get_real_countries_list()->map('Code', 'Name')->toArray();
157
        unset($countries[EcommerceConfig::get('EcommerceCountry', 'default_country_code')]);
158
        $field = DropdownField::create('Country', 'Country', $countries);
159
        $fields->replaceField('Country', $field);
160
161
        if ($this->ID) {
162
            $fields->makeFieldReadonly('Country');
163
            $list = EcommerceCurrency::ecommerce_currency_list()->exclude(array("Code" => $this->Currency));
0 ignored issues
show
Documentation introduced by
The property Currency does not exist on object<CountryPrice>. 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...
164
            if ($list->count()) {
165
                $listArray = array($this->Currency => $this->Currency) + $list->map("Code", "Name")->toArray();
0 ignored issues
show
Documentation introduced by
The property Currency does not exist on object<CountryPrice>. 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...
166
            } else {
167
                $listArray = array($this->Currency => $this->Currency);
0 ignored issues
show
Documentation introduced by
The property Currency does not exist on object<CountryPrice>. 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...
168
            }
169
            $fields->replaceField(
170
                'Currency',
171
                DropdownField::create(
172
                    'Currency',
173
                    'Currency',
174
                    $listArray
175
                )
176
            );
177
        } else {
178
            $fields->removeByName('Currency');
179
        }
180
        $fields->removeByName('ObjectClass');
181
        $fields->removeByName('ObjectID');
182
        if (self::$cms_object) {
183
            $fields->addFieldToTab("Root.Main", new HiddenField('MyObjectClass', '', self::$cms_object->ClassName));
184
            $fields->addFieldToTab("Root.Main", new HiddenField('MyObjectID', '', self::$cms_object->ID));
185
        } else {
186
            //to do BuyableSelectField
187
        }
188
        $buyable = $this->Buyable();
189
        if ($buyable && $buyable->exists()) {
190
            $fields->addFieldToTab(
191
                'Root.Main',
192
                $buyableLink = ReadonlyField::create(
193
                    'ProductOrService',
194
                    'Product or Service',
195
                    '<a href="'.$buyable->CMSEditLink().'">'.$this->getBuyableName().'</a>'
196
                )
197
            );
198
            $buyableLink->dontEscape = true;
199
        }
200
        $fields->addFieldsToTab(
201
            'Root.Debug',
202
            array(
203
                ReadonlyField::create('ObjectClass', 'ObjectClass'),
204
                ReadonlyField::create('ObjectID', 'ObjectID')
205
            )
206
        );
207
        return $fields;
208
    }
209
210
    private static $cms_object = null;
211
212
    //MUST KEEP
213
    public static function set_cms_object($o)
214
    {
215
        self::$cms_object = $o;
216
    }
217
218
    public function canEdit($member = null)
219
    {
220
        $canEdit = parent::canEdit();
221
        if (! $canEdit) {
222
            $member = Member::currentUser();
223
            $distributor = $member->Distributor();
224
            if ($distributor->exists()) {
225
                return $distributor->getComponents('Countries', "\"Code\" = '$this->Country'")->Count() > 0;
0 ignored issues
show
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
226
            }
227
        }
228
        return $canEdit;
229
    }
230
231
    /**
232
     * We use validate as an onBeforeWrite as well because in this case it makes sense
233
     * as in the validation process we add stuff...
234
     * @return ValidationResult
235
     */
236
    protected function validate()
237
    {
238
        $result = parent::validate();
239
        if (! $this->ObjectClass && isset($_REQUEST["MyObjectClass"])) {
0 ignored issues
show
Documentation introduced by
The property ObjectClass does not exist on object<CountryPrice>. 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...
240
            if (class_exists($_REQUEST["MyObjectClass"])) {
241
                $this->ObjectClass = Convert::raw2sql($_REQUEST["MyObjectClass"]);
0 ignored issues
show
Documentation introduced by
The property ObjectClass does not exist on object<CountryPrice>. 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...
242
            }
243
        }
244
        if (! $this->ObjectID && isset($_REQUEST["MyObjectID"])) {
0 ignored issues
show
Documentation introduced by
The property ObjectID does not exist on object<CountryPrice>. 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...
245
            $this->ObjectID = intval($_REQUEST["MyObjectID"]);
0 ignored issues
show
Documentation introduced by
The property ObjectID does not exist on object<CountryPrice>. 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...
246
        }
247
        //check for duplicates in case it has not been created yet...
248
        if (! $this->ObjectClass || ! $this->ObjectID) {
0 ignored issues
show
Documentation introduced by
The property ObjectClass does not exist on object<CountryPrice>. 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 ObjectID does not exist on object<CountryPrice>. 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...
249
            $result->error('Object could not be created. Please contact your developer.');
250
            return $result;
251
        }
252
        $currencyPerCountry = CountryPrice_EcommerceCurrency::get_currency_per_country();
253
        if (!isset($currencyPerCountry[$this->Country])) {
0 ignored issues
show
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
254
            $result->error("Can not find currency for this country '".$this->Country."'");
0 ignored issues
show
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
255
        }
256
        $this->Currency = $currencyPerCountry[$this->Country];
0 ignored issues
show
Documentation introduced by
The property Currency does not exist on object<CountryPrice>. 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...
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
257
        $duplicates = CountryPrice::get()
258
            ->exclude(array("ID" => $this->ID - 0))
259
            ->filter(array("ObjectClass" => $this->ObjectClass, "ObjectID" => $this->ObjectID, "Country" => $this->Country));
0 ignored issues
show
Documentation introduced by
The property ObjectClass does not exist on object<CountryPrice>. 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 ObjectID does not exist on object<CountryPrice>. 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...
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
260
        if ($duplicates->count()) {
261
            $result->error('You can not add this price for this country because a price for this country already exists.');
262
        }
263
        return $result;
264
    }
265
266
    /**
267
     * Returns if the currency is an old currency not used anymore.
268
     * @return Boolean
0 ignored issues
show
Documentation introduced by
Should the return type not be boolean|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
269
     */
270
    public function isObsolete()
271
    {
272
        $currencyPerCountry = CountryPrice_EcommerceCurrency::get_currency_per_country();
273
        if (isset($currencyPerCountry[$this->Country])) {
0 ignored issues
show
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
274
            return $currencyPerCountry[$this->Country] != $this->Currency;
0 ignored issues
show
Documentation introduced by
The property Currency does not exist on object<CountryPrice>. 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...
Bug introduced by
The property Country does not seem to exist. Did you mean _myCountryObject?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
275
        }
276
    }
277
278
    /**
279
     * name of session variable used to set Country
280
     * @var String
281
     */
282
    private static $location_param = 'Location';
283
284
285
    /**
286
     * country for user
287
     * @var String
288
     */
289
    private static $location_country;
290
291
    /**
292
     * returns Country code
293
     * @return string
294
     */
295
    public static function get_location_country()
296
    {
297
        return self::$location_country;
298
    }
299
}
300