Skip to content

Commit

Permalink
optimize arrayObject
Browse files Browse the repository at this point in the history
  • Loading branch information
JanHuang committed Mar 18, 2017
1 parent d0ef733 commit e110c1e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 26 deletions.
8 changes: 4 additions & 4 deletions helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
* @param $string
* @return \FastD\Utils\StringObject
*/
function stringObject($string)
function stringObject($string = '')
{
return \FastD\Utils\StringObject::create($string);
return new \FastD\Utils\StringObject($string);
}

/**
* @param array $array
* @return \FastD\Utils\ArrayObject
*/
function arrayObject(array $array)
function arrayObject(array $array = [])
{
return \FastD\Utils\ArrayObject::create($array);
return new \FastD\Utils\ArrayObject($array);
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/ArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,6 @@
*/
class ArrayObject extends \ArrayObject
{
/**
* @param array $array
* @return static
*/
public static function create(array $array = [])
{
return new static($array);
}

/**
* @return bool
*/
Expand Down Expand Up @@ -92,7 +83,7 @@ public function find($key)
*/
public function implode($glue)
{
return StringObject::create(implode($glue, $this->data));
return stringObject(implode($glue, $this->data));
}

/**
Expand All @@ -108,14 +99,23 @@ public function combine(ArrayObject $arrayObject)
return $this;
}

/**
* @param $key
* @return mixed
*/
public function get($key)
{
return $this->offsetGet($key);
}

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

return $this;
}
Expand Down
11 changes: 1 addition & 10 deletions src/StringObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,13 @@ public function __construct($string)
$this->string = $string;
}

/**
* @param $string
* @return static
*/
public static function create($string)
{
return new static($string);
}

/**
* @param $glue
* @return ArrayObject
*/
public function explode($glue)
{
return ArrayObject::create(explode($glue, $this->string));
return arrayObject(explode($glue, $this->string));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/ArrayObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ArrayObjectTest extends PHPUnit_Framework_TestCase

public function setUp()
{
$this->array = ArrayObject::create();
$this->array = arrayObject();
}

public function testCreate()
Expand Down

0 comments on commit e110c1e

Please sign in to comment.