8000 adjust to feedback · symfony/symfony@de5a875 · GitHub
[go: up one dir, main page]

Skip to content

Commit de5a875

Browse files
committed
adjust to feedback
1 parent 2a74256 commit de5a875

File tree

2 files changed

+12
-16
lines changed

2 files changed

+12
-16
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,12 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
101101

102102
if (isset($this->defaultContext[self::CALLBACKS])) {
10000 103103
if (!\is_array($this->defaultContext[self::CALLBACKS])) {
104-
throw new InvalidArgumentException('The callbacks default context must be a array of callable.');
104+
throw new InvalidArgumentException(sprintf('The "%s" default context option must be a array of callables.', self::CALLBACKS));
105105
}
106106

107107
foreach ($this->defaultContext[self::CALLBACKS] as $attribute => $callback) {
108108
if (!\is_callable($callback)) {
109-
throw new InvalidArgumentException(sprintf('The callback given in the default context for attribute "%s" is not callable.', $attribute));
109+
throw new InvalidArgumentException(sprintf('Invalid callback found for attribute "%s" in the "%s" default context option.', $attribute, self::CALLBACKS));
110110
}
111111
}
112112
}

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function __construct(ClassMetadataFactoryInterface $classMetadataFactory
6161
parent::__construct($classMetadataFactory, $nameConverter, $defaultContext);
6262

6363
if (isset($this->defaultContext[self::MAX_DEPTH_HANDLER]) && !\is_callable($this->defaultContext[self::MAX_DEPTH_HANDLER])) {
64-
throw new InvalidArgumentException(sprintf('The %s given in the default context is not callable.', self::MAX_DEPTH_HANDLER));
64+
throw new InvalidArgumentException(sprintf('The "%s" given in the default context is not callable.', self::MAX_DEPTH_HANDLER));
6565
}
6666

6767
$this->defaultContext[self::EXCLUDE_FROM_CACHE_KEY] = [self::CIRCULAR_REFERENCE_LIMIT_COUNTERS];
@@ -91,22 +91,15 @@ public function normalize($object, $format = null, array $context = [])
9191
if (!isset($context['cache_key'])) {
9292
$context['cache_key'] = $this->getCacheKey($format, $context);
9393
}
94-
if (\array_key_exists(self::CALLBACKS, $context)) {
95-
foreach ($context[self::CALLBACKS] as $attribute => $callback) {
96-
if (!\is_callable($callback)) {
97-
throw new InvalidArgumentException(sprintf('The callback given in the context for attribute "%s" is not callable.', $attribute));
98-
}
99-
}
100-
}
10194

10295
if (isset($context[self::CALLBACKS])) {
10396
if (!\is_array($context[self::CALLBACKS])) {
104-
throw new InvalidArgumentException('The callbacks context must be a array of callable.');
97+
throw new InvalidArgumentException(sprintf('The "%s" context option must be a array of callables.', self::CALLBACKS));
10598
}
10699

107100
foreach ($context[self::CALLBACKS] as $attribute => $callback) {
108101
if (!\is_callable($callback)) {
109-
throw new InvalidArgumentException(sprintf('The callback given in the context for attribute "%s" is not callable.', $attribute));
102+
throw new InvalidArgumentException(sprintf('Invalid callback found for attribute "%s" in the "%s" context option.', $attribute, self::CALLBACKS));
110103
}
111104
}
112105
}
@@ -120,10 +113,13 @@ public function normalize($object, $format = null, array $context = [])
120113
$attributes = $this->getAttributes($object, $format, $context);
121114
$class = $this->objectClassResolver ? ($this->objectClassResolver)($object) : \get_class($object);
122115
$attributesMetadata = $this->classMetadataFactory ? $this->classMetadataFactory->getMetadataFor($class)->getAttributesMetadata() : null;
123-
$maxDepthHandler = $context[self::MAX_DEPTH_HANDLER] ?? $this->defaultContext[self::MAX_DEPTH_HANDLER] ?? $this->maxDepthHandler;
124-
125-
if (null !== $maxDepthHandler && !\is_callable($maxDepthHandler)) {
126-
throw new InvalidArgumentException(sprintf('The %s given in the context is not callable.', self::MAX_DEPTH_HANDLER));
116+
if (isset($context[self::MAX_DEPTH_HANDLER])) {
117+
$maxDepthHandler = $context[self::MAX_DEPTH_HANDLER];
118+
if (!\is_callable($maxDepthHandler)) {
119+
throw new InvalidArgumentException(sprintf('The "%s" given in the context is not callable.', self::MAX_DEPTH_HANDLER));
120+
}
121+
} else {
122+
$maxDepthHandler = $this->defaultContext[self::MAX_DEPTH_HANDLER] ?? $this->maxDepthHandler;
127123
}
128124

129125
foreach ($attributes as $attribute) {

0 commit comments

Comments
 (0)
0