Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00%
0 / 1
0.00%
0 / 4
CRAP
0.00%
0 / 24
Stack
0.00%
0 / 1
0.00%
0 / 4
42
0.00%
0 / 24
 push($item)
0.00%
0 / 1
2
0.00%
0 / 5
 pushMultiple($items)
0.00%
0 / 1
2
0.00%
0 / 5
 pop()
0.00%
0 / 1
6
0.00%
0 / 7
 peek()
0.00%
0 / 1
6
0.00%
0 / 7
<?php
// Copyright (c) Lellys Informática. All rights reserved. See License.txt in the project root for license information.
namespace Easy\Collections;
use BadFunctionCallException;
use Easy\Collections\CollectionArray;
/**
 * Represents a simple last-in-first-out (LIFO) non-generic collection of objects.
 */
class Stack extends CollectionArray implements IStack
{
    /**
     * Inserts an object at the top of the Stack.
     * @param type $item The Object to push onto the Stack. The value <b>can</b> be null.
     */
    public function push($item)
    {
        array_push($this->array, $item);
        return $this;
    }
    /**
     * Inserts multiples objects at the top of the Stack.
     * @param type $item The Objects to push onto the Stack. The value <b>can</b> be null.
     */
    public function pushMultiple($items)
    {
        $this->addMultiple($items);
        return $this;
    }
    /**
     * Removes and returns the object at the top of the Stack.
     * @return mixed The Object removed from the top of the Stack.
     * @throws BadFunctionCallException
     */
    public function pop()
    {
        if ($this->isEmpty()) {
            throw new BadFunctionCallException(__('Cannot use method Pop on an empty Stack'));
        }
        return array_pop($this->array);
    }
    /**
     * Returns the object at the top of the Stack without removing it.
     * @return mixed The Object at the top of the Stack.
     * @throws BadFunctionCallException
     */
    public function peek()
    {
        if ($this->isEmpty()) {
            throw new BadFunctionCallException(__('Cannot use method Peek on an empty Stack'));
        }
        return end($this->array);
    }
}