Skip to content

Commit

Permalink
tmp remove batchFirst
Browse files Browse the repository at this point in the history
  • Loading branch information
grongor committed Jul 6, 2020
1 parent ea57eef commit 6266703
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 38 deletions.
29 changes: 5 additions & 24 deletions src/Helpers/ValueGetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,19 @@
final class ValueGetter
{
/**
* @param array<string, mixed> $response
* @param array<int|string, mixed> $response
*
* @return mixed
*
* @psalm-template T
* @psalm-param array<string, T> $response
* @psalm-param array<int|string, T> $response
* @psalm-return T
*/
public static function first(array $response)
{
return self::batchFirst([$response])[0];
}

/**
* @param list<array<string, mixed>> $responses
*
* @return list<mixed>
*
* @psalm-template T
* @psalm-param list<array<string, T>> $responses
* @psalm-return list<T>
*/
public static function batchFirst(array $responses) : array
{
$result = [];
foreach ($responses as $response) {
$first = array_shift($response);
if ($first === null) {
throw GeneralException::new('Expected non-empty array');
}

$result[] = $first;
$result = array_shift($response);
if ($result === null) {
throw GeneralException::new('Expected non-empty array');
}

return $result;
Expand Down
14 changes: 0 additions & 14 deletions tests/Helpers/ValueGetterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,6 @@ public function testFirstWithUnexpectedData() : void
ValueGetter::first([]);
}

public function testBatchFirst() : void
{
$responses = [['.1.2.3.1' => 'a'], ['.3.4.5.1' => 'b']];

self::assertSame(['a', 'b'], ValueGetter::batchFirst($responses));
}

public function testBatchFirstWithUnexpectedData() : void
{
$this->expectExceptionObject(GeneralException::new('Expected non-empty array'));

ValueGetter::batchFirst([[]]);
}

public function testFirstFromSameTree() : void
{
$snmpClient = $this->createMock(SnmpClient::class);
Expand Down

0 comments on commit 6266703

Please sign in to comment.