7
7
*
8
8
* @author Kristopher Wilson <kristopherwilson@gmail.com>
9
9
* @copyright Copyright (c) 2010-2013, Kristopher Wilson
10
- * @package php-gedcom
10
+ * @package php-gedcom
11
11
* @license GPL-3.0
12
12
* @link http://github.com/mrkrstphr/php-gedcom
13
13
*/
@@ -26,43 +26,53 @@ public function __call($method, $args)
26
26
{
27
27
if (substr ($ method , 0 , 3 ) == 'add ' ) {
28
28
$ arr = strtolower (substr ($ method , 3 ));
29
-
29
+
30
30
if (!property_exists ($ this , '_ ' . $ arr ) || !is_array ($ this ->{'_ ' . $ arr })) {
31
31
throw new \Exception ('Unknown ' . get_class ($ this ) . ':: ' . $ arr );
32
32
}
33
-
34
- if (!is_array ($ args ) || ! isset ( $ args [ 0 ]) ) {
33
+
34
+ if (!is_array ($ args )) {
35
35
throw new \Exception ('Incorrect arguments to ' . $ method );
36
36
}
37
37
38
+ if (!isset ($ args [0 ])) {
39
+ // Argument can be empty since we trim it's value
40
+ return ;
41
+ }
42
+
38
43
if (is_object ($ args [0 ])) {
39
44
// Type safety?
40
45
}
41
-
46
+
42
47
$ this ->{'_ ' . $ arr }[] = $ args [0 ];
43
48
44
49
return $ this ;
45
50
} elseif (substr ($ method , 0 , 3 ) == 'set ' ) {
46
51
$ arr = strtolower (substr ($ method , 3 ));
47
-
52
+
48
53
if (!property_exists ($ this , '_ ' . $ arr )) {
49
54
throw new \Exception ('Unknown ' . get_class ($ this ) . ':: ' . $ arr );
50
55
}
51
56
52
- if (!is_array ($ args ) || ! isset ( $ args [ 0 ]) ) {
57
+ if (!is_array ($ args )) {
53
58
throw new \Exception ('Incorrect arguments to ' . $ method );
54
59
}
55
60
61
+ if (!isset ($ args [0 ])) {
62
+ // Argument can be empty since we trim it's value
63
+ return ;
64
+ }
65
+
56
66
if (is_object ($ args [0 ])) {
57
67
// Type safety?
58
68
}
59
-
69
+
60
70
$ this ->{'_ ' . $ arr } = $ args [0 ];
61
71
62
72
return $ this ;
63
73
} elseif (substr ($ method , 0 , 3 ) == 'get ' ) {
64
74
$ arr = strtolower (substr ($ method , 3 ));
65
-
75
+
66
76
if (!property_exists ($ this , '_ ' . $ arr )) {
67
77
throw new \Exception ('Unknown ' . get_class ($ this ) . ':: ' . $ arr );
68
78
}
@@ -72,7 +82,7 @@ public function __call($method, $args)
72
82
throw new \Exception ('Unknown method called: ' . $ method );
73
83
}
74
84
}
75
-
85
+
76
86
/**
77
87
*
78
88
*/
@@ -81,13 +91,13 @@ public function __set($var, $val)
81
91
// this class does not have any public vars
82
92
throw new \Exception ('Undefined property ' . get_class () . ':: ' . $ var );
83
93
}
84
-
94
+
85
95
/**
86
96
* Checks if this GEDCOM object has the provided attribute (ie, if the provided
87
97
* attribute exists below the current object in its tree).
88
- *
89
- * @param string $var The name of the attribute
90
- * @return bool True if this object has the provided attribute
98
+ *
99
+ * @param string $var The name of the attribute
100
+ * @return bool True if this object has the provided attribute
91
101
*/
92
102
public function hasAttribute ($ var )
93
103
{
0 commit comments