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

CPS-IT / handlebars / 15557342456

10 Jun 2025 10:41AM UTC coverage: 90.436% (-0.2%) from 90.638%
15557342456

push

github

web-flow
Merge pull request #441 from CPS-IT/fix/reverse-layouts

[BUGFIX] Avoid breaking references to original layout stack

2 of 4 new or added lines in 2 files covered. (50.0%)

851 of 941 relevant lines covered (90.44%)

5.6 hits per line

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

92.59
/Classes/Renderer/Component/Layout/HandlebarsLayoutStack.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "handlebars".
7
 *
8
 * It is free software; you can redistribute it and/or modify it under
9
 * the terms of the GNU General Public License, either version 2
10
 * of the License, or any later version.
11
 *
12
 * For the full copyright and license information, please read the
13
 * LICENSE.txt file that was distributed with this source code.
14
 *
15
 * The TYPO3 project - inspiring people to share!
16
 */
17

18
namespace Fr\Typo3Handlebars\Renderer\Component\Layout;
19

20
use IteratorAggregate;
21
use TYPO3\CMS\Core;
22

23
/**
24
 * HandlebarsLayoutStack
25
 *
26
 * @author Elias Häußler <e.haeussler@familie-redlich.de>
27
 * @license GPL-2.0-or-later
28
 * @implements IteratorAggregate<HandlebarsLayout>
29
 */
30
final class HandlebarsLayoutStack implements Core\SingletonInterface, \IteratorAggregate
31
{
32
    /**
33
     * @var HandlebarsLayout[]
34
     */
35
    private array $stack = [];
36

37
    public function push(HandlebarsLayout $layout): self
8✔
38
    {
39
        $this->stack[] = $layout;
8✔
40

41
        return $this;
8✔
42
    }
43

44
    public function pop(): ?HandlebarsLayout
2✔
45
    {
46
        return array_pop($this->stack);
2✔
47
    }
48

49
    public function first(): ?HandlebarsLayout
2✔
50
    {
51
        $first = reset($this->stack);
2✔
52

53
        if ($first === false) {
2✔
54
            return null;
1✔
55
        }
56

57
        return $first;
1✔
58
    }
59

60
    public function last(): ?HandlebarsLayout
3✔
61
    {
62
        $last = end($this->stack);
3✔
63

64
        if ($last === false) {
3✔
65
            return null;
1✔
66
        }
67

68
        return $last;
2✔
69
    }
70

71
    /**
72
     * @return HandlebarsLayout[]
73
     */
74
    public function all(): array
3✔
75
    {
76
        return $this->stack;
3✔
77
    }
78

79
    public function reverse(): self
1✔
80
    {
81
        $clone = clone $this;
1✔
82
        $clone->stack = array_reverse($this->stack);
1✔
83

84
        return $clone;
1✔
85
    }
86

87
    public function reset(): void
1✔
88
    {
89
        $this->stack = [];
1✔
90
    }
91

92
    /**
93
     * @phpstan-assert-if-false HandlebarsLayout $this->pop()
94
     * @phpstan-assert-if-false HandlebarsLayout $this->first()
95
     * @phpstan-assert-if-false HandlebarsLayout $this->last()
96
     */
97
    public function isEmpty(): bool
3✔
98
    {
99
        return $this->stack === [];
3✔
100
    }
101

102
    /**
103
     * @return \Generator<HandlebarsLayout>
104
     */
NEW
105
    public function getIterator(): \Generator
×
106
    {
NEW
107
        yield from $this->stack;
×
108
    }
109
}
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