Skip to content

Commit

Permalink
Merge pull request #25 from tomtomsen/report_with_path
Browse files Browse the repository at this point in the history
path in report
  • Loading branch information
enygma committed Feb 28, 2014
2 parents 6d61dc7 + ba94090 commit 91ae6eb
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/Expose/Export/Text.php
Expand Up @@ -13,6 +13,7 @@ public function render()
$line = '';
$line .= 'Variable: '.$report->getVarName();
$line .= ' | Value: '.$report->getVarValue();
$line .= ' | Path: '.json_encode($report->getVarPath());
$line .= "\n########################\n";

foreach ($report->getFilterMatch() as $filter) {
Expand Down
2 changes: 1 addition & 1 deletion src/Expose/Manager.php
Expand Up @@ -204,7 +204,7 @@ public function runFilters($data, $path, $lvl = 0)
);
$filterMatches[] = $filter;

$report = new \Expose\Report($index, $value);
$report = new \Expose\Report($index, $value, $path);
$report->addFilterMatch($filter);
$this->reports[] = $report;

Expand Down
52 changes: 41 additions & 11 deletions src/Expose/Report.php
Expand Up @@ -16,6 +16,12 @@ class Report
*/
private $varValue = null;

/**
* Path of the variable being evaluated
* @var mixed
*/
private $varPath = null;

/**
* Set of filters matched for the report
* @var array
Expand All @@ -24,23 +30,26 @@ class Report

/**
* Init the object and optionally set the variable name/value
*
*
* @param string $varName Variable name [optional]
* @param mixed $varValue Variable value [optional]
*/
public function __construct($varName = null, $varValue = null)
public function __construct($varName = null, $varValue = null, $varPath = null)
{
if ($varName !== null) {
$this->setVarName($varName);
$this->setVarName($varName);
}
if ($varValue !== null) {
$this->setVarValue($varValue);
}
if ($varPath !== null) {
$this->setVarPath($varPath);
}
}

/**
* Set the current variable's name
*
*
* @param string $name Variable name
*/
public function setVarName($name)
Expand All @@ -50,7 +59,7 @@ public function setVarName($name)

/**
* Get the current variable's name
*
*
* @return string Variable name
*/
public function getVarName()
Expand All @@ -60,7 +69,7 @@ public function getVarName()

/**
* Set variable value
*
*
* @param mixed $value Variable value
*/
public function setVarValue($value)
Expand All @@ -70,31 +79,51 @@ public function setVarValue($value)

/**
* Get varaible value
*
*
* @return mixed variable value
*/
public function getVarValue()
{
return $this->varValue;
}

/**
* Set variable path in data array
*
* @param mixed $path Variable path
*/
public function setVarPath($path)
{
$this->varPath = $path;
}

/**
* Gets the variable path in data array
*
* @return mixed variable path
*/
public function getVarPath()
{
return $this->varPath;
}

/**
* Add filter match(es) for the report/variable relation
* Can take in either a single filter or a set
*
*
* @param mixed $match Either a single \Expose\Filter or an array of them
*/
public function addFilterMatch($match)
{
$match = (!is_array($match)) ? array($match) : $match;
foreach ($match as $filter) {
$this->filterMatches[] = $filter;
$this->filterMatches[] = $filter;
}
}

/**
* Get the current set of filter matches
*
*
* @return array Filter match set
*/
public function getFilterMatch()
Expand All @@ -104,7 +133,7 @@ public function getFilterMatch()

/**
* Convert the object to an array
*
*
* @return array Filter data
*/
public function toArray($expandFilters = false)
Expand All @@ -119,6 +148,7 @@ public function toArray($expandFilters = false)
return array(
'varName' => $this->getVarName(),
'varValue' => $this->getVarValue(),
'varPath' => $this->getVarPath(),
'filterMatches' => $matches
);
}
Expand Down
26 changes: 21 additions & 5 deletions tests/ReportTest.php
Expand Up @@ -13,7 +13,7 @@ public function setUp()

/**
* Test the getter/setter for the variable name
*
*
* @covers \Expose\Report::getVarName
* @covers \Expose\Report::setVarName
*/
Expand All @@ -29,7 +29,7 @@ public function testGetSetVariableName()

/**
* Test the getter/setter for the variable value
*
*
* @covers \Expose\Report::setVarValue
* @covers \Expose\Report::getVarValue
*/
Expand All @@ -43,9 +43,25 @@ public function testGetSetVariableValue()
);
}

/**
* Test the getter/setter for the variable path
*
* @covers \Expose\Report::setVarPath
* @covers \Expose\Report::getVarPath
*/
public function testGetSetVariablePath()
{
$value = 'value1';
$this->report->setVarPath($value);
$this->assertEquals(
$this->report->getVarPath(),
$value
);
}

/**
* Test the getter/setter for working with filter matches
*
*
* @covers \Expose\Report::addFilterMatch
* @covers \Expose\Report::getfilterMatch
*/
Expand All @@ -61,7 +77,7 @@ public function testGetSetFilterMatch()

/**
* Convert the object into an array
*
*
* @covers \Expose\Report::toArray
*/
public function testObjectToArray()
Expand All @@ -78,7 +94,7 @@ public function testObjectToArray()

/**
* Test the "expansion" of filters (converting them to arrays too)
*
*
* @covers \Expose\Report::toArray
*/
public function testObjectToArrayExpandFilters()
Expand Down

0 comments on commit 91ae6eb

Please sign in to comment.