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 | * Styrer adresser til intranet, bruger, kunde og kontaktperson |
|||||||||||
4 | * |
|||||||||||
5 | * Klassen kan styrer flere forskellige typer af adresser. B�de for intranettet, brugere, kunder og kontaktpersoner. |
|||||||||||
6 | * Beskrivelsen af hvilke og med hvilket navn er beskrevet l�ngere nede. |
|||||||||||
7 | * |
|||||||||||
8 | * @todo Skal vi programmere intranet_id ind i klassen? Det kr�ver at den f�r Kernel. |
|||||||||||
9 | * |
|||||||||||
10 | * @package Intraface |
|||||||||||
11 | * @author Sune Jensen <[email protected]> |
|||||||||||
12 | */ |
|||||||||||
13 | require_once 'Intraface/functions.php'; |
|||||||||||
14 | ||||||||||||
15 | class Intraface_Address extends Intraface_Standard |
|||||||||||
16 | { |
|||||||||||
17 | /** |
|||||||||||
18 | * @var integer |
|||||||||||
19 | */ |
|||||||||||
20 | protected $belong_to_key; |
|||||||||||
21 | ||||||||||||
22 | /** |
|||||||||||
23 | * @var integer |
|||||||||||
24 | */ |
|||||||||||
25 | protected $belong_to_id; |
|||||||||||
26 | ||||||||||||
27 | /** |
|||||||||||
28 | * @var integer |
|||||||||||
29 | */ |
|||||||||||
30 | protected $id; |
|||||||||||
31 | ||||||||||||
32 | /** |
|||||||||||
33 | * @var array |
|||||||||||
34 | */ |
|||||||||||
35 | public $value = array(); |
|||||||||||
36 | ||||||||||||
37 | /** |
|||||||||||
38 | * @var array |
|||||||||||
39 | */ |
|||||||||||
40 | public $fields = array('name', 'address', 'postcode', 'city', 'country', 'cvr', 'email', 'website', 'phone', 'ean'); |
|||||||||||
41 | ||||||||||||
42 | /** |
|||||||||||
43 | * @var object error |
|||||||||||
44 | */ |
|||||||||||
45 | public $error; |
|||||||||||
46 | ||||||||||||
47 | protected $db; |
|||||||||||
48 | ||||||||||||
49 | /** |
|||||||||||
50 | * Init: loader klassen |
|||||||||||
51 | * |
|||||||||||
52 | * Her er angivet de typer af adresser den kan h�ndtere med arrayet address_type[]. |
|||||||||||
53 | * $this-fields er felter i tabellen (db) som overf�res til array og omvendt. M�ske disse |
|||||||||||
54 | * engang skal differencieres, s� man angvier hvad feltet i tabellen skal svare til navnet i arrayet. |
|||||||||||
55 | * Klassen loader ogs� adressens felter |
|||||||||||
56 | * |
|||||||||||
57 | * @param integer $id Id on address. |
|||||||||||
58 | * |
|||||||||||
59 | * @return void |
|||||||||||
0 ignored issues
–
show
|
||||||||||||
60 | */ |
|||||||||||
61 | 97 | function __construct($id) |
||||||||||
62 | { |
|||||||||||
63 | 97 | $this->id = $id; |
||||||||||
64 | 97 | $this->error = new Intraface_Error; |
||||||||||
65 | 97 | $this->db = MDB2::singleton(DB_DSN); |
||||||||||
66 | ||||||||||||
67 | 97 | $this->load(); |
||||||||||
68 | ||||||||||||
69 | 97 | $this->belong_to_types = $this->getBelongToTypes(); |
||||||||||
0 ignored issues
–
show
The property
belong_to_types does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
||||||||||||
70 | ||||||||||||
71 | ||||||||||||
72 | 97 | if (PEAR::isError($this->db)) { |
||||||||||
73 | throw new Exception("Error db singleton: ".$this->db->getUserInfo()); |
|||||||||||
74 | } |
|||||||||||
75 | 97 | $this->db->setFetchMode(MDB2_FETCHMODE_ASSOC); |
||||||||||
76 | 97 | } |
||||||||||
77 | ||||||||||||
78 | /** |
|||||||||||
79 | * Returns an instance of Address from belong_to and belong_to_id |
|||||||||||
80 | * |
|||||||||||
81 | * @deprecated |
|||||||||||
82 | * |
|||||||||||
83 | * @param string $belong_to What the address belongs to, corresponding to the ones in Address::getBelongToTypes() |
|||||||||||
84 | * @param integer $belong_to_id From belong_to. NB not id on the address |
|||||||||||
85 | * |
|||||||||||
86 | * @return object Address |
|||||||||||
87 | */ |
|||||||||||
88 | function factory($belong_to, $belong_to_id) |
|||||||||||
89 | { |
|||||||||||
90 | $gateway = new Intraface_AddressGateway(new DB_Sql); |
|||||||||||
91 | return $gateway->findByBelongToAndId($belong_to, $belong_to_id); |
|||||||||||
92 | } |
|||||||||||
93 | ||||||||||||
94 | /** |
|||||||||||
95 | * Returns possible belong to types |
|||||||||||
96 | * |
|||||||||||
97 | * @return array |
|||||||||||
98 | */ |
|||||||||||
99 | 97 | public static function getBelongToTypes() |
||||||||||
100 | { |
|||||||||||
101 | 97 | return array(1 => 'intranet', |
||||||||||
102 | 97 | 2 => 'user', |
||||||||||
103 | 97 | 3 => 'contact', |
||||||||||
104 | 97 | 4 => 'contact_delivery', |
||||||||||
105 | 97 | 5 => 'contact_invoice', |
||||||||||
106 | 97 | 6 => 'contactperson'); |
||||||||||
107 | } |
|||||||||||
108 | ||||||||||||
109 | /** |
|||||||||||
110 | * Sets belong to @todo used for what? |
|||||||||||
111 | * |
|||||||||||
112 | * @param string $belong_to Which type the address belongs to |
|||||||||||
113 | * @param integer $belong_to_id Which id for the type the address belongs to |
|||||||||||
114 | * |
|||||||||||
115 | * @return void |
|||||||||||
116 | */ |
|||||||||||
117 | 80 | function setBelongTo($belong_to, $belong_to_id) |
||||||||||
118 | { |
|||||||||||
119 | 80 | if ($this->id != 0) { |
||||||||||
120 | // is id already set, then you can not change belong_to |
|||||||||||
121 | return; |
|||||||||||
122 | } |
|||||||||||
123 | ||||||||||||
124 | 80 | $belong_to_types = $this->getBelongToTypes(); |
||||||||||
125 | 80 | $this->belong_to_key = array_search($belong_to, $belong_to_types); |
||||||||||
0 ignored issues
–
show
It seems like
array_search($belong_to, $belong_to_types) can also be of type false . However, the property $belong_to_key is declared as type integer . 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 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;
}
![]() |
||||||||||||
126 | 80 | if ($this->belong_to_key === false) { |
||||||||||
127 | throw new Exception("Invalid address type ".$belong_to." in Address::setBelongTo()"); |
|||||||||||
128 | } |
|||||||||||
129 | ||||||||||||
130 | 80 | $this->belong_to_id = (int)$belong_to_id; |
||||||||||
131 | 80 | if ($this->belong_to_id == 0) { |
||||||||||
132 | throw new Exception("Invalid belong_to_id in Address::setBelongTo()"); |
|||||||||||
133 | } |
|||||||||||
134 | 80 | } |
||||||||||
135 | ||||||||||||
136 | /** |
|||||||||||
137 | * Loads data to array |
|||||||||||
138 | * |
|||||||||||
139 | * @return integer |
|||||||||||
140 | */ |
|||||||||||
141 | 97 | protected function load() |
||||||||||
142 | { |
|||||||||||
143 | 97 | if ($this->id == 0) { |
||||||||||
144 | 80 | return 0; |
||||||||||
145 | } |
|||||||||||
146 | ||||||||||||
147 | 91 | $result = $this->db->query("SELECT id, type, belong_to_id, ".implode(', ', $this->fields)." FROM address WHERE id = ".(int)$this->id); |
||||||||||
148 | ||||||||||||
149 | 91 | if (PEAR::isError($result)) { |
||||||||||
150 | throw new Exception($result->getUserInfo()); |
|||||||||||
151 | } |
|||||||||||
152 | ||||||||||||
153 | 91 | if ($result->numRows() > 1) { |
||||||||||
154 | throw new Exception('There is more than one active address'); |
|||||||||||
155 | } |
|||||||||||
156 | ||||||||||||
157 | 91 | if ($result->numRows() == 0) { |
||||||||||
158 | $this->id = 0; |
|||||||||||
159 | $this->value['id'] = 0; |
|||||||||||
160 | ||||||||||||
161 | return 0; |
|||||||||||
162 | } |
|||||||||||
163 | 91 | $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC); |
||||||||||
164 | ||||||||||||
165 | 91 | $this->value = $row; |
||||||||||
166 | 91 | $this->value['id'] = $row['id']; |
||||||||||
167 | 91 | $this->value['address_id'] = $row['id']; |
||||||||||
168 | 91 | $this->belong_to_key = $row['type']; |
||||||||||
169 | 91 | $this->belong_to_id = $row['belong_to_id']; |
||||||||||
170 | ||||||||||||
171 | 91 | return $this->id; |
||||||||||
172 | } |
|||||||||||
173 | ||||||||||||
174 | /** |
|||||||||||
175 | * Validates |
|||||||||||
176 | * |
|||||||||||
177 | * @param array $array_var Values |
|||||||||||
178 | * |
|||||||||||
179 | * @return boolean |
|||||||||||
180 | */ |
|||||||||||
181 | 2 | function validate($array_var) |
||||||||||
182 | { |
|||||||||||
183 | 2 | $validator = new Intraface_Validator($this->error); |
||||||||||
184 | 2 | if (empty($array_var)) { |
||||||||||
185 | 1 | $this->error->set('array cannot be empty'); |
||||||||||
186 | 1 | } |
||||||||||
187 | ||||||||||||
188 | // public $fields = array('name', 'address', 'postcode', 'city', 'country', 'cvr', 'email', 'website', 'phone', 'ean'); |
|||||||||||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
65% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
||||||||||||
189 | ||||||||||||
190 | 2 | settype($array_var['name'], 'string'); |
||||||||||
191 | 2 | $validator->isString($array_var['name'], 'there was an error in name', ''); |
||||||||||
192 | 2 | settype($array_var['address'], 'string'); |
||||||||||
193 | 2 | $validator->isString($array_var['address'], 'there was an error in address', ''); |
||||||||||
194 | 2 | settype($array_var['postcode'], 'string'); |
||||||||||
195 | 2 | $validator->isNumeric($array_var['postcode'], 'there was an error in postcode', 'greater_than_zero'); |
||||||||||
196 | 2 | settype($array_var['city'], 'string'); |
||||||||||
197 | 2 | $validator->isString($array_var['city'], 'there was an error in city', ''); |
||||||||||
198 | 2 | settype($array_var['country'], 'string'); |
||||||||||
199 | 2 | $validator->isString($array_var['country'], 'there was an error in country', '', 'allow_empty'); |
||||||||||
200 | 2 | settype($array_var['cvr'], 'string'); |
||||||||||
201 | 2 | $validator->isString($array_var['cvr'], 'there was an error in cvr', '', 'allow_empty'); |
||||||||||
202 | // E-mail is not allowed to be empty do you need that. You should probably consider some places there this is needed before you set it (eg. intranet and user address) maybe make a param more to the function determine that: 'email:allow_empty' |
|||||||||||
203 | 2 | settype($array_var['email'], 'string'); |
||||||||||
204 | 2 | $validator->isEmail($array_var['email'], 'not a valid e-mail'); |
||||||||||
205 | 2 | settype($array_var['website'], 'string'); |
||||||||||
206 | 2 | $validator->isUrl($array_var['website'], 'website is not valid', '', 'allow_empty'); |
||||||||||
0 ignored issues
–
show
The call to
Intraface_Validator::isUrl() has too many arguments starting with 'allow_empty' .
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue. If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. In this case you can add the ![]() |
||||||||||||
207 | 2 | settype($array_var['phone'], 'string'); |
||||||||||
208 | 2 | $validator->isString($array_var['phone'], 'not a valid phone number', '', 'allow_empty'); |
||||||||||
209 | 2 | settype($array_var['ean'], 'string'); |
||||||||||
210 | 2 | $validator->isString($array_var['ean'], 'ean location number is not valid', '', 'allow_empty'); |
||||||||||
211 | ||||||||||||
212 | 2 | if ($this->error->isError()) { |
||||||||||
213 | 1 | return false; |
||||||||||
214 | } |
|||||||||||
215 | 1 | return true; |
||||||||||
216 | } |
|||||||||||
217 | ||||||||||||
218 | /** |
|||||||||||
219 | * Public: Denne funktion gemmer data. At gemme data vil sige, at den gamle adresse gemmes, men den nye aktiveres. |
|||||||||||
220 | * |
|||||||||||
221 | * @param array $array_var et array med felter med adressen. Se felterne i init funktionen: $this->fields |
|||||||||||
222 | * |
|||||||||||
223 | * @return bolean true or false |
|||||||||||
224 | */ |
|||||||||||
225 | 72 | function save($array_var) |
||||||||||
226 | { |
|||||||||||
227 | // @todo validate should probably be called. Selenium debtor:testChangeContactPersonAndSender fails. |
|||||||||||
228 | 72 | if ($this->belong_to_key == 0 || $this->belong_to_id == 0) { |
||||||||||
229 | throw new Exception("belong_to or belong_to_id was not set. Maybe because the provided address id was not valid. In Address::save"); |
|||||||||||
230 | } |
|||||||||||
231 | ||||||||||||
232 | 72 | $sql = ''; |
||||||||||
233 | ||||||||||||
234 | 72 | if (count($array_var) > 0) { |
||||||||||
235 | 72 | if ($this->id != 0) { |
||||||||||
236 | 2 | $do_update = 0; |
||||||||||
237 | 2 | foreach ($this->fields as $i => $field) { |
||||||||||
238 | 2 | View Code Duplication | if (array_key_exists($field, $array_var) and isset($array_var[$field])) { |
|||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
239 | 2 | $sql .= $field.' = "'.safeToDb($array_var[$field]).'", '; |
||||||||||
240 | 2 | if ($this->get($field) != $array_var[$field]) { |
||||||||||
241 | 1 | $do_update = 1; |
||||||||||
242 | 1 | } |
||||||||||
243 | 2 | } |
||||||||||
244 | 2 | } |
||||||||||
245 | 2 | View Code Duplication | } else { |
|||||||||
246 | // Kun hvis der rent faktisk gemmes nogle v�rdier opdaterer vi. hvis count($arra_var) > 0 s� m� der ogs� v�re noget at opdatere? |
|||||||||||
247 | 72 | $do_update = 0; |
||||||||||
248 | 72 | foreach ($this->fields as $i => $field) { |
||||||||||
249 | 72 | if (array_key_exists($field, $array_var) and isset($array_var[$field])) { |
||||||||||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Using logical operators such as
and instead of && is generally not recommended.
PHP has two types of connecting operators (logical operators, and boolean operators):
The difference between these is the order in which they are executed. In most cases,
you would want to use a boolean operator like Let’s take a look at a few examples: // Logical operators have lower precedence:
$f = false or true;
// is executed like this:
($f = false) or true;
// Boolean operators have higher precedence:
$f = false || true;
// is executed like this:
$f = (false || true);
Logical Operators are used for Control-FlowOne case where you explicitly want to use logical operators is for control-flow such as this: $x === 5
or die('$x must be 5.');
// Instead of
if ($x !== 5) {
die('$x must be 5.');
}
Since // The following is currently a parse error.
$x === 5
or throw new RuntimeException('$x must be 5.');
These limitations lead to logical operators rarely being of use in current PHP code. ![]() |
||||||||||||
250 | 72 | $sql .= $field.' = "'.safeToDb($array_var[$field]).'", '; |
||||||||||
251 | 72 | $do_update = 1; |
||||||||||
252 | 72 | } |
||||||||||
253 | 72 | } |
||||||||||
254 | } |
|||||||||||
255 | ||||||||||||
256 | 72 | if ($do_update == 0) { |
||||||||||
257 | // There is nothing to save, but that is OK, so we just return 1 |
|||||||||||
258 | 1 | return true; |
||||||||||
259 | } else { |
|||||||||||
260 | 72 | $result = $this->db->exec("UPDATE address SET active = 0 WHERE type = ".$this->belong_to_key." AND belong_to_id = ".$this->belong_to_id); |
||||||||||
261 | 72 | if (PEAR::isError($result)) { |
||||||||||
262 | throw new Exception("Error in exec: ".$result->getUserInfo()); |
|||||||||||
263 | } |
|||||||||||
264 | ||||||||||||
265 | 72 | $result = $this->db->exec("INSERT INTO address SET ".$sql." type = ".$this->belong_to_key.", belong_to_id = ".$this->belong_to_id.", active = 1, changed_date = NOW()"); |
||||||||||
266 | 72 | if (PEAR::isError($result)) { |
||||||||||
267 | throw new Exception("Error in exec: ".$result->getUserInfo()); |
|||||||||||
268 | } |
|||||||||||
269 | 72 | $this->id = $this->db->lastInsertId('address', 'id'); |
||||||||||
270 | 72 | $this->load(); |
||||||||||
271 | 72 | return true; |
||||||||||
272 | } |
|||||||||||
273 | } else { |
|||||||||||
274 | // Der var slet ikke noget indhold i arrayet, s� vi lader v�re at opdatere, men siger, at vi gjorde. |
|||||||||||
275 | return true; |
|||||||||||
276 | } |
|||||||||||
277 | } |
|||||||||||
278 | } |
|||||||||||
279 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.