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

aplus-framework / mvc / 16927505441

22 Jul 2025 07:08PM UTC coverage: 100.0%. Remained the same
16927505441

push

github

natanfelles
Add info about order in which commands are added to the console

1836 of 1836 relevant lines covered (100.0%)

10.61 hits per line

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

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

12
use Framework\Debug\Collector;
13
use Framework\Debug\Debugger;
14
use Framework\MVC\View;
15

16
/**
17
 * Class ViewsCollector.
18
 *
19
 * @package mvc
20
 */
21
class ViewsCollector extends Collector
22
{
23
    protected View $view;
24

25
    public function setView(View $view) : static
26
    {
27
        $this->view = $view;
12✔
28
        return $this;
12✔
29
    }
30

31
    public function getActivities() : array
32
    {
33
        $activities = [];
3✔
34
        foreach ($this->getSortedData() as $index => $data) {
3✔
35
            $activities[] = [
2✔
36
                'collector' => $this->getName(),
2✔
37
                'class' => static::class,
2✔
38
                'description' => 'Render view ' . ($index + 1),
2✔
39
                'start' => $data['start'],
2✔
40
                'end' => $data['end'],
2✔
41
            ];
2✔
42
        }
43
        return $activities;
3✔
44
    }
45

46
    public function getContents() : string
47
    {
48
        $baseDir = $this->view->getBaseDir();
5✔
49
        $extension = $this->view->getExtension();
5✔
50
        $layoutPrefix = $this->view->getLayoutPrefix();
5✔
51
        $includePrefix = $this->view->getIncludePrefix();
5✔
52
        \ob_start();
5✔
53
        if (isset($baseDir)): ?>
5✔
54
            <p><strong>Base Directory:</strong> <?= \htmlentities($baseDir) ?></p>
4✔
55
        <?php
56
        endif; ?>
57
        <p><strong>Extension:</strong> <?= \htmlentities($extension) ?></p>
5✔
58
        <?php
59
        if ($layoutPrefix !== ''): ?>
5✔
60
            <p><strong>Layout Prefix:</strong> <?= \htmlentities($layoutPrefix) ?>
1✔
61
            </p>
1✔
62
        <?php
1✔
63
        endif;
64
        if ($includePrefix !== ''): ?>
5✔
65
            <p><strong>Include Prefix:</strong> <?= \htmlentities($includePrefix) ?>
1✔
66
            </p>
1✔
67
        <?php
1✔
68
        endif ?>
69
        <h1>Rendered Views</h1>
5✔
70
        <?php
5✔
71
        echo $this->renderRenderedViews();
5✔
72
        return \ob_get_clean(); // @phpstan-ignore-line
5✔
73
    }
74

75
    protected function renderRenderedViews() : string
76
    {
77
        if (!$this->hasData()) {
5✔
78
            return '<p>No view has been rendered.</p>';
3✔
79
        }
80
        $data = $this->getSortedData();
2✔
81
        \ob_start();
2✔
82
        $count = \count($data); ?>
2✔
83
        <p>Total of <?= $count ?> rendered view file<?= $count > 1 ? 's' : '' ?>.</p>
2✔
84
        <table>
85
            <thead>
86
            <tr>
87
                <th>#</th>
88
                <th>File</th>
89
                <th>Type</th>
90
                <th title="Milliseconds">Time to Render</th>
91
            </tr>
92
            </thead>
93
            <tbody>
94
            <?php foreach ($data as $index => $item): ?>
2✔
95
                <tr title="<?= \htmlentities($item['filepath']) ?>">
2✔
96
                    <td><?= $index + 1 ?></td>
2✔
97
                    <td><?= \htmlentities($item['file']) ?></td>
2✔
98
                    <td><?= \htmlentities($item['type']) ?></td>
2✔
99
                    <td><?= Debugger::roundSecondsToMilliseconds($item['end'] - $item['start']) ?></td>
2✔
100
                </tr>
101
            <?php endforeach ?>
102
            </tbody>
2✔
103
        </table>
2✔
104
        <?php
2✔
105
        return \ob_get_clean(); // @phpstan-ignore-line
2✔
106
    }
107

108
    /**
109
     * @return array<mixed>
110
     */
111
    protected function getSortedData() : array
112
    {
113
        $data = $this->getData();
4✔
114
        \usort($data, static function ($d1, $d2) {
4✔
115
            return $d1['start'] <=> $d2['start'];
3✔
116
        });
4✔
117
        return $data;
4✔
118
    }
119
}
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