Improved safe_var_dump(), Inventory::addItem() Inventory::removeItem() using argument unpacking

This commit is contained in:
Shoghi Cervantes 2014-08-27 12:29:04 +02:00
parent 759d7e2545
commit 8e9da9c84e
3 changed files with 6 additions and 8 deletions

View File

@ -20,9 +20,9 @@
*/
namespace {
function safe_var_dump(){
function safe_var_dump(...$params){
static $cnt = 0;
foreach(func_get_args() as $var){
foreach($params as $var){
switch(true){
case is_array($var):
echo str_repeat(" ", $cnt) . "array(" . count($var) . ") {" . PHP_EOL;

View File

@ -225,9 +225,8 @@ abstract class BaseInventory implements Inventory{
return false;
}
public function addItem(){
public function addItem(...$slots){
/** @var Item[] $slots */
$slots = func_get_args();
foreach($slots as $i => $slot){
$slots[$i] = clone $slot;
}
@ -264,9 +263,8 @@ abstract class BaseInventory implements Inventory{
return $slots;
}
public function removeItem(){
public function removeItem(...$slots){
/** @var Item[] $slots */
$slots = func_get_args();
for($i = 0; $i < $this->getSize(); ++$i){
$item = $this->getItem($i);
if($item->getID() === Item::AIR){

View File

@ -73,7 +73,7 @@ interface Inventory{
*
* @return Item[]
*/
public function addItem();
public function addItem(...$slots);
/**
* Checks if a given Item can be added to the inventory
@ -92,7 +92,7 @@ interface Inventory{
*
* @return Item[]
*/
public function removeItem();
public function removeItem(...$slots);
/**
* @return Item[]