Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Commit

Permalink
optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
rez1dent3 committed Apr 11, 2017
1 parent 61391d1 commit cef3688
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 29 deletions.
3 changes: 1 addition & 2 deletions demo/slice.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

include_once dirname(__DIR__) . '/vendor/autoload.php';

$builder = new \Deimos\Builder\Builder();
$helper = new \Deimos\Helper\Helper($builder);
$helper = new \Deimos\Helper\Helper();

$slice = new \Deimos\Slice\Slice($helper, [
'dir' => [
Expand Down
32 changes: 5 additions & 27 deletions src/Slice/Slice.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,7 @@ public function setData(array $storage)
*/
public function getData($path, $default = null)
{
return $this->helper->arr()->get(
$this->storage,
$path,
$default
);
return $this->helper->arr()->get($this->storage, $path, $default);
}

/**
Expand Down Expand Up @@ -213,37 +209,19 @@ public function offsetSet($offset, $value)
if (null === $offset)
{
$this->storage[] = $value;
}
else
{
$path = $this->helper->arr()->keys($offset);
$last = array_pop($path);
$row = &$this->storage;

foreach ($path as $iterator)
{
$row = &$row[$iterator];
}

$row[$last] = $value;
return;
}

$this->helper->arr()->set($this->storage, $offset, $value);
}

/**
* @inheritdoc
*/
public function offsetUnset($offset)
{
$path = $this->helper->arr()->keys($offset);
$last = array_pop($path);
$row = &$this->storage;

foreach ($path as $iterator)
{
$row = &$row[$iterator];
}

unset($row[$last]);
$this->helper->arr()->remove($this->storage, $offset);
}

/**
Expand Down

0 comments on commit cef3688

Please sign in to comment.