Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
AbstractStack
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 current
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 key
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 next
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 rewind
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 valid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3/**
4 * @license MIT
5 * @author hazuki3417<hazuki3417@gmail.com>
6 * @copyright 2021 hazuki3417 all rights reserved.
7 */
8
9namespace Selen\Data\Structure;
10
11abstract class AbstractStack extends AbstractObjects implements StackInterface
12{
13    /** @var mixed 要素の値 */
14    private $workValue;
15
16    /** @var int|string 要素のkey */
17    private $workKey;
18
19    #[\ReturnTypeWillChange]
20    public function current()
21    {
22        return $this->workValue;
23    }
24
25    #[\ReturnTypeWillChange]
26    public function key()
27    {
28        return $this->workKey;
29    }
30
31    public function next(): void
32    {
33        --$this->workKey;
34        $this->workValue = array_pop($this->objects);
35    }
36
37    public function rewind(): void
38    {
39        end($this->objects);
40        $this->workKey   = key($this->objects);
41        $this->workValue = array_pop($this->objects);
42    }
43
44    public function valid(): bool
45    {
46        return $this->workValue !== null;
47    }
48}