This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * Payment DataObject |
||
5 | * |
||
6 | * This class is used for storing a payment amount, and it's status of being |
||
7 | * paid or not, and the gateway used to make payment. |
||
8 | * |
||
9 | * @package payment |
||
10 | */ |
||
11 | final class Payment extends DataObject{ |
||
12 | |||
13 | private static $db = array( |
||
14 | 'Gateway' => 'Varchar(50)', //this is the omnipay 'short name' |
||
15 | 'Money' => 'Money', //contains Amount and Currency |
||
16 | 'Status' => "Enum('Created,Authorized,Captured,Refunded,Void','Created')", |
||
17 | 'Identifier' => 'Varchar' |
||
18 | ); |
||
19 | |||
20 | private static $has_many = array( |
||
21 | 'Messages' => 'PaymentMessage' |
||
22 | ); |
||
23 | |||
24 | private static $defaults = array( |
||
25 | 'Status' => 'Created' |
||
26 | ); |
||
27 | |||
28 | private static $casting = array( |
||
29 | "Amount" => "Decimal" |
||
30 | ); |
||
31 | |||
32 | private static $summary_fields = array( |
||
33 | 'Money' => 'Money', |
||
34 | 'GatewayTitle' => 'Gateway', |
||
35 | 'PaymentStatus' => 'Status', |
||
36 | 'Created.Nice' => 'Created' |
||
37 | ); |
||
38 | |||
39 | private static $indexes = array( |
||
40 | 'Identifier' => true, |
||
41 | ); |
||
42 | |||
43 | private static $default_sort = "\"Created\" DESC, \"ID\" DESC"; |
||
44 | |||
45 | public function getCMSFields() { |
||
46 | $fields = new FieldList( |
||
47 | TextField::create("MoneyValue", _t("Payment.MONEY", "Money"), $this->dbObject('Money')->Nice()), |
||
48 | TextField::create("GatewayTitle", _t("Payment.GATEWAY", "Gateway")) |
||
49 | ); |
||
50 | $fields = $fields->makeReadonly(); |
||
51 | $fields->push( |
||
52 | GridField::create("Messages", _t("Payment.MESSAGES", "Messages"), $this->Messages(), |
||
0 ignored issues
–
show
|
|||
53 | GridFieldConfig_RecordViewer::create() |
||
54 | ) |
||
55 | ); |
||
56 | |||
57 | $this->extend('updateCMSFields', $fields); |
||
58 | |||
59 | return $fields; |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Change search context to use a dropdown for list of gateways. |
||
64 | */ |
||
65 | public function getDefaultSearchContext() { |
||
66 | $context = parent::getDefaultSearchContext(); |
||
67 | $fields = $context->getSearchFields(); |
||
68 | |||
69 | $fields->removeByName('Gateway'); |
||
70 | $fields->removeByName('Created'); |
||
71 | $fields->insertAfter(DropdownField::create('Gateway', _t('Payment.GATEWAY', 'Gateway'), |
||
72 | GatewayInfo::get_supported_gateways() |
||
73 | )->setHasEmptyDefault(true), 'Money'); |
||
0 ignored issues
–
show
'Money' is of type string , but the function expects a object<FormField> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
74 | |||
75 | // create a localized status dropdown for the search-context |
||
76 | $fields->insertAfter(DropdownField::create('Status', _t('Payment.db_Status', 'Status'), |
||
77 | $this->getStatusValues() |
||
78 | )->setHasEmptyDefault(true), 'Gateway'); |
||
0 ignored issues
–
show
'Gateway' is of type string , but the function expects a object<FormField> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
79 | |||
80 | // update "money" to localized title |
||
81 | $fields->fieldByName('Money')->setTitle(_t('Payment.MONEY', 'Money')); |
||
82 | |||
83 | $context->addFilter(new PartialMatchFilter('Gateway')); |
||
84 | |||
85 | return $context; |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * Set gateway, amount, and currency in one function. |
||
90 | * @param string $gateway omnipay gateway short name |
||
91 | * @param float $amount monetary amount |
||
92 | * @param string $currency the currency to set |
||
93 | * @return Payment this object for chaining |
||
94 | */ |
||
95 | public function init($gateway, $amount, $currency) { |
||
96 | $this->setGateway($gateway); |
||
97 | $this->setAmount($amount); |
||
98 | $this->setCurrency($currency); |
||
99 | return $this; |
||
100 | } |
||
101 | |||
102 | public function getTitle() { |
||
103 | return implode(' ', array( |
||
104 | $this->getGatewayTitle(), |
||
105 | $this->forTemplate()->Nice(), |
||
106 | $this->dbObject('Created')->Date() |
||
107 | )); |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Set the payment gateway |
||
112 | * @param string $gateway the omnipay gateway short name. |
||
113 | * @return Payment this object for chaining |
||
114 | */ |
||
115 | public function setGateway($gateway) { |
||
116 | if ($this->Status == 'Created') { |
||
0 ignored issues
–
show
The property
Status does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
117 | $this->setField('Gateway', $gateway); |
||
118 | } |
||
119 | return $this; |
||
120 | } |
||
121 | |||
122 | public function getGatewayTitle() { |
||
123 | return GatewayInfo::nice_title($this->Gateway); |
||
0 ignored issues
–
show
The property
Gateway does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Get the payment status. This will return a localized value if available. |
||
128 | * @return string the payment status |
||
129 | */ |
||
130 | public function getPaymentStatus() { |
||
131 | return _t('Payment.STATUS_' . strtoupper($this->Status), $this->Status); |
||
0 ignored issues
–
show
The property
Status does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
132 | } |
||
133 | |||
134 | /** |
||
135 | * Get the payment amount |
||
136 | * @return string amount of this payment |
||
137 | */ |
||
138 | public function getAmount() { |
||
139 | return $this->MoneyAmount; |
||
0 ignored issues
–
show
The property
MoneyAmount does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
140 | } |
||
141 | |||
142 | /** |
||
143 | * Set the payment amount, but only when the status is 'Created'. |
||
144 | * @param float $amt value to set the payment to |
||
0 ignored issues
–
show
There is no parameter named
$amt . Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. ![]() |
|||
145 | * @return Payment this object for chaining |
||
146 | */ |
||
147 | public function setAmount($amount) { |
||
148 | if ($amount instanceof Money) { |
||
149 | $this->setField("Money", $amount); |
||
150 | } elseif ($this->Status == 'Created' && is_numeric($amount)) { |
||
0 ignored issues
–
show
The property
Status does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
151 | $this->MoneyAmount = $amount; |
||
0 ignored issues
–
show
The property
MoneyAmount does not exist on object<Payment> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?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. ![]() |
|||
152 | } |
||
153 | return $this; |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Get just the currency of this payment's money component |
||
158 | * @return string the currency of this payment |
||
159 | */ |
||
160 | public function getCurrency() { |
||
161 | return $this->MoneyCurrency; |
||
0 ignored issues
–
show
The property
MoneyCurrency does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
162 | } |
||
163 | |||
164 | /** |
||
165 | * Set the payment currency, but only when the status is 'Created'. |
||
166 | * @param string $currency the currency to set |
||
167 | */ |
||
168 | public function setCurrency($currency) { |
||
169 | if ($this->Status == 'Created') { |
||
0 ignored issues
–
show
The property
Status does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
170 | $this->MoneyCurrency = $currency; |
||
0 ignored issues
–
show
The property
MoneyCurrency does not exist on object<Payment> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?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. ![]() |
|||
171 | } |
||
172 | |||
173 | return $this; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * This payment requires no more processing. |
||
178 | * @return boolean completion |
||
179 | */ |
||
180 | public function isComplete() { |
||
181 | return $this->Status == 'Captured' || |
||
0 ignored issues
–
show
The property
Status does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
182 | $this->Status == 'Refunded' || |
||
0 ignored issues
–
show
The property
Status does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
183 | $this->Status == 'Void'; |
||
0 ignored issues
–
show
The property
Status does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
184 | } |
||
185 | |||
186 | /** |
||
187 | * Check the payment is captured. |
||
188 | * @return boolean completion |
||
189 | */ |
||
190 | public function isCaptured() { |
||
191 | return $this->Status == 'Captured'; |
||
0 ignored issues
–
show
The property
Status does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
192 | } |
||
193 | |||
194 | public function forTemplate() { |
||
195 | return $this->dbObject('Money'); |
||
196 | } |
||
197 | |||
198 | /** |
||
199 | * Only allow setting identifier, if one doesn't exist yet. |
||
200 | * @param string $id identifier |
||
201 | */ |
||
202 | public function setIdentifier($id) { |
||
203 | if (!$this->Identifier) { |
||
0 ignored issues
–
show
The property
Identifier does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
204 | $this->setField('Identifier', $id); |
||
205 | } |
||
206 | } |
||
207 | |||
208 | protected function onBeforeWrite() { |
||
209 | parent::onBeforeWrite(); |
||
210 | if(!$this->Identifier){ |
||
0 ignored issues
–
show
The property
Identifier does not exist on object<Payment> . Since you implemented __get , maybe consider adding a @property annotation.
Since your code implements the magic getter <?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. ![]() |
|||
211 | $this->Identifier = $this->generateUniquePaymentIdentifier(); |
||
0 ignored issues
–
show
The property
Identifier does not exist on object<Payment> . Since you implemented __set , maybe consider adding a @property annotation.
Since your code implements the magic setter <?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. ![]() |
|||
212 | } |
||
213 | } |
||
214 | |||
215 | /** |
||
216 | * Generate an internally unique string that identifies a payment, |
||
217 | * and can be used in URLs. |
||
218 | * @return string Identifier |
||
219 | */ |
||
220 | public function generateUniquePaymentIdentifier() { |
||
221 | $generator = Injector::inst()->create('RandomGenerator'); |
||
222 | $id = null; |
||
0 ignored issues
–
show
$id is not used, you could remove the assignment.
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently. $myVar = 'Value';
$higher = false;
if (rand(1, 6) > 3) {
$higher = true;
} else {
$higher = false;
}
Both the ![]() |
|||
223 | do{ |
||
224 | $id = substr($generator->randomToken(), 0, 30); |
||
225 | } while (!$id && self::get()->filter('Identifier', $id)->exists()); |
||
226 | |||
227 | return $id; |
||
228 | } |
||
229 | |||
230 | public function provideI18nEntities() |
||
231 | { |
||
232 | $entities = parent::provideI18nEntities(); |
||
233 | |||
234 | // collect all the payment status values |
||
235 | foreach($this->dbObject('Status')->enumValues() as $value){ |
||
236 | $key = strtoupper($value); |
||
237 | $entities["Payment.STATUS_$key"] = array( |
||
238 | $value, |
||
239 | "Translation of the payment status '$value'" |
||
240 | ); |
||
241 | } |
||
242 | |||
243 | return $entities; |
||
0 ignored issues
–
show
The return type of
return $entities; (array<*,array> ) is incompatible with the return type of the parent method DataObject::provideI18nEntities of type array<*,array<array|inte...double|string|boolean>> .
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design. Let’s take a look at an example: class Author {
private $name;
public function __construct($name) {
$this->name = $name;
}
public function getName() {
return $this->name;
}
}
abstract class Post {
public function getAuthor() {
return 'Johannes';
}
}
class BlogPost extends Post {
public function getAuthor() {
return new Author('Johannes');
}
}
class ForumPost extends Post { /* ... */ }
function my_function(Post $post) {
echo strtoupper($post->getAuthor());
}
Our function ![]() |
|||
244 | } |
||
245 | |||
246 | /** |
||
247 | * Get an array of status enum value to translated string. |
||
248 | * Can be used for dropdowns |
||
249 | * @return array |
||
250 | */ |
||
251 | protected function getStatusValues() |
||
252 | { |
||
253 | $values = array(); |
||
254 | foreach($this->dbObject('Status')->enumValues() as $value){ |
||
255 | $values[$value] = _t('Payment.STATUS_' . strtoupper($value), $value); |
||
256 | } |
||
257 | return $values; |
||
258 | } |
||
259 | } |
||
260 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: