Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7e6eee2

Browse files
Rename normalize param
1 parent 9b719ab commit 7e6eee2

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Serializer\Normalizer;
1313

1414
use Symfony\Component\ErrorHandler\Exception\FlattenException;
15+
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
1516

1617
/**
1718
* Normalizes errors according to the API Problem spec (RFC 7807).
@@ -40,20 +41,24 @@ public function __construct(bool $debug = false, array $defaultContext = [])
4041
*
4142
* @return array
4243
*/
43-
public function normalize($exception, $format = null, array $context = [])
44+
public function normalize($object, $format = null, array $context = [])
4445
{
46+
if (!$object instanceof FlattenException) {
47+
throw new InvalidArgumentException(sprintf('The object must implement "%s".', FlattenException::class));
48+
}
49+
4550
$context += $this->defaultContext;
4651
$debug = $this->debug && ($context['debug'] ?? true);
4752

4853
$data = [
4954
'type' => $context['type'],
5055
'title' => $context['title'],
51-
'status' => $context['status'] ?? $exception->getStatusCode(),
52-
'detail' => $debug ? $exception->getMessage() : $exception->getStatusText(),
56+
'status' => $context['status'] ?? $object->getStatusCode(),
57+
'detail' => $debug ? $object->getMessage() : $object->getStatusText(),
5358
];
5459
if ($debug) {
55-
$data['class'] = $exception->getClass();
56-
$data['trace'] = $exception->getTrace();
60+
$data['class'] = $object->getClass();
61+
$data['trace'] = $object->getTrace();
5762
}
5863

5964
return $data;

0 commit comments

Comments
 (0)