for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Walker;
/**
* Class Walker
*/
class Walker
{
private $dataStream;
* @var array
private $founds = [];
private $target;
* @param array $founds
private function setFounds(array $founds)
$this->founds = $founds;
}
* @param $json
* @return $this
public function fromJson($json)
$this->setFounds([]);
$this->dataStream = json_decode($json);
return $this;
* @param $rawData
public function from($rawData)
$this->dataStream = $rawData;
* @param $target
* @return Walker
public function with($target)
$this->target = $target;
$this->run();
* @param callable|null $formatter
* @return string
public function asString(callable $formatter = null)
return (is_null($formatter)) ? implode(', ', $this->founds) : $formatter($this->founds);
* @return array
public function asArray()
return $this->founds;
protected function parseTarget($target)
if (empty($target)) {
throw new \LogicException(sprintf('You must call %s::with($target) first', get_class($this)));
$separator = '->';
return(explode($separator, $target));
* @param $node
* @param array $matches
* @return void
protected function walk($node, array $matches)
if (is_object($node)) {
$match = array_shift($matches);
if (property_exists($node, $match)) {
if(count($matches) === 0 && isset($node->$match)) {
$this->founds[] = $node->$match;
return;
$this->walk($node->$match, $matches);
} elseif (is_array($node)) {
foreach($node as $n) {
$this->walk($n, $matches);
private function run()
$this->walk($this->dataStream, $this->parseTarget($this->target));