Skip to content

Commit c17eb99

Browse files
committed
Simplify maintenance and remove useless dependencies
1 parent 461685b commit c17eb99

12 files changed

Lines changed: 167 additions & 626 deletions

src/AggregationType.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ enum AggregationType: string
1313
case Sum = 'sum';
1414
case Range = 'range';
1515
case Variance = 'variance';
16-
case StdDev = 'stdDev';
16+
case StdDev = 'std_dev';
1717
case CoefVar = 'coef_var';
1818
}

src/Console/ConsoleFormatter.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace Bakame\Stackwatch\Console;
66

7-
use Bakame\Stackwatch\Exporter\Translator;
87
use Bakame\Stackwatch\Exporter\ViewExporter;
98
use Bakame\Stackwatch\Report;
109
use Throwable;
@@ -14,7 +13,6 @@ final class ConsoleFormatter implements Formatter
1413
public function __construct(
1514
public readonly ViewExporter $exporter,
1615
public readonly Feature $dryRun = Feature::Disabled,
17-
public readonly Translator $translator = new Translator(),
1816
) {
1917
}
2018

src/Console/ConsoleHandler.php

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
namespace Bakame\Stackwatch\Console;
66

77
use Bakame\Stackwatch\Environment;
8-
use Bakame\Stackwatch\Exporter\AnsiStyle;
9-
use Bakame\Stackwatch\Exporter\LeaderPrinter;
10-
use Bakame\Stackwatch\Exporter\Translator;
118
use Bakame\Stackwatch\Version;
129
use Bakame\Stackwatch\Warning;
1310
use Psr\Log\LoggerInterface;
@@ -23,8 +20,6 @@ public function __construct(
2320
private readonly OutputInterface $stdout,
2421
private readonly LoggerInterface $logger,
2522
private readonly Environment $environment,
26-
private readonly LeaderPrinter $leaderPrinter = new LeaderPrinter(),
27-
private readonly Translator $translator = new Translator(),
2823
) {
2924
}
3025

@@ -38,28 +33,18 @@ public function handle(Input $input): void
3833
$output = new StreamOutput($handler);
3934
}
4035

41-
$profiler = PathProfiler::forConsole($input, $output, $this->logger, $this->translator);
36+
$pathProfiler = PathProfiler::forConsole($input, $output, $this->logger);
4237
$output->writeln(Version::toConsoleString());
43-
4438
if ($input->infoSection->isVisible()) {
45-
$formatter = $profiler->formatter;
39+
$formatter = $pathProfiler->formatter;
4640
if ($formatter instanceof ConsoleFormatter) {
47-
$data = $this->translator->translateArrayKeys($this->environment->toHuman());
48-
$formatter->exporter->output->writeln(
49-
$this
50-
->leaderPrinter
51-
->setPairs($data)
52-
->setStylesKey(AnsiStyle::BrightGreen)
53-
->setStylesValue(AnsiStyle::BrightCyan)
54-
->renderCli()
55-
);
41+
$formatter->exporter->exportEnvironment($this->environment);
5642
$formatter->exporter->output->writeln('');
5743
}
5844
} else {
5945
$output->writeln('<fg=green>Runtime:</> PHP '.$this->environment->phpVersion.' <fg=green>OS:</> '.$this->environment->os.' <fg=green>Memory Limit:</> '.$this->environment->rawMemoryLimit);
6046
}
61-
6247
$output->writeln('');
63-
$profiler->handle($input->path);
48+
$pathProfiler->handle($input->path);
6449
}
6550
}

