Skip to content

Commit aa1d379

Browse files
committed
[ReflectionExtractor] Simplify feature gate with simple "PHP_VERSION_ID" comparison
1 parent e4d754f commit aa1d379

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/Symfony/Component/PropertyInfo/Extractor/ReflectionExtractor.php

+14-10
Original file line numberDiff line numberDiff line change
@@ -713,13 +713,7 @@ private function isAllowedProperty(string $class, string $property, bool $writeA
713713
return false;
714714
}
715715

716-
// PHP 8.4: Asymmetric Visibility and Property Hooks
717-
$hasAsymmetricVisibilityCapability = method_exists($reflectionProperty, 'isPrivateSet')
718-
&& method_exists($reflectionProperty, 'isProtectedSet')
719-
&& method_exists($reflectionProperty, 'isVirtual')
720-
&& method_exists($reflectionProperty, 'hasHook');
721-
722-
if ($hasAsymmetricVisibilityCapability) {
716+
if (\PHP_VERSION_ID >= 80400) {
723717
// If the property is virtual and has no setter, it's not writable.
724718
if ($writeAccessRequired && $reflectionProperty->isVirtual() && !$reflectionProperty->hasHook(\PropertyHookType::Set)) {
725719
return false;
@@ -969,15 +963,25 @@ private function getReadVisiblityForMethod(\ReflectionMethod $reflectionMethod):
969963

970964
private function getWriteVisiblityForProperty(\ReflectionProperty $reflectionProperty): string
971965
{
972-
// PHP 8.4: Property hooks
973-
if (method_exists($reflectionProperty, 'isVirtual') && method_exists($reflectionProperty, 'hasHook')) {
966+
if (\PHP_VERSION_ID >= 80400) {
967+
// If the property is virtual and has no setter, it's private
974968
if ($reflectionProperty->isVirtual() && !$reflectionProperty->hasHook(\PropertyHookType::Set)) {
975969
return PropertyWriteInfo::VISIBILITY_PRIVATE;
976970
}
971+
972+
// If the property has private setter, it's not writable
973+
if ($reflectionProperty->isPrivateSet()) {
974+
return PropertyWriteInfo::VISIBILITY_PRIVATE;
975+
}
976+
977+
// If the property has protected setter, it's protected
978+
if ($reflectionProperty->isProtectedSet()) {
979+
return PropertyWriteInfo::VISIBILITY_PROTECTED;
980+
}
977981
}
978982

979983
// PHP 8.4: Asymmetric visibility
980-
if (method_exists($reflectionProperty, 'isPrivateSet') && method_exists($reflectionProperty, 'isProtectedSet')) {
984+
if (\PHP_VERSION_ID >= 80400) {
981985
if ($reflectionProperty->isPrivateSet()) {
982986
return PropertyWriteInfo::VISIBILITY_PRIVATE;
983987
}

0 commit comments

Comments
 (0)