Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
20 / 20
Stacker
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
10 / 10
11
100.00% covered (success)
100.00%
20 / 20
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 start
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
4 / 4
 create
100.00% covered (success)
100.00%
1 / 1
1  
 
 getStack
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 reset
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 current
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 end
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 isEmpty
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getContainer
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setContainer
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
<?php
/**
 * Manages the Loop instances
 */
namespace Radic\BladeExtensions\Helpers;
use Illuminate\Contracts\Container\Container;
/**
 * Manages the Loop instances
 *
 * @package        Radic\BladeExtensions
 * @subpackage     Helpers
 * @version        2.1.0
 * @author         Robin Radic
 * @license        MIT License - http://radic.mit-license.org
 * @copyright      (2011-2014, Robin Radic - Radic Technologies
 * @link           http://robin.radic.nl/blade-extensions
 *
 */
abstract class Stacker
{
    protected $container;
    /**
     * The stack of Loop instances
     *
     * @var array $stack
     */
    protected $stack = array();
    /**
     * @inheritDoc
     */
    public function __construct(Container $container)
    {
        $this->container = $container;
    }
    /**
     * Adds a Loop to the stack
     */
    public function start()
    {
        $stackItem = static::create(func_get_args());
        array_push($this->stack, $stackItem);
        $stackItem->start();
        return $stackItem;
    }
    /**
     * create
     *
     * @return mixed
     */
    abstract protected function create($args = []);
    /**
     * Returns the stack
     *
     * @return array
     */
    public function getStack()
    {
        return $this->stack;
    }
    /**
     * Resets the stack
     */
    public function reset()
    {
        $this->stack = array();
    }
    /**
     * To be called first inside the foreach loop. Returns the current loop
     *
     * @return mixed $current The current loop data
     */
    public function current()
    {
        $current = end($this->stack);
        return $current;
    }
    /**
     * To be called before the end of the loop
     */
    public function end()
    {
        if (!$this->isEmpty()) {
            static::current()->end();
            array_pop($this->stack);
        }
    }
    public function isEmpty()
    {
        return count($this->stack) === 0;
    }
    /**
     * get container value
     *
     * @return \Illuminate\Contracts\Container\Container
     */
    public function getContainer()
    {
        return $this->container;
    }
    /**
     * Set the container value
     *
     * @param \Illuminate\Contracts\Container\Container $container
     * @return Stacker
     */
    public function setContainer($container)
    {
        $this->container = $container;
        return $this;
    }
}