From 29638979b2eda867964704db07cb08bf56a4b89c Mon Sep 17 00:00:00 2001 From: Alf Eaton Date: Sat, 8 Nov 2014 14:13:36 +0000 Subject: [PATCH] Single-line return --- src/MicrodataPhpDOMElement.php | 41 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/src/MicrodataPhpDOMElement.php b/src/MicrodataPhpDOMElement.php index fd3a9c3..b622d9a 100644 --- a/src/MicrodataPhpDOMElement.php +++ b/src/MicrodataPhpDOMElement.php @@ -25,12 +25,11 @@ public function itemScope() { */ public function itemType() { $itemtype = $this->getAttribute('itemtype'); - if (!empty($itemtype)) { - return $this->tokenList($itemtype); - } + // Return NULL instead of the empty string returned by getAttributes so we // can use the function for boolean tests. - return NULL; + + return empty($itemtype) ? NULL : $this->tokenList($itemtype); } /** @@ -41,12 +40,10 @@ public function itemType() { */ public function itemId() { $itemid = $this->getAttribute('itemid'); - if (!empty($itemid)) { - return $itemid; - } + // Return NULL instead of the empty string returned by getAttributes so we // can use the function for boolean tests. - return NULL; + return empty($itemid) ? NULL : $itemid; } /** @@ -57,10 +54,8 @@ public function itemId() { */ public function itemProp() { $itemprop = $this->getAttribute('itemprop'); - if (!empty($itemprop)) { - return $this->tokenList($itemprop); - } - return array(); + + return empty($itemprop) ? array() : $this->tokenList($itemprop); } /** @@ -71,10 +66,8 @@ public function itemProp() { */ public function itemRef() { $itemref = $this->getAttribute('itemref'); - if (!empty($itemref)) { - return $this->tokenList($itemref); - } - return array(); + + return empty($itemref) ? array() : $this->tokenList($itemref); } /** @@ -113,14 +106,19 @@ public function properties() { */ public function itemValue() { $itemprop = $this->itemProp(); - if (empty($itemprop)) + + if (empty($itemprop)) { return null; + } + if ($this->itemScope()) { return $this; } + switch (strtoupper($this->tagName)) { case 'META': return $this->getAttribute('content'); + case 'AUDIO': case 'EMBED': case 'IFRAME': @@ -130,20 +128,25 @@ public function itemValue() { case 'VIDEO': // @todo Should this test that the URL resolves? return $this->getAttribute('src'); + case 'A': case 'AREA': case 'LINK': // @todo Should this test that the URL resolves? return $this->getAttribute('href'); + case 'OBJECT': // @todo Should this test that the URL resolves? return $this->getAttribute('data'); + case 'DATA': return $this->getAttribute('value'); + case 'TIME': $datetime = $this->getAttribute('datetime'); - if (!empty($datetime)) - return $datetime; + + return empty($datetime) ? $this->textContent : $datetime; + default: return $this->textContent; }