Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
Collection
100.00% covered (success)
100.00%
21 / 21
100.00% covered (success)
100.00%
9 / 9
12
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSafeName
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addCollector
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getCollectors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 addAction
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getActions
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 hasCollectors
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getActivities
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
4
1<?php declare(strict_types=1);
2/*
3 * This file is part of Aplus Framework Debug Library.
4 *
5 * (c) Natan Felles <natanfelles@gmail.com>
6 *
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
9 */
10namespace Framework\Debug;
11
12/**
13 * Class Collection.
14 *
15 * @package debug
16 */
17class Collection
18{
19    protected string $name;
20    /**
21     * @var array<Collector>
22     */
23    protected array $collectors = [];
24    /**
25     * @var array<string>
26     */
27    protected array $actions = [];
28
29    public function __construct(string $name)
30    {
31        $this->name = $name;
32    }
33
34    public function getName() : string
35    {
36        return $this->name;
37    }
38
39    public function getSafeName() : string
40    {
41        return Debugger::makeSafeName($this->getName());
42    }
43
44    public function addCollector(Collector $collector) : static
45    {
46        $this->collectors[] = $collector;
47        return $this;
48    }
49
50    /**
51     * @return array<Collector>
52     */
53    public function getCollectors() : array
54    {
55        return $this->collectors;
56    }
57
58    public function addAction(string $action) : static
59    {
60        $this->actions[] = $action;
61        return $this;
62    }
63
64    /**
65     * @return array<string>
66     */
67    public function getActions() : array
68    {
69        return $this->actions;
70    }
71
72    public function hasCollectors() : bool
73    {
74        return ! empty($this->collectors);
75    }
76
77    /**
78     * @return array<int,array<int,array<string,mixed>>>
79     */
80    public function getActivities() : array
81    {
82        $result = [];
83        foreach ($this->getCollectors() as $collector) {
84            $activities = $collector->getActivities();
85            if ($activities) {
86                foreach ($activities as &$activity) {
87                    $activity = \array_merge([
88                        'collection' => $this->getName(),
89                    ], $activity);
90                }
91                unset($activity);
92                $result[] = $activities;
93            }
94        }
95        return $result;
96    }
97}