src/Console/PathProfiler.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
use ArrayIterator;
88
use Bakame\Stackwatch\Exporter\JsonExporter;
9-
use Bakame\Stackwatch\Exporter\Translator;
109
use Bakame\Stackwatch\Exporter\ViewExporter;
1110
use Bakame\Stackwatch\Profile;
1211
use Bakame\Stackwatch\UnableToProfile;
@@ -50,11 +49,10 @@ public static function forConsole(
5049
Input $input,
5150
OutputInterface $output = new ConsoleOutput(),
5251
LoggerInterface $logger = new NullLogger(),
53-
Translator $translator = new Translator(),
5452
): self {
5553
return new self(
5654
new UnitOfWorkGenerator(new PathInspector(Profile::class), $logger),
57-
new ConsoleFormatter(new ViewExporter($output), $input->dryRun, $translator),
55+
new ConsoleFormatter(new ViewExporter($output), $input->dryRun),
5856
$input,
5957
$logger,
6058
);

src/Console/Stackwatch.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
namespace Bakame\Stackwatch\Console;
66

77
use Bakame\Stackwatch\Environment;
8-
use Bakame\Stackwatch\Exporter\LeaderPrinter;
9-
use Bakame\Stackwatch\Exporter\Translator;
108
use Bakame\Stackwatch\Version;
119
use Bakame\Stackwatch\Warning;
1210
use Psr\Log\LoggerInterface;
@@ -72,8 +70,6 @@ public function __construct(
7270
private readonly OutputInterface $stderr,
7371
private readonly LoggerInterface $logger,
7472
private readonly Environment $environment,
75-
private readonly LeaderPrinter $leaderPrinter = new LeaderPrinter(),
76-
private readonly Translator $translator = new Translator(),
7773
) {
7874
}
7975

@@ -120,7 +116,7 @@ public function execute(Input $input): int
120116

121117
try {
122118
(match ($input->format) {
123-
Input::TEXT_FORMAT => new ConsoleHandler($this->stdout, $this->logger, $this->environment, $this->leaderPrinter, $this->translator),
119+
Input::TEXT_FORMAT => new ConsoleHandler($this->stdout, $this->logger, $this->environment),
124120
Input::JSON_FORMAT => new JsonHandler($this->logger, $this->environment),
125121
default => throw new RuntimeException('Unknown output format: '.$input->format),
126122
})->handle($input);

src/MetricType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ enum MetricType: string
1414
case PeakMemoryUsageGrowth = 'peak_memory_usage_growth';
1515
case RealMemoryUsage = 'real_memory_usage';
1616
case RealMemoryUsageGrowth = 'real_memory_usage_growth';
17-
case RealPeaKMemoryUsage = 'real_peak_memory_usage';
18-
case RealPeakMemoryUsageGrowth = 'real_peak_memory_usage_glow';
17+
case RealPeakMemoryUsage = 'real_peak_memory_usage';
18+
case RealPeakMemoryUsageGrowth = 'real_peak_memory_usage_growth';
1919

2020
public function isGrowth(): bool
2121
{

src/Metrics.php

Lines changed: 40 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -107,32 +107,32 @@ public static function fromSnapshots(Snapshot $start, Snapshot $end): self
107107
public static function fromArray(array $data): self
108108
{
109109
$missingKeys = array_diff_key([
110-
'cpu_time' => 1,
111-
'execution_time' => 1,
112-
'memory_usage' => 1,
113-
'memory_usage_growth' => 1,
114-
'real_memory_usage' => 1,
115-
'real_memory_usage_growth' => 1,
116-
'peak_memory_usage' => 1,
117-
'peak_memory_usage_growth' => 1,
118-
'real_peak_memory_usage' => 1,
119-
'real_peak_memory_usage_growth' => 1,
110+
MetricType::CpuTime->value => 1,
111+
MetricType::ExecutionTime->value => 1,
112+
MetricType::MemoryUsage->value => 1,
113+
MetricType::MemoryUsageGrowth->value => 1,
114+
MetricType::RealMemoryUsage->value => 1,
115+
MetricType::RealMemoryUsageGrowth->value => 1,
116+
MetricType::PeakMemoryUsage->value => 1,
117+
MetricType::PeakMemoryUsageGrowth->value => 1,
118+
MetricType::RealPeakMemoryUsage->value => 1,
119+
MetricType::RealPeakMemoryUsageGrowth->value => 1,
120120
], $data);
121121

122122
[] === $missingKeys || throw new InvalidArgument('The payload is missing the following keys: '.implode(', ', array_keys($missingKeys)));
123123

124124
try {
125125
return new self(
126-
$data['cpu_time'],
127-
$data['execution_time'],
128-
$data['memory_usage'],
129-
$data['memory_usage_growth'],
130-
$data['real_memory_usage'],
131-
$data['real_memory_usage_growth'],
132-
$data['peak_memory_usage'],
133-
$data['peak_memory_usage_growth'],
134-
$data['real_peak_memory_usage'],
135-
$data['real_peak_memory_usage_growth'],
126+
cpuTime: $data[MetricType::CpuTime->value],
127+
executionTime: $data[MetricType::ExecutionTime->value],
128+
memoryUsage: $data[MetricType::MemoryUsage->value],
129+
memoryUsageGrowth: $data[MetricType::MemoryUsageGrowth->value],
130+
peakMemoryUsage: $data[MetricType::PeakMemoryUsage->value],
131+
peakMemoryUsageGrowth: $data[MetricType::PeakMemoryUsageGrowth->value],
132+
realMemoryUsage: $data[MetricType::RealMemoryUsage->value],
133+
realMemoryUsageGrowth: $data[MetricType::RealMemoryUsageGrowth->value],
134+
realPeakMemoryUsage: $data[MetricType::RealPeakMemoryUsage->value],
135+
realPeakMemoryUsageGrowth: $data[MetricType::RealPeakMemoryUsageGrowth->value],
136136
);
137137
} catch (Throwable $exception) {
138138
throw new InvalidArgument('Unable to create a metrics from the payload', previous: $exception);
@@ -153,16 +153,16 @@ public function jsonSerialize(): array
153153
public function toArray(): array
154154
{
155155
return [
156-
'cpu_time' => $this->cpuTime,
157-
'execution_time' => $this->executionTime,
158-
'memory_usage' => $this->memoryUsage,
159-
'memory_usage_growth' => $this->memoryUsageGrowth,
160-
'real_memory_usage' => $this->realMemoryUsage,
161-
'real_memory_usage_growth' => $this->realMemoryUsageGrowth,
162-
'peak_memory_usage' => $this->peakMemoryUsage,
163-
'peak_memory_usage_growth' => $this->peakMemoryUsageGrowth,
164-
'real_peak_memory_usage' => $this->realPeakMemoryUsage,
165-
'real_peak_memory_usage_growth' => $this->realPeakMemoryUsageGrowth,
156+
MetricType::CpuTime->value => $this->cpuTime,
157+
MetricType::ExecutionTime->value => $this->executionTime,
158+
MetricType::MemoryUsage->value => $this->memoryUsage,
159+
MetricType::MemoryUsageGrowth->value => $this->memoryUsageGrowth,
160+
MetricType::RealMemoryUsage->value => $this->realMemoryUsage,
161+
MetricType::RealMemoryUsageGrowth->value => $this->realMemoryUsageGrowth,
162+
MetricType::PeakMemoryUsage->value => $this->peakMemoryUsage,
163+
MetricType::PeakMemoryUsageGrowth->value => $this->peakMemoryUsageGrowth,
164+
MetricType::RealPeakMemoryUsage->value => $this->realPeakMemoryUsage,
165+
MetricType::RealPeakMemoryUsageGrowth->value => $this->realPeakMemoryUsageGrowth,
166166
];
167167
}
168168

@@ -172,16 +172,16 @@ public function toArray(): array
172172
public function toHuman(): array
173173
{
174174
return [
175-
'cpu_time' => DurationUnit::format($this->cpuTime, 3),
176-
'execution_time' => DurationUnit::format($this->executionTime, 3),
177-
'memory_usage' => MemoryUnit::format($this->memoryUsage, 1),
178-
'memory_usage_growth' => MemoryUnit::format($this->memoryUsageGrowth, 1),
179-
'real_memory_usage' => MemoryUnit::format($this->realMemoryUsage, 1),
180-
'real_memory_usage_growth' => MemoryUnit::format($this->realMemoryUsageGrowth, 1),
181-
'peak_memory_usage' => MemoryUnit::format($this->peakMemoryUsage, 1),
182-
'peak_memory_usage_growth' => MemoryUnit::format($this->peakMemoryUsageGrowth, 1),
183-
'real_peak_memory_usage' => MemoryUnit::format($this->realPeakMemoryUsage, 1),
184-
'real_peak_memory_usage_growth' => MemoryUnit::format($this->realPeakMemoryUsageGrowth, 1),
175+
MetricType::CpuTime->value => DurationUnit::format($this->cpuTime, 3),
176+
MetricType::ExecutionTime->value => DurationUnit::format($this->executionTime, 3),
177+
MetricType::MemoryUsage->value => MemoryUnit::format($this->memoryUsage, 1),
178+
MetricType::MemoryUsageGrowth->value => MemoryUnit::format($this->memoryUsageGrowth, 1),
179+
MetricType::RealMemoryUsage->value => MemoryUnit::format($this->realMemoryUsage, 1),
180+
MetricType::RealMemoryUsageGrowth->value => MemoryUnit::format($this->realMemoryUsageGrowth, 1),
181+
MetricType::PeakMemoryUsage->value => MemoryUnit::format($this->peakMemoryUsage, 1),
182+
MetricType::PeakMemoryUsageGrowth->value => MemoryUnit::format($this->peakMemoryUsageGrowth, 1),
183+
MetricType::RealPeakMemoryUsage->value => MemoryUnit::format($this->realPeakMemoryUsage, 1),
184+
MetricType::RealPeakMemoryUsageGrowth->value => MemoryUnit::format($this->realPeakMemoryUsageGrowth, 1),
185185
];
186186
}
187187

0 commit comments

Comments
 (0)