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

tempestphp / tempest-framework / 14024978163

23 Mar 2025 05:55PM UTC coverage: 79.391% (-0.05%) from 79.441%
14024978163

push

github

web-flow
feat(view): cache Blade and Twig templates in internal storage (#1061)

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

912 existing lines in 110 files now uncovered.

10478 of 13198 relevant lines covered (79.39%)

91.09 hits per line

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

66.67
/src/Tempest/Debug/src/Debug.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Tempest\Debug;
6

7
use Exception;
8
use Symfony\Component\VarDumper\Cloner\VarCloner;
9
use Symfony\Component\VarDumper\Dumper\CliDumper;
10
use Symfony\Component\VarDumper\VarDumper;
11
use Tempest\Container\GenericContainer;
12
use Tempest\EventBus\EventBus;
13
use Tempest\Highlight\Themes\TerminalStyle;
14
use Tempest\Log\LogConfig;
15

16
final readonly class Debug
17
{
18
    private function __construct(
5✔
19
        private ?LogConfig $logConfig = null,
20
        private ?EventBus $eventBus = null,
21
    ) {
22
    }
5✔
23

24
    public static function resolve(): self
5✔
25
    {
26
        try {
27
            $container = GenericContainer::instance();
5✔
28

29
            return new self(
5✔
30
                logConfig: $container?->get(LogConfig::class),
5✔
31
                eventBus: $container?->get(EventBus::class),
5✔
32
            );
5✔
UNCOV
33
        } catch (Exception) {
×
UNCOV
34
            return new self();
×
35
        }
36
    }
37

38
    public function log(array $items, bool $writeToLog = true, bool $writeToOut = true): void
5✔
39
    {
40
        $trace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
5✔
41
        $callPath = $trace[1]['file'] . ':' . $trace[1]['line'];
5✔
42

43
        if ($writeToLog) {
5✔
44
            $this->writeToLog($items, $callPath);
4✔
45
        }
46

47
        if ($writeToOut) {
5✔
UNCOV
48
            $this->writeToOut($items, $callPath);
×
49
        }
50

51
        $this->eventBus?->dispatch(new ItemsDebugged($items));
5✔
52
    }
53

54
    private function writeToLog(array $items, string $callPath): void
4✔
55
    {
56
        if ($this->logConfig === null) {
4✔
UNCOV
57
            return;
×
58
        }
59

60
        if (! $this->logConfig->debugLogPath) {
4✔
61
            return;
×
62
        }
63

64
        $directory = dirname($this->logConfig->debugLogPath);
4✔
65

66
        if (! is_dir($directory)) {
4✔
67
            mkdir(directory: $directory, recursive: true);
1✔
68
        }
69

70
        $handle = @fopen($this->logConfig->debugLogPath, 'a');
4✔
71

72
        if (! $handle) {
4✔
73
            return;
×
74
        }
75

76
        foreach ($items as $key => $item) {
4✔
77
            $output = $this->createDump($item) . $callPath;
4✔
78

79
            fwrite($handle, "{$key} " . $output . PHP_EOL);
4✔
80
        }
81

82
        fclose($handle);
4✔
83
    }
84

85
    private function writeToOut(array $items, string $callPath): void
×
86
    {
UNCOV
87
        foreach ($items as $key => $item) {
×
88
            if (defined('STDOUT')) {
×
UNCOV
89
                fwrite(STDOUT, TerminalStyle::BG_BLUE(" {$key} ") . ' ');
×
90

UNCOV
91
                $output = $this->createDump($item);
×
92

UNCOV
93
                fwrite(STDOUT, $output);
×
94

95
                fwrite(STDOUT, $callPath . PHP_EOL);
×
96
            } else {
UNCOV
97
                echo sprintf(
×
UNCOV
98
                        '<span style="
×
99
                    display:inline-block; 
100
                    color: #fff; 
101
                    font-family: %s;
102
                    padding: 2px 4px;
103
                    font-size: 0.8rem;
104
                    margin-bottom: -12px;
105
                    background: #0071BC;"
106
                >%s (%s)</span>',
×
107
                        'Source Code Pro, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, Liberation Mono, Courier New, monospace',
×
UNCOV
108
                        $key,
×
109
                        $callPath,
×
UNCOV
110
                    );
×
111

UNCOV
112
                VarDumper::dump($item);
×
113
            }
114
        }
115
    }
116

117
    private function createDump(mixed $input): string
4✔
118
    {
119
        $cloner = new VarCloner();
4✔
120

121
        $output = '';
4✔
122

123
        $dumper = new CliDumper(function ($line, $depth) use (&$output): void {
4✔
124
            if ($depth < 0) {
4✔
125
                return;
4✔
126
            }
127

128
            $output .= str_repeat(' ', $depth) . $line . "\n";
4✔
129
        });
4✔
130

131
        $dumper->setColors(true);
4✔
132

133
        $dumper->dump($cloner->cloneVar($input));
4✔
134

135
        return preg_replace(
4✔
136
            pattern: '/\e](.*)\e]8;;\e/',
4✔
137
            replacement: '',
4✔
138
            subject: $output,
4✔
139
        );
4✔
140
    }
141
}
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