Skip to content

Commit

Permalink
Improved code climate
Browse files Browse the repository at this point in the history
  • Loading branch information
jkphl committed Mar 5, 2017
1 parent 384bdda commit 1892b93
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
30 changes: 21 additions & 9 deletions src/Micrometa/Application/Factory/ItemFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,31 @@ protected function getProperties(\stdClass $item)
$properties = [];
if (isset($item->properties) && is_array($item->properties)) {
foreach ($item->properties as $propertyName => $propertyValues) {
try {
$expandedPropertyValues = $this->getPropertyValues($propertyValues);
if (count($expandedPropertyValues)) {
$properties [$propertyName] = $expandedPropertyValues;
}
} catch (InvalidArgumentException $e) {
continue;
}
$this->processPropertyValues($properties, $propertyName, $propertyValues);
}
}
return $properties;
}

/**
* Process the values of a property
*
* @param array $properties Properties
* @param string $propertyName Property name
* @param array $propertyValues Property values
*/
protected function processPropertyValues(array &$properties, $propertyName, $propertyValues)
{
try {
$expandedPropertyValues = $this->getPropertyValues($propertyValues);
if (count($expandedPropertyValues)) {
$properties[$propertyName] = $expandedPropertyValues;
}
} catch (InvalidArgumentException $e) {
// Skip this property
}
}

/**
* Prepare item property values
*
Expand All @@ -119,7 +131,7 @@ protected function getPropertyValues($propertyValues)
}

return array_map(
function($propertyValue) {
function ($propertyValue) {
return is_object($propertyValue) ? $this->__invoke($propertyValue) : $propertyValue;
},
$propertyValues
Expand Down
2 changes: 1 addition & 1 deletion src/Micrometa/Infrastructure/Parser/ParsingResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ParsingResult implements ParsingResultInterface
/**
* Extracted items
*
* @var \stdClass[]
* @var ItemInterface[]
*/
protected $items;
/**
Expand Down

0 comments on commit 1892b93

Please sign in to comment.