Skip to content

Commit

Permalink
Added docblocks for all methods. [closes #11]
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanRL committed Aug 27, 2015
1 parent 65e4e27 commit 7693d7f
Show file tree
Hide file tree
Showing 7 changed files with 169 additions and 1 deletion.
66 changes: 66 additions & 0 deletions src/Samsara/Planck/Core/AbstractGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,21 @@ abstract class AbstractGrid
*/
protected $addresses = [];

/**
* @var array
*/
protected $maxVals = [];

/**
* @var array
*/
protected $minVals = [];

/**
* @param string $name
* @param string $address
* @param GridInterface|null $protoSubGrid
*/
public function __construct($name, $address = '', GridInterface $protoSubGrid = null)
{
$this->name = $name;
Expand All @@ -49,13 +60,23 @@ public function __construct($name, $address = '', GridInterface $protoSubGrid =
}
}

/**
* @param GridInterface $grid
* @return $this
*/
public function attachParentGrid(GridInterface $grid)
{
$this->parentGrid = $grid;

return $this;
}

/**
* @param Node $node
* @param string|null $address
* @return $this
* @throws \Exception
*/
public function attachNode(Node $node, $address = null)
{
if (is_null($address)) {
Expand All @@ -67,6 +88,12 @@ public function attachNode(Node $node, $address = null)
return $this;
}

/**
* @param string $address
* @param GridInterface|null $grid
* @return $this
* @throws \Exception
*/
public function addAddress($address, GridInterface $grid = null)
{
$validAddress = $this->evalAddress($address);
Expand All @@ -83,11 +110,21 @@ public function addAddress($address, GridInterface $grid = null)
return $this;
}

/**
* @param string|null $address
* @return $this|AbstractGrid
* @throws \Exception
*/
public function getLocation($address = null)
{
return $this->resolve($address);
}

/**
* @param string|null $address
* @return Node
* @throws \Exception
*/
public function getNode($address = null)
{
if (is_null($address)) {
Expand All @@ -97,6 +134,11 @@ public function getNode($address = null)
return $this->resolve($address)->getNode();
}

/**
* @param string|null $address
* @return array
* @throws \Exception
*/
public function getNodeProperties($address = null)
{
$location = $this->resolve($address);
Expand All @@ -111,6 +153,9 @@ public function getNodeProperties($address = null)
return $properties;
}

/**
* @return array
*/
public function getNodeEvents()
{
$properties = $this->node->getAllEventsProperties();
Expand All @@ -122,6 +167,9 @@ public function getNodeEvents()
return $properties;
}

/**
* @return $this
*/
public function resetGrid()
{
$this->name = '';
Expand All @@ -131,6 +179,10 @@ public function resetGrid()
return $this;
}

/**
* @param AbstractGrid|null $grid
* @return AbstractGrid
*/
protected function makeSubGrid(AbstractGrid $grid = null)
{
if (is_null($grid)) {
Expand All @@ -147,6 +199,11 @@ protected function makeSubGrid(AbstractGrid $grid = null)
return $return;
}

/**
* @param string $address
* @return array
* @throws \Exception
*/
protected function evalAddress($address)
{
$return = [];
Expand All @@ -169,6 +226,11 @@ protected function evalAddress($address)
return $return;
}

/**
* @param string $address
* @return $this
* @throws \Exception
*/
protected function resolve($address = '')
{
if (empty($address)) {
Expand All @@ -184,6 +246,10 @@ protected function resolve($address = '')
}
}

/**
* @param string $address
* @return bool
*/
abstract protected function isValidAddress($address);

}
16 changes: 15 additions & 1 deletion src/Samsara/Planck/Core/AbstractNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,27 @@

abstract class AbstractNode
{

/**
* @var array
*/
protected $properties = [];

/**
* @param string $key
* @param string $value
* @return $this
*/
public function set($key, $value)
{
$this->properties[$key] = $value;

return $this;
}

/**
* @param string $key
* @return null|mixed
*/
public function get($key)
{
if (array_key_exists($key, $this->properties)) {
Expand All @@ -23,6 +34,9 @@ public function get($key)
return null;
}

/**
* @return array
*/
public function getAllProperties()
{
return $this->properties;
Expand Down
39 changes: 39 additions & 0 deletions src/Samsara/Planck/Core/GridInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,61 @@
interface GridInterface
{

/**
* @param string $name
* @param string $address
* @param GridInterface|null $protoSubGrid
* @param array|null $maxVals
* @param array|null $minVals
*/
public function __construct($name, $address = '', GridInterface $protoSubGrid = null, array $maxVals = null, array $minVals = null);

/**
* @param GridInterface $grid
* @return $this
*/
public function attachParentGrid(GridInterface $grid);

/**
* @param Node $node
* @param null|string $address
* @return $this
*/
public function attachNode(Node $node, $address = null);

/**
* @param string $address
* @param GridInterface|null $grid
* @return $this
*/
public function addAddress($address, GridInterface $grid = null);

/**
* @param string|null $address
* @return $this
*/
public function getLocation($address = null);

/**
* @param string|null $address
* @return Node
*/
public function getNode($address = null);

/**
* @param string|null $address
* @return array
*/
public function getNodeProperties($address = null);

/**
* @return array
*/
public function getNodeEvents();

/**
* @return $this
*/
public function resetGrid();

}
8 changes: 8 additions & 0 deletions src/Samsara/Planck/Factory/GridFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

namespace Samsara\Planck\Factory;

use Samsara\Planck\Core\AbstractGrid;

class GridFactory
{
const TWO_DIMENSION = 'Samsara\\Planck\\Grid\\TwoDimensionGrid';
const THREE_DIMENSION = 'Samsara\\Planck\\Grid\\ThreeDimensionGrid';

/**
* @param string|AbstractGrid $type
* @param array $options
* @return AbstractGrid
* @throws \Exception
*/
public static function makeGrid($type, $options = [])
{
$reflector = new \ReflectionClass($type);
Expand Down
12 changes: 12 additions & 0 deletions src/Samsara/Planck/Grid/ThreeDimensionGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ abstract class ThreeDimensionGrid extends AbstractGrid implements GridInterface
self::AXIS_THREE => 0
];

/**
* @param string $name
* @param string $address
* @param GridInterface|null $protoSubGrid
* @param array|null $maxVals
* @param array|null $minVals
* @throws \Exception
*/
public function __construct($name, $address = '', GridInterface $protoSubGrid = null, array $maxVals = null, array $minVals = null)
{
if (!is_null($maxVals) && count($maxVals)) {
Expand Down Expand Up @@ -68,6 +76,10 @@ public function __construct($name, $address = '', GridInterface $protoSubGrid =
parent::__construct($name, $address, $protoSubGrid);
}

/**
* @param string $address
* @return bool
*/
protected function isValidAddress($address)
{
if (is_string($address)) {
Expand Down
12 changes: 12 additions & 0 deletions src/Samsara/Planck/Grid/TwoDimensionGrid.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class TwoDimensionGrid extends AbstractGrid implements GridInterface
const AXIS_ONE = 'x';
const AXIS_TWO = 'y';

/**
* @param string $name
* @param string $address
* @param GridInterface|null $protoSubGrid
* @param array|null $maxVals
* @param array|null $minVals
* @throws \Exception
*/
public function __construct($name, $address = '', GridInterface $protoSubGrid = null, array $maxVals = null, array $minVals = null)
{
if (!is_null($maxVals) && count($maxVals)) {
Expand Down Expand Up @@ -54,6 +62,10 @@ public function __construct($name, $address = '', GridInterface $protoSubGrid =
parent::__construct($name, $address, $protoSubGrid);
}

/**
* @param string $address
* @return bool
*/
protected function isValidAddress($address)
{
if (is_string($address)) {
Expand Down
17 changes: 17 additions & 0 deletions src/Samsara/Planck/Node/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Node extends AbstractNode
*/
protected $events = [];

/**
* @param string $key
* @param Event $event
* @return $this
* @throws \Exception
*/
public function attachEvent($key, Event $event)
{
if (array_key_exists($key, $this->events)) {
Expand All @@ -22,6 +28,10 @@ public function attachEvent($key, Event $event)
return $this;
}

/**
* @param string $key
* @return null|Event
*/
public function getEvent($key)
{
if (array_key_exists($key, $this->events)) {
Expand All @@ -31,6 +41,10 @@ public function getEvent($key)
return null;
}

/**
* @param string $key
* @return $this
*/
public function removeEvent($key)
{
if (array_key_exists($key, $this->events)) {
Expand All @@ -40,6 +54,9 @@ public function removeEvent($key)
return $this;
}

/**
* @return array
*/
public function getAllEventsProperties()
{
$properties = [];
Expand Down

0 comments on commit 7693d7f

Please sign in to comment.