-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a table formed result metric
- Loading branch information
Showing
3 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
); | ||
} | ||
} |