Skip to content

Commit c8516eb

Browse files
committed
Move array response logic from FilterResponse to Filterer
1 parent d42a5ad commit c8516eb

3 files changed

Lines changed: 6 additions & 57 deletions

File tree

src/FilterResponse.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,4 @@ public function __set($name, $value)
5858

5959
throw new InvalidArgumentException("Property '{$name}' does not exist");
6060
}
61-
62-
/**
63-
* Converts the response to an array.
64-
*
65-
* @return array
66-
*/
67-
public function toArray() : array
68-
{
69-
$filteredValue = $this->success ? $this->filteredValue : null;
70-
71-
return [
72-
$this->success,
73-
$filteredValue,
74-
$this->errorMessage,
75-
$this->unknowns
76-
];
77-
}
7861
}

src/Filterer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,12 @@ private static function generateFilterResponse(
489489
}
490490

491491
if ($responseType === self::RESPONSE_TYPE_ARRAY) {
492-
return $filterResponse->toArray();
492+
return [
493+
$filterResponse->success,
494+
$filterResponse->success ? $filterResponse->filteredValue : null,
495+
$filterResponse->errorMessage,
496+
$filterResponse->unknowns
497+
];
493498
}
494499

495500
throw new InvalidArgumentException("'responseType' was not a recognized value");

tests/FilterResponseTest.php

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -105,43 +105,4 @@ public function settingInvalidPropertyThrowsAnException()
105105
$response = new FilterResponse([]);
106106
$response->foo = false;
107107
}
108-
109-
/**
110-
* @test
111-
* @covers ::toArray
112-
* @dataProvider provideToArray
113-
*
114-
* @param array $value The filtered value to pass to the response.
115-
* @param array $errors The errors to pass to the response.
116-
* @param array $unknowns The unknowns to pass to the response.
117-
* @param array $expected The expected array value.
118-
*/
119-
public function toArray(array $value, array $errors, array $unknowns, array $expected)
120-
{
121-
$response = new FilterResponse($value, $errors, $unknowns);
122-
$arrayResponse = $response->toArray();
123-
124-
$this->assertSame($expected, $arrayResponse);
125-
}
126-
127-
/**
128-
* @return array
129-
*/
130-
public function provideToArray() : array
131-
{
132-
return [
133-
'success' => [
134-
'input' => ['foo' => 'bar'],
135-
'errors' => [],
136-
'unknowns' => ['other' => 'unknown'],
137-
'expected' => [true, ['foo' => 'bar'], null, ['other' => 'unknown']],
138-
],
139-
'failure' => [
140-
'input' => ['foo' => 'bar'],
141-
'errors' => ['something bad happened', 'and something else too'],
142-
'unknowns' => ['other' => 'unknown'],
143-
'expected' => [false, null, "something bad happened\nand something else too", ['other' => 'unknown']],
144-
],
145-
];
146-
}
147108
}

0 commit comments

Comments
 (0)