Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
| BreadcrumbTrait | |
100.00% |
9 / 9 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
| addBreadcrumb | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| initBreadcrumbs | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| getBreadcrumbs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace App\Helper; |
| 6 | |
| 7 | trait BreadcrumbTrait |
| 8 | { |
| 9 | /** |
| 10 | * @var array<string, string> |
| 11 | */ |
| 12 | private array $breadcrumbs = []; |
| 13 | |
| 14 | protected function addBreadcrumb(string $text, string $link = ''): self |
| 15 | { |
| 16 | $this->initBreadcrumbs(); |
| 17 | |
| 18 | $this->breadcrumbs[$text] = $link; |
| 19 | |
| 20 | return $this; |
| 21 | } |
| 22 | |
| 23 | private function initBreadcrumbs(): self |
| 24 | { |
| 25 | if (!$this->breadcrumbs) { |
| 26 | $this->breadcrumbs = [ |
| 27 | 'Home' => 'welcome', |
| 28 | ]; |
| 29 | } |
| 30 | |
| 31 | return $this; |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * @return array<string, string> |
| 36 | */ |
| 37 | protected function getBreadcrumbs(): array |
| 38 | { |
| 39 | return $this->initBreadcrumbs()->breadcrumbs; |
| 40 | } |
| 41 | } |