• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PHPOffice / PhpSpreadsheet / 18014029598

25 Sep 2025 04:20PM UTC coverage: 95.867% (+0.3%) from 95.602%
18014029598

push

github

web-flow
Merge pull request #4663 from oleibman/tweakcoveralls

Tweak Coveralls

45116 of 47061 relevant lines covered (95.87%)

373.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.5
/src/PhpSpreadsheet/Calculation/Token/Stack.php
1
<?php
2

3
namespace PhpOffice\PhpSpreadsheet\Calculation\Token;
4

5
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
6
use PhpOffice\PhpSpreadsheet\Calculation\Engine\BranchPruner;
7
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
8

9
class Stack
10
{
11
    private BranchPruner $branchPruner;
12

13
    /**
14
     * The parser stack for formulae.
15
     *
16
     * @var array<int, array<mixed>>
17
     */
18
    private array $stack = [];
19

20
    /**
21
     * Count of entries in the parser stack.
22
     */
23
    private int $count = 0;
24

25
    public function __construct(BranchPruner $branchPruner)
12,175✔
26
    {
27
        $this->branchPruner = $branchPruner;
12,175✔
28
    }
29

30
    /**
31
     * Return the number of entries on the stack.
32
     */
33
    public function count(): int
11,912✔
34
    {
35
        return $this->count;
11,912✔
36
    }
37

38
    /**
39
     * Push a new entry onto the stack.
40
     */
41
    public function push(string $type, mixed $value, ?string $reference = null): void
12,157✔
42
    {
43
        $stackItem = $this->getStackItem($type, $value, $reference);
12,157✔
44
        $this->stack[$this->count++] = $stackItem;
12,157✔
45

46
        if ($type === 'Function') {
12,157✔
47
            $localeFunction = Calculation::localeFunc(StringHelper::convertToString($value));
11,792✔
48
            if ($localeFunction != $value) {
11,792✔
49
                $this->stack[($this->count - 1)]['localeValue'] = $localeFunction;
68✔
50
            }
51
        }
52
    }
53

54
    /** @param array<mixed> $stackItem */
55
    public function pushStackItem(array $stackItem): void
8,034✔
56
    {
57
        $this->stack[$this->count++] = $stackItem;
8,034✔
58
    }
59

60
    /** @return array<mixed> */
61
    public function getStackItem(string $type, mixed $value, ?string $reference = null): array
12,171✔
62
    {
63
        $stackItem = [
12,171✔
64
            'type' => $type,
12,171✔
65
            'value' => $value,
12,171✔
66
            'reference' => $reference,
12,171✔
67
        ];
12,171✔
68

69
        // will store the result under this alias
70
        $storeKey = $this->branchPruner->currentCondition();
12,171✔
71
        if (isset($storeKey) || $reference === 'NULL') {
12,171✔
72
            $stackItem['storeKey'] = $storeKey;
280✔
73
        }
74

75
        // will only run computation if the matching store key is true
76
        $onlyIf = $this->branchPruner->currentOnlyIf();
12,171✔
77
        if (isset($onlyIf) || $reference === 'NULL') {
12,171✔
78
            $stackItem['onlyIf'] = $onlyIf;
277✔
79
        }
80

81
        // will only run computation if the matching store key is false
82
        $onlyIfNot = $this->branchPruner->currentOnlyIfNot();
12,171✔
83
        if (isset($onlyIfNot) || $reference === 'NULL') {
12,171✔
84
            $stackItem['onlyIfNot'] = $onlyIfNot;
271✔
85
        }
86

87
        return $stackItem;
12,171✔
88
    }
89

90
    /**
91
     * Pop the last entry from the stack.
92
     *
93
     * @return null|array<mixed>
94
     */
95
    public function pop(): ?array
12,167✔
96
    {
97
        if ($this->count > 0) {
12,167✔
98
            return $this->stack[--$this->count];
12,155✔
99
        }
100

101
        return null;
11,943✔
102
    }
103

104
    /**
105
     * Return an entry from the stack without removing it.
106
     *
107
     * @return null|array<mixed>
108
     */
109
    public function last(int $n = 1): ?array
12,103✔
110
    {
111
        if ($this->count - $n < 0) {
12,103✔
112
            return null;
712✔
113
        }
114

115
        return $this->stack[$this->count - $n];
12,081✔
116
    }
117

118
    /**
119
     * Clear the stack.
120
     */
121
    public function clear(): void
×
122
    {
123
        $this->stack = [];
×
124
        $this->count = 0;
×
125
    }
126
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc