Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 22 additions & 19 deletions src/MicrodataPhpDOMElement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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);
}

/**
Expand All @@ -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);
}

/**
Expand Down Expand Up @@ -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':
Expand All @@ -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;
}
Expand Down