Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d23b74e

Browse filesBrowse files
committed
bug #39735 [Serializer] Rename normalize param (VincentLanglet)
This PR was merged into the 4.4 branch. Discussion ---------- [Serializer] Rename normalize param | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | License | MIT The ProblemNormalizer is the only one Normalizer which - Use a different param name `$exception` instead of the one in the interface `$object`. - Doesn't type check the param. The first point lead to an unfixable error with Psalm when extending the ProblemNormalizer - If the variable is named `$object` it does not match with the parent - If the variable is named `$exception` it does not match with the interface Commits ------- 7e6eee2 Rename normalize param
2 parents d4c70a5 + 7e6eee2 commit d23b74e
Copy full SHA for d23b74e

File tree

1 file changed

+10
-5
lines changed
Filter options

1 file changed

+10
-5
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/ProblemNormalizer.php
+10-5Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.