Skip to content

Commit 6f28b2d

Browse files
author
Xavier Barbosa
committed
Reduced verbosity for renderers, using same helpers in all renderers for consistency.
1 parent 619115c commit 6f28b2d

File tree

8 files changed

+46
-72
lines changed

8 files changed

+46
-72
lines changed

src/Renderers/AbstractRenderer.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,9 @@
33
namespace Madewithlove\LaravelDebugConsole\Renderers;
44

55
use Madewithlove\LaravelDebugConsole\Renderers\Contracts\RendererInterface;
6-
use Symfony\Component\Console\Input\InputInterface;
7-
use Symfony\Component\Console\Output\OutputInterface;
86
use Symfony\Component\Console\Style\SymfonyStyle;
97

10-
abstract class AbstractRenderer implements RendererInterface
8+
abstract class AbstractRenderer extends SymfonyStyle implements RendererInterface
119
{
12-
/**
13-
* @var \Symfony\Component\Console\Output\OutputInterface
14-
*/
15-
protected $output;
1610

17-
/**
18-
* @param \Symfony\Component\Console\Input\InputInterface $input
19-
* @param \Symfony\Component\Console\Output\OutputInterface $output
20-
*/
21-
public function __construct(InputInterface $input, OutputInterface $output)
22-
{
23-
$this->output = new SymfonyStyle($input, $output);
24-
}
2511
}

src/Renderers/Exception.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class Exception extends AbstractRenderer
99
*/
1010
public function render(array $data)
1111
{
12-
$this->output->title('Exceptions');
12+
$this->title('Exceptions');
1313

1414
foreach (array_get($data, 'exceptions.exceptions', []) as $exception) {
15-
$this->output->block(array_get($exception, 'message'), array_get($exception, 'type'), 'fg=white;bg=red', ' ', true);
16-
$this->output->text(array_get($exception, 'file') . '#' . array_get($exception, 'line'));
17-
$this->output->newLine();
18-
$this->output->block(array_get($exception, 'surrounding_lines'), null, 'fg=yellow', ' ! ');
15+
$this->block(array_get($exception, 'message'), array_get($exception, 'type'), 'fg=white;bg=red', ' ', true);
16+
$this->text(array_get($exception, 'file') . '#' . array_get($exception, 'line'));
17+
$this->newLine();
18+
$this->block(array_get($exception, 'surrounding_lines'), null, 'fg=yellow', ' ! ');
1919
}
2020
}
2121
}

src/Renderers/General.php

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,29 @@
22

33
namespace Madewithlove\LaravelDebugConsole\Renderers;
44

5-
use Symfony\Component\Console\Helper\Table;
6-
75
class General extends AbstractRenderer
86
{
97
/**
108
* @param array $data
119
*/
1210
public function render(array $data)
1311
{
14-
$this->output->title('General');
12+
$this->title('General');
1513

16-
$table = new Table($this->output);
17-
$table->setHeaders([
14+
$this->table([
1815
'Request Time',
1916
'Route',
2017
'Memory Usage',
2118
'Request Duration',
2219
'PHP Version',
23-
])
24-
->setRows([
25-
[
26-
array_get($data, '__meta.datetime'),
27-
array_get($data, '__meta.method') . ' ' . array_get($data, '__meta.uri'),
28-
array_get($data, 'memory.peak_usage_str'),
29-
array_get($data, 'time.duration_str'),
30-
array_get($data, 'php.version')
31-
],
32-
])
33-
->render();
20+
], [
21+
[
22+
array_get($data, '__meta.datetime'),
23+
array_get($data, '__meta.method') . ' ' . array_get($data, '__meta.uri'),
24+
array_get($data, 'memory.peak_usage_str'),
25+
array_get($data, 'time.duration_str'),
26+
array_get($data, 'php.version')
27+
],
28+
]);
3429
}
3530
}

