Skip to content

Commit c086af4

Browse files
author
Harrison Ifeanyichukwu
committed
refactor: return a ParameterBag for feed array property result value
1 parent c121bb9 commit c086af4

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/FeedItems/BaseFeedItem.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Forensic\FeedParser\XPath;
88
use DOMElement;
99
use Forensic\FeedParser\Traits\Parser;
10+
use Forensic\FeedParser\ParameterBag;
1011

1112
class BaseFeedItem
1213
{
@@ -104,8 +105,14 @@ public function __get(string $property)
104105
{
105106
$this_property = '_' . $property;
106107
if (property_exists($this, $this_property))
107-
return $this->{$this_property};
108-
else
109-
return null;
108+
{
109+
$value = $this->{$this_property};
110+
if (is_array($value))
111+
return new ParameterBag($value);
112+
else
113+
return $value;
114+
}
115+
116+
return null;
110117
}
111118
}

src/Feeds/BaseFeed.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Forensic\FeedParser\FeedItems\ATOMFeedItem;
1111
use Forensic\FeedParser\FeedItems\RSSFeedItem;
1212
use Forensic\FeedParser\FeedItems\RDFFeedItem;
13+
use Forensic\FeedParser\ParameterBag;
1314

1415
class BaseFeed
1516
{
@@ -122,12 +123,23 @@ public function __construct(FeedTypes $feed_type, string $default_lang, XPath $x
122123
$this->_items[] = new $item_class($items->item($i), $xpath, $remove_styles, $remove_scripts);
123124
}
124125

126+
/**
127+
*
128+
*@param string $property - the property to retrieve
129+
*@return string|null
130+
*/
125131
public function __get(string $property)
126132
{
127133
$this_property = '_' . $property;
128134
if (property_exists($this, $this_property))
129-
return $this->{$this_property};
130-
else
131-
return null;
135+
{
136+
$value = $this->{$this_property};
137+
if (is_array($value))
138+
return new ParameterBag($value);
139+
else
140+
return $value;
141+
}
142+
143+
return null;
132144
}
133145
}

0 commit comments

Comments
 (0)