for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Igor Pomiluyko [email protected]
* @license MIT
*/
namespace WS\Utils\Collections;
use RuntimeException;
use WS\Utils\Collections\Iterator\Iterator;
use WS\Utils\Collections\Iterator\IteratorFactory;
class ArrayStack extends AbstractCollection implements Stack, IndexIterable
{
use RemoveTraverseTrait;
* Adds element to the top of stack
*
* @param $element
* @return bool
public function push($element): bool
return $this->add($element);
}
* Gets element from the top of stack
* @return mixed
public function pop()
if ($this->isEmpty()) {
throw new RuntimeException('Stack is empty');
return array_pop($this->elements);
* Retrieves, but does not remove
public function peek()
return $this->elements[count($this->elements) - 1];
public function stream(): Stream
return new SerialStream($this);
public function toArray(): array
return array_reverse($this->elements);
public function getIndexIterator(): Iterator
return IteratorFactory::reverseSequence($this->size());
protected function afterElementAdd($element): void
protected function afterElementsSet(): void