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

aplus-framework / config / 13066327659

29 Jan 2025 11:27PM UTC coverage: 100.0%. Remained the same
13066327659

push

github

natanfelles
Add debug icon

311 of 311 relevant lines covered (100.0%)

3.01 hits per line

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

100.0
/src/Debug/ConfigCollector.php
1
<?php declare(strict_types=1);
2
/*
3
 * This file is part of Aplus Framework Config 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
 */
10
namespace Framework\Config\Debug;
11

12
use Framework\Config\Config;
13
use Framework\Debug\Collector;
14
use Framework\Debug\Debugger;
15
use Framework\Helpers\ArraySimple;
16

17
class ConfigCollector extends Collector
18
{
19
    protected Config $config;
20

21
    public function setConfig(Config $config) : static
22
    {
23
        $this->config = $config;
6✔
24
        return $this;
6✔
25
    }
26

27
    public function getActivities() : array
28
    {
29
        $activities = [];
1✔
30
        foreach ($this->getData() as $data) {
1✔
31
            $activities[] = [
1✔
32
                'collector' => $this->getName(),
1✔
33
                'class' => static::class,
1✔
34
                'description' => 'Load config file ' . \htmlentities($data['name']),
1✔
35
                'start' => $data['start'],
1✔
36
                'end' => $data['end'],
1✔
37
            ];
1✔
38
        }
39
        return $activities;
1✔
40
    }
41

42
    public function getContents() : string
43
    {
44
        if (!isset($this->config)) {
6✔
45
            \ob_start();
1✔
46
            echo '<p>This collector has not been added to a Config instance.</p>';
1✔
47
            return \ob_get_clean(); // @phpstan-ignore-line
1✔
48
        }
49
        $count = \count($this->getConfigs());
5✔
50
        \ob_start();
5✔
51
        $dir = $this->config->getDir();
5✔
52
        if ($dir !== null):
5✔
53
            ?>
54
            <p><strong>Config directory:</strong> <?= \htmlentities($dir) ?></p>
3✔
55
        <?php
56
        endif;
57
        ?>
58
        <p><?= $count ?> configuration<?= $count === 1 ? '' : 's' ?> have been set.</p>
5✔
59
        <?php
60
        if ($count === 0) {
5✔
61
            return \ob_get_clean(); // @phpstan-ignore-line
3✔
62
        }
63
        echo $this->getTable();
2✔
64
        return \ob_get_clean(); // @phpstan-ignore-line
2✔
65
    }
66

67
    protected function getTable() : string
68
    {
69
        \ob_start();
2✔
70
        ?>
71
        <table>
2✔
72
            <thead>
2✔
73
            <tr>
2✔
74
                <th>Name</th>
2✔
75
                <th>Instances</th>
2✔
76
                <th>Values</th>
2✔
77
                <th title="Milliseconds">Time to Load</th>
2✔
78
            </tr>
2✔
79
            </thead>
2✔
80
            <tbody>
2✔
81
            <?php foreach ($this->getConfigs() as $config): ?>
2✔
82
                <?php
2✔
83
                $count = \count($config['instances']);
2✔
84
                ?>
85
                <tr>
2✔
86
                    <td rowspan="<?= $count ?>"><?= $config['name'] ?></td>
2✔
87
                    <td><?= $config['instances'][0]['name'] ?></td>
2✔
88
                    <td rowspan="1">
89

90
                        <table>
91
                            <thead>
92
                            <tr>
93
                                <th>Key</th>
94
                                <th>Type</th>
95
                            </tr>
96
                            </thead>
97
                            <tbody>
98
                            <?php foreach ($config['instances'][0]['values'] as $key => $value): ?>
2✔
99
                                <tr>
2✔
100
                                    <td><?= \htmlentities((string) $key) ?></td>
2✔
101
                                    <td><?= \htmlentities((string) $value) ?></td>
2✔
102
                                </tr>
103
                            <?php endforeach ?>
104
                            </tbody>
2✔
105
                        </table>
2✔
106

107
                    </td>
2✔
108
                    <td rowspan="<?= \count($config['instances']) ?>">
2✔
109
                        <?php
110
                        $found = false;
2✔
111
                        foreach ($this->getData() as $value) {
2✔
112
                            if ($value['name'] === $config['name']) {
2✔
113
                                echo Debugger::roundSecondsToMilliseconds($value['end'] - $value['start']);
2✔
114
                                $found = true;
2✔
115
                                break;
2✔
116
                            }
117
                        }
118
                        if (!$found) {
2✔
119
                            echo 0;
1✔
120
                        }
121
                        ?>
122
                    </td>
2✔
123
                </tr>
2✔
124
                <?php for ($i = 1; $i < $count; $i++): ?>
2✔
125
                    <tr>
2✔
126
                        <td><?= $config['instances'][$i]['name'] ?></td>
2✔
127
                        <td>
128

129
                            <table>
130
                                <thead>
131
                                <tr>
132
                                    <th>Key</th>
133
                                    <th>Type</th>
134
                                </tr>
135
                                </thead>
136
                                <tbody>
137
                                <?php foreach ($config['instances'][$i]['values'] as $key => $value): ?>
2✔
138
                                    <tr>
2✔
139
                                        <td><?= \htmlentities((string) $key) ?></td>
2✔
140
                                        <td><?= \htmlentities((string) $value) ?></td>
2✔
141
                                    </tr>
142
                                <?php endforeach ?>
143
                                </tbody>
2✔
144
                            </table>
2✔
145

146
                        </td>
2✔
147
                    </tr>
2✔
148

149
                <?php endfor ?>
2✔
150

151
            <?php endforeach ?>
152
            </tbody>
2✔
153
        </table>
2✔
154
        <?php
2✔
155
        return \ob_get_clean(); // @phpstan-ignore-line
2✔
156
    }
157

158
    /**
159
     * @return array<mixed>
160
     */
161
    protected function getConfigs() : array
162
    {
163
        $result = [];
5✔
164
        foreach ($this->config->getAll() as $name => $instances) {
5✔
165
            $count = \count($result);
2✔
166
            $result[$count]['name'] = $name;
2✔
167
            $result[$count]['instances'] = [];
2✔
168
            $counter = 0;
2✔
169
            foreach ($instances as $instance => $values) {
2✔
170
                $result[$count]['instances'][$counter]['name'] = $instance;
2✔
171
                $result[$count]['instances'][$counter]['values'] = ArraySimple::convert($values);
2✔
172
                foreach ($result[$count]['instances'][$counter]['values'] as &$value) {
2✔
173
                    $value = \get_debug_type($value);
2✔
174
                }
175
                unset($value);
2✔
176
                $counter++;
2✔
177
            }
178
        }
179
        return $result;
5✔
180
    }
181
}
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

© 2025 Coveralls, Inc