Skip to content

Commit

Permalink
chore(psalm): fix psalm issues
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Jun 1, 2024
1 parent 5939b7d commit 3e7ce4c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 20 deletions.
10 changes: 5 additions & 5 deletions src/Service/FilesObserver/Converter/Cost.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@ final class Cost implements \JsonSerializable

public float $p_wt = 0;

/** @var int<0, max> */
/** @var int<min, max> */
public int $d_cpu = 0;

/** @var int<0, max> */
/** @var int<min, max> */
public int $d_ct = 0;

/** @var int<0, max> */
/** @var int<min, max> */
public int $d_mu = 0;

/** @var int<0, max> */
/** @var int<min, max> */
public int $d_pmu = 0;

/** @var int<0, max> */
/** @var int<min, max> */
public int $d_wt = 0;

/**
Expand Down
4 changes: 4 additions & 0 deletions src/Service/FilesObserver/Converter/Edge.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
*/
final class Edge implements \JsonSerializable
{
/**
* @param non-empty-string|null $caller
* @param non-empty-string $callee
*/
public function __construct(

Check warning on line 16 in src/Service/FilesObserver/Converter/Edge.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/Edge.php#L16

Added line #L16 was not covered by tests
public readonly ?string $caller,
public readonly string $callee,
Expand Down
36 changes: 21 additions & 15 deletions src/Service/FilesObserver/Converter/XHProf.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
* pmu: int<0, max>
* }>
*
* @psalm-import-type Metadata from \Buggregator\Trap\Proto\Frame\Profiler\Payload
* @psalm-import-type Calls from \Buggregator\Trap\Proto\Frame\Profiler\Payload
*
* @internal
*/
final class XHProf implements FileFilterInterface
Expand All @@ -33,16 +36,19 @@ public function validate(FileInfo $file): bool
return $file->getExtension() === 'xhprof';

Check warning on line 36 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L36

Added line #L36 was not covered by tests
}

/**
* @return \Traversable<int, ProfilerFrame>
*/
public function convert(FileInfo $file): \Traversable

Check warning on line 42 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L42

Added line #L42 was not covered by tests
{
try {
/** @var Metadata $metadata */
$metadata = [
'date' => $file->mtime,
'hostname' => \explode('.', $file->getName(), 2)[0],
'filename' => $file->getName(),
];

Check warning on line 50 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L46-L50

Added lines #L46 - L50 were not covered by tests

/** @psalm-suppress MixedArgumentTypeCoercion */
yield new ProfilerFrame(
ProfilerFrame\Payload::new(
type: ProfilerFrame\Type::XHProf,
Expand All @@ -62,10 +68,10 @@ public function convert(FileInfo $file): \Traversable

/**
* @param RawData $data
* @return Calls
*/
private function dataToPayload(array $data): array

Check warning on line 73 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L73

Added line #L73 was not covered by tests
{
/** @var array<string, array<string, int>> $data */
$peaks = [
'cpu' => 0,
'ct' => 0,
Expand All @@ -77,15 +83,13 @@ private function dataToPayload(array $data): array
/** @var Tree<Edge> $tree */
$tree = new Tree();

Check warning on line 84 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L84

Added line #L84 was not covered by tests

// \uasort($data, static function (array $a, array $b) {
// return $b['wt'] <=> $a['wt'];
// });

foreach ($data as $key => $value) {
[$caller, $callee] = \explode('==>', $key, 2) + [1 => null];
if ($callee === null) {
[$caller, $callee] = \explode('==>', $key, 2) + [1 => ''];
if ($callee === '') {
[$caller, $callee] = [null, $caller];

Check warning on line 89 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L86-L89

Added lines #L86 - L89 were not covered by tests
}
$caller === '' and $caller = null;

Check warning on line 91 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L91

Added line #L91 was not covered by tests
\assert($callee !== '');

$edge = new Edge(
caller: $caller,
Expand All @@ -102,8 +106,10 @@ private function dataToPayload(array $data): array
$tree->addItem($edge, $edge->callee, $edge->caller);

Check warning on line 106 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L106

Added line #L106 was not covered by tests
}

// Calc percentages and delta
/** @var Branch<Edge> $branch */
/**
* Calc percentages and delta
* @var Branch<Edge> $branch Needed for IDE
*/
foreach ($tree->getIterator() as $branch) {
$cost = $branch->item->cost;
$cost->p_cpu = $peaks['cpu'] > 0 ? \round($cost->cpu / $peaks['cpu'] * 100, 3) : 0;
Expand All @@ -114,11 +120,11 @@ private function dataToPayload(array $data): array

if ($branch->parent !== null) {
$parentCost = $branch->parent->item->cost;
$cost->d_cpu = $cost->cpu - ($parentCost->cpu);
$cost->d_ct = $cost->ct - ($parentCost->ct);
$cost->d_mu = $cost->mu - ($parentCost->mu);
$cost->d_pmu = $cost->pmu - ($parentCost->pmu);
$cost->d_wt = $cost->wt - ($parentCost->wt);
$cost->d_cpu = $cost->cpu - $parentCost->cpu;
$cost->d_ct = $cost->ct - $parentCost->ct;
$cost->d_mu = $cost->mu - $parentCost->mu;
$cost->d_pmu = $cost->pmu - $parentCost->pmu;
$cost->d_wt = $cost->wt - $parentCost->wt;

Check warning on line 127 in src/Service/FilesObserver/Converter/XHProf.php

View check run for this annotation

Codecov / codecov/patch

src/Service/FilesObserver/Converter/XHProf.php#L121-L127

Added lines #L121 - L127 were not covered by tests
}
}

Expand Down

0 comments on commit 3e7ce4c

Please sign in to comment.