Skip to content

Commit 3fbc1a3

Browse files
committed
Added check if $data is array or variable before being used in the foreach loop
1 parent d296690 commit 3fbc1a3

1 file changed

Lines changed: 43 additions & 41 deletions

File tree

scripts/appendSetCode.txt

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,49 @@
11
// Json Set Code
22
public function set($data)
33
{
4-
$mapper = \net\authorize\util\Mapper::Instance();
5-
foreach($data AS $key => $value) {
6-
$classDetails = $mapper->getClass(get_class() , $key);
7-
8-
if($classDetails !== NULL ) {
9-
if ($classDetails->isArray) {
10-
if ($classDetails->isCustomDefined) {
11-
foreach($value AS $keyChild => $valueChild) {
12-
$type = new $classDetails->className;
13-
$type->set($valueChild);
14-
$this->{'addTo' . $key}($type);
15-
}
16-
}
17-
else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
18-
foreach($value AS $keyChild => $valueChild) {
19-
$type = new \DateTime($valueChild);
20-
$this->{'addTo' . $key}($type);
21-
}
22-
}
23-
else {
24-
foreach($value AS $keyChild => $valueChild) {
25-
$this->{'addTo' . $key}($valueChild);
26-
}
27-
}
28-
}
29-
else {
30-
if ($classDetails->isCustomDefined){
31-
$type = new $classDetails->className;
32-
$type->set($value);
33-
$this->{'set' . $key}($type);
34-
}
35-
else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
36-
$type = new \DateTime($value);
37-
$this->{'set' . $key}($type);
38-
}
39-
else {
40-
$this->{'set' . $key}($value);
41-
}
42-
}
43-
}
44-
}
4+
if(is_array($data) || is_object($data)) {
5+
$mapper = \net\authorize\util\Mapper::Instance();
6+
foreach($data AS $key => $value) {
7+
$classDetails = $mapper->getClass(get_class() , $key);
8+
9+
if($classDetails !== NULL ) {
10+
if ($classDetails->isArray) {
11+
if ($classDetails->isCustomDefined) {
12+
foreach($value AS $keyChild => $valueChild) {
13+
$type = new $classDetails->className;
14+
$type->set($valueChild);
15+
$this->{'addTo' . $key}($type);
16+
}
17+
}
18+
else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
19+
foreach($value AS $keyChild => $valueChild) {
20+
$type = new \DateTime($valueChild);
21+
$this->{'addTo' . $key}($type);
22+
}
23+
}
24+
else {
25+
foreach($value AS $keyChild => $valueChild) {
26+
$this->{'addTo' . $key}($valueChild);
27+
}
28+
}
29+
}
30+
else {
31+
if ($classDetails->isCustomDefined){
32+
$type = new $classDetails->className;
33+
$type->set($value);
34+
$this->{'set' . $key}($type);
35+
}
36+
else if ($classDetails->className === 'DateTime' || $classDetails->className === 'Date' ) {
37+
$type = new \DateTime($value);
38+
$this->{'set' . $key}($type);
39+
}
40+
else {
41+
$this->{'set' . $key}($value);
42+
}
43+
}
44+
}
45+
}
46+
}
4547
}
4648

4749
}

0 commit comments

Comments
 (0)