src/Renderers/Message.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,22 @@ class Message extends AbstractRenderer
99
*/
1010
public function render(array $data)
1111
{
12-
$this->output->title('Messages');
12+
$this->title('Messages');
1313

1414
array_map(function ($message) {
1515
$label = array_get($message, 'label');
1616
$message = array_get($message, 'message', '');
1717

1818
switch ($label) {
1919
case 'error':
20-
$this->output->error($message);
20+
$this->error($message);
2121
break;
2222
case 'warning':
23-
$this->output->warning($message);
23+
$this->warning($message);
2424
break;
2525
case 'info':
2626
default;
27-
$this->output->block($message, $label, 'fg=black;bg=blue', ' ', true);
27+
$this->block($message, $label, 'fg=black;bg=blue', ' ', true);
2828
}
2929

3030
}, array_get($data, 'messages.messages', []));

src/Renderers/Query.php

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Madewithlove\LaravelDebugConsole\Renderers;
44

5-
use Symfony\Component\Console\Helper\Table;
6-
75
class Query extends AbstractRenderer
86
{
97
/**
@@ -18,27 +16,22 @@ public function render(array $data)
1816
array_get($data, 'queries.accumulated_duration_str')
1917
);
2018

21-
$this->output->title('Queries');
22-
$this->output->writeln($message);
19+
$this->title('Queries');
20+
$this->writeln($message);
21+
$this->newLine();
2322

24-
$table = new Table($this->output);
25-
$table
26-
->setHeaders([
27-
'SQL',
28-
'Duration',
29-
'Statement ID',
30-
'connection',
31-
])
32-
->setRows(
33-
$queries->map(function ($query, $index) {
34-
return [
35-
array_get($query, 'sql'),
36-
array_get($query, 'duration_str'),
37-
array_get($query, 'stmt_id'),
38-
str_limit(array_get($query, 'connection'), 20),
39-
];
40-
})
41-
->all())
42-
->render();
23+
$this->table([
24+
'SQL',
25+
'Duration',
26+
'Statement ID',
27+
'connection',
28+
], $queries->map(function ($query, $index) {
29+
return [
30+
array_get($query, 'sql'),
31+
array_get($query, 'duration_str'),
32+
array_get($query, 'stmt_id'),
33+
str_limit(array_get($query, 'connection'), 20),
34+
];
35+
})->all());
4336
}
4437
}

src/Renderers/Request.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class Request extends AbstractRenderer
99
*/
1010
public function render(array $data)
1111
{
12-
$this->output->title('Route');
12+
$this->title('Route');
1313

1414
$request = array_get($data, 'request', []);
1515

16-
$this->output->table([], array_map(function ($value, $index) {
16+
$this->table([], array_map(function ($value, $index) {
1717
if (is_array($value)) {
1818
$value = implode(', ', $value);
1919
}

src/Renderers/Route.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ class Route extends AbstractRenderer
99
*/
1010
public function render(array $data)
1111
{
12-
$this->output->title('Route');
12+
$this->title('Route');
1313

1414
$route = array_get($data, 'route', []);
1515

16-
$this->output->table([], array_map(function ($value, $index) {
16+
$this->table([], array_map(function ($value, $index) {
1717
if (is_array($value)) {
1818
$value = implode(', ', $value);
1919
}

src/Renderers/Timeline.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ class Timeline extends AbstractRenderer
99
*/
1010
public function render(array $data)
1111
{
12-
$this->output->title('Timeline');
12+
$this->title('Timeline');
1313

1414
$duration = array_get($data, 'time.duration', 0) * 1000;
1515

1616
foreach (array_get($data, 'time.measures', []) as $measure) {
17-
$this->output->comment(sprintf('%s (%s)', array_get($measure, 'label'), array_get($measure, 'duration_str')));
17+
$this->comment(sprintf('%s (%s)', array_get($measure, 'label'), array_get($measure, 'duration_str')));
1818

19-
$this->output->progressStart($duration);
20-
$this->output->progressAdvance(array_get($measure, 'duration') * 1000);
19+
$this->progressStart($duration);
20+
$this->progressAdvance(array_get($measure, 'duration') * 1000);
2121

22-
$this->output->newLine(2);
22+
$this->newLine(2);
2323
}
2424
}
2525
}

0 commit comments

Comments
 (0)