Skip to content

Commit 9fcb3ac

Browse files
derrabusnicolas-grekas
authored andcommitted
Leverage str_contains/str_starts_with
Signed-off-by: Alexander M. Turek <[email protected]>
1 parent 236c5a0 commit 9fcb3ac

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

PropertyAccessor.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ private static function throwInvalidArgumentException(string $message, array $tr
188188
}
189189

190190
if (\PHP_VERSION_ID < 80000) {
191-
if (0 !== strpos($message, 'Argument ')) {
191+
if (!str_starts_with($message, 'Argument ')) {
192192
return;
193193
}
194194

@@ -400,7 +400,7 @@ private function readProperty(array $zval, string $property, bool $ignoreInvalid
400400
&& $object instanceof $trace['class']
401401
&& preg_match('/Return value (?:of .*::\w+\(\) )?must be of (?:the )?type (\w+), null returned$/', $e->getMessage(), $matches)
402402
) {
403-
throw new AccessException(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"?', false === strpos(\get_class($object), "@anonymous\0") ? \get_class($object) : (get_parent_class($object) ?: 'class').'@anonymous', $access[self::ACCESS_NAME], $matches[1]), 0, $e);
403+
throw new AccessException(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"?', !str_contains(\get_class($object), "@anonymous\0") ? \get_class($object) : (get_parent_class($object) ?: 'class').'@anonymous', $access[self::ACCESS_NAME], $matches[1]), 0, $e);
404404
}
405405

406406
throw $e;

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
],
1818
"require": {
1919
"php": ">=7.1.3",
20-
"symfony/inflector": "^3.4|^4.0|^5.0"
20+
"symfony/inflector": "^3.4|^4.0|^5.0",
21+
"symfony/polyfill-php80": "^1.16"
2122
},
2223
"require-dev": {
2324
"symfony/cache": "^3.4|^4.0|^5.0"

0 commit comments

Comments
 (0)