Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
7 / 7
CRAP
100.00% covered (success)
100.00%
13 / 13
Stack
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
7 / 7
8
100.00% covered (success)
100.00%
13 / 13
 __construct() // [\SplQueue]
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 bottom() // -> mixed [\SplQueue]
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 count() // -> int [\Countable]
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 isEmpty() // -> bool [\SplQueue]
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 pop() // -> mixed [\SplQueue]
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
 push($value) // [\SplQueue]
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 top() // -> mixed [\SplQueue]
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php namespace SEIDS\LinkedLists\Singly;
//==============================================================================
// PHP SEIDS: Supplementary, Easily Interchangeable Data Structures
// 
// Copyright 2015, Daniel A.C. Martin
// Distributed under the MIT License.
// (See LICENSE file for details.)
//==============================================================================
use \SEIDS\LinkedLists\CantPopFromEmptyException;
class Stack implements \Countable
{
    ////////////////////////////////////////////////////////////////////////////
    // Members
    ////////////////////////////////////////////////////////////////////////////
    
    protected $ds; // &LinkedList
    
    ////////////////////////////////////////////////////////////////////////////
    // Public methods - Implement a tiny subset of \SplStack. We cannot
    //                  implement the full interface as we do not support LIFO.
    ////////////////////////////////////////////////////////////////////////////
    
    public function __construct() // [\SplQueue]
    {
        $this->ds = new LinkedList;
    }
    
    public function bottom() // -> mixed [\SplQueue]
    {
        return $this->ds->top();
    }
    
    public function count() // -> int [\Countable]
    {
        return $this->ds->count();
    }
    
    public function isEmpty() // -> bool [\SplQueue]
    {
        return $this->ds->isEmpty();
    }
    
    public function pop() // -> mixed [\SplQueue]
    {
        $r = null;
        
        if($this->isEmpty())
        {
            throw new CantPopFromEmptyException('Can\'t pop from an empty datastructure');
        }
        else
        {
            $r = $this->ds->shift();
        }
        
        return $r;
    }
    
    public function push($value) // [\SplQueue]
    {
        // SplStack documentation claims that this function returns void but
        // this does not seem to be the case!
        return $this->ds->unshift($value);
    }
    
    //public function setIteratorMode($mode) // [\SplQueue]
    
    public function top() // -> mixed [\SplQueue]
    {
        return $this->ds->bottom();
    }
}