Skip to content

Commit

Permalink
Implement a table formed result metric
Browse files Browse the repository at this point in the history
  • Loading branch information
DZunke committed Apr 15, 2024
1 parent 3b4b144 commit 41761f7
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Result/Metric/Integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

namespace Panaly\Result\Metric;

final class Integer implements Value
final readonly class Integer implements Value
{
public function __construct(private readonly int $value)
public function __construct(public int $value)
{
}

Expand Down
26 changes: 26 additions & 0 deletions src/Result/Metric/Table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Panaly\Result\Metric;

use function array_merge;

final readonly class Table implements Value
{
/**
* @param list<string> $columns
* @param list<list<mixed>> $rows
*/
public function __construct(
public array $columns,
public array $rows,
) {
}

/** @return list<list<mixed>> */
public function compute(): array
{
return array_merge([$this->columns], $this->rows);
}
}
24 changes: 24 additions & 0 deletions tests/Result/Metric/TableResultTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Panaly\Test\Result\Metric;

use Panaly\Result\Metric\Table;
use PHPUnit\Framework\TestCase;

class TableResultTest extends TestCase
{
public function testTableResultLooksFine(): void
{
$metric = new Table(
['foo', 'bar'],
[['bar', 12], ['baz', 13]],
);

self::assertSame(
[['foo', 'bar'], ['bar', 12], ['baz', 13]],
$metric->compute(),
);
}
}

0 comments on commit 41761f7

Please sign in to comment.