8000 Merge branch '5.1' · symfony/property-access@663140c · GitHub
[go: up one dir, main page]

Skip to content

Commit 663140c

Browse files
Merge branch '5.1'
* 5.1: (33 commits) [Cache] $lifetime cannot be null [Serializer] minor cleanup fix merge Run PHP 8 as 7.4.99 Remove calls to deprecated ReflectionParameter::getClass(). [VarDumper] fix PHP 8 support Removed "services" prototype node from "custom_authenticator" Add php 8 to travis. [Cache] Accessing undefined constants raises an Error in php8 [Cache] allow DBAL v3 Skip Doctrine DBAL on php 8 until we have a compatible version. [DomCrawler] Catch expected ValueError. Made method signatures compatible with their corresponding traits. [ErrorHandler] Apply php8 fixes from Debug component. [DomCrawler] Catch expected ValueError. [Validator] Catch expected ValueError. [VarDumper] ReflectionFunction::isDisabled() is deprecated. [BrowserKit] Raw body with custom Content-Type header Revert symfony/symfony#34986 Make ExpressionLanguageSyntax validator usable with annotation ...
2 parents 3e9934d + 3d19a2b commit 663140c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

PropertyAccessor.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,15 @@ public function setValue(&$objectOrArray, $propertyPath, $value)
190190

191191
private static function throwInvalidArgumentException(string $message, array $trace, int $i, string $propertyPath, \Throwable $previous = null): void
192192
{
193-
// the type mismatch is not caused by invalid arguments (but e.g. by an incompatible return type hint of the writer method)
194-
if (0 !== strpos($message, 'Argument ')) {
193+
if (!isset($trace[$i]['file']) || __FILE__ !== $trace[$i]['file']) {
195194
return;
196195
}
197196

198-
if (isset($trace[$i]['file']) && __FILE__ === $trace[$i]['file']) {
197+
if (\PHP_VERSION_ID < 80000) {
198+
if (0 !== strpos($message, 'Argument ')) {
199+
return;
200+
}
201+
199202
$pos = strpos($message, $delim = 'must be of the type ') ?: (strpos($message, $delim = 'must be an instance of ') ?: strpos($message, $delim = 'must implement interface '));
200203
$pos += \strlen($delim);
201204
$j = strpos($message, ',', $pos);
@@ -204,6 +207,12 @@ private static function throwInvalidArgumentException(string $message, array $tr
204207

205208
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given at property path "%s".', $message, 'NULL' === $type ? 'null' : $type, $propertyPath), 0, $previous);
206209
}
210+
211+
if (preg_match('/^\S+::\S+\(\): Argument #\d+ \(\$\S+\) must be of type (\S+), (\S+) given/', $message, $matches)) {
212+
list(, $expectedType, $actualType) = $matches;
213+
214+
throw new InvalidArgumentException(sprintf('Expected argument of type "%s", "%s" given.', $expectedType, 'NULL' === $actualType ? 'null' : $actualType), 0, $previous);
215+
}
207216
}
208217

209218
/**
@@ -395,7 +404,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
395404
try {
396405
$result[self::VALUE] = $object->$name();
397406
} catch (\TypeError $e) {
398-
if (preg_match((sprintf('/^Return value of %s::%s\(\) must be of the type (\w+), null returned$/', preg_quote(\get_class($object)), $name)), $e->getMessage(), $matches)) {
407+
if (preg_match((sprintf('/^Return value of %s::%s\(\) must be of (?:the )?type (\w+), null returned$/', preg_quote(\get_class($object)), 4A03 $name)), $e->getMessage(), $matches)) {
399408
throw new UninitializedPropertyException(sprintf('The method "%s::%s()" returned "null", but expected type "%3$s". Did you forget to initialize a property or to make the return type nullable using "?%3$s"?', \get_class($object), $name, $matches[1]), 0, $e);
400409
}
401410

0 commit comments

Comments
 (0)
0