Skip to content

Commit 8404156

Browse files
Empty argument no longer throw Exception while calling set or add
1 parent 124f080 commit 8404156

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

library/PhpGedcom/Record.php

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @author Kristopher Wilson <kristopherwilson@gmail.com>
99
* @copyright Copyright (c) 2010-2013, Kristopher Wilson
10-
* @package php-gedcom
10+
* @package php-gedcom
1111
* @license GPL-3.0
1212
* @link http://github.com/mrkrstphr/php-gedcom
1313
*/
@@ -26,43 +26,53 @@ public function __call($method, $args)
2626
{
2727
if (substr($method, 0, 3) == 'add') {
2828
$arr = strtolower(substr($method, 3));
29-
29+
3030
if (!property_exists($this, '_' . $arr) || !is_array($this->{'_' . $arr})) {
3131
throw new \Exception('Unknown ' . get_class($this) . '::' . $arr);
3232
}
33-
34-
if (!is_array($args) || !isset($args[0])) {
33+
34+
if (!is_array($args)) {
3535
throw new \Exception('Incorrect arguments to ' . $method);
3636
}
3737

38+
if (!isset($args[0])) {
39+
// Argument can be empty since we trim it's value
40+
return;
41+
}
42+
3843
if (is_object($args[0])) {
3944
// Type safety?
4045
}
41-
46+
4247
$this->{'_' . $arr}[] = $args[0];
4348

4449
return $this;
4550
} elseif (substr($method, 0, 3) == 'set') {
4651
$arr = strtolower(substr($method, 3));
47-
52+
4853
if (!property_exists($this, '_' . $arr)) {
4954
throw new \Exception('Unknown ' . get_class($this) . '::' . $arr);
5055
}
5156

52-
if (!is_array($args) || !isset($args[0])) {
57+
if (!is_array($args)) {
5358
throw new \Exception('Incorrect arguments to ' . $method);
5459
}
5560

61+
if (!isset($args[0])) {
62+
// Argument can be empty since we trim it's value
63+
return;
64+
}
65+
5666
if (is_object($args[0])) {
5767
// Type safety?
5868
}
59-
69+
6070
$this->{'_' . $arr} = $args[0];
6171

6272
return $this;
6373
} elseif (substr($method, 0, 3) == 'get') {
6474
$arr = strtolower(substr($method, 3));
65-
75+
6676
if (!property_exists($this, '_' . $arr)) {
6777
throw new \Exception('Unknown ' . get_class($this) . '::' . $arr);
6878
}
@@ -72,7 +82,7 @@ public function __call($method, $args)
7282
throw new \Exception('Unknown method called: ' . $method);
7383
}
7484
}
75-
85+
7686
/**
7787
*
7888
*/
@@ -81,13 +91,13 @@ public function __set($var, $val)
8191
// this class does not have any public vars
8292
throw new \Exception('Undefined property ' . get_class() . '::' . $var);
8393
}
84-
94+
8595
/**
8696
* Checks if this GEDCOM object has the provided attribute (ie, if the provided
8797
* 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
91101
*/
92102
public function hasAttribute($var)
93103
{

0 commit comments

Comments
 (0)