[PR #24] [MERGED] Add reflection typed no default property class #28

Open
opened 2026-01-24 11:24:52 +01:00 by admin · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/doctrine/reflection/pull/24
Author: @sspat
Created: 12/2/2019
Status: Merged
Merged: 1/8/2020
Merged by: @beberlei

Base: masterHead: add_reflection_typed_no_default_property_class


📝 Commits (7)

  • 7070705 Added reflection class for handling typed properties without default value #23
  • 0ac0da5 Updated phpunit and travis configs to work with tests containing code in php 7.4 syntax #23
  • 6efdc3f Added php 7.4 specific tests directory to composer autoloading config #23
  • bbf9810 Changed test assertion method #23
  • 7fba840 Changed dynamic property name access syntax #23
  • 8299ca4 Changed the property access syntax again #23
  • 9acbb8c Replaced isset with ReflectionProperty::isInitialized #23

📊 Changes

4 files changed (+58 additions, -2 deletions)

View changed files

📝 composer.json (+2 -1)
lib/Doctrine/Common/Reflection/TypedNoDefaultReflectionProperty.php (+23 -0)
📝 phpunit.xml.dist (+2 -1)
tests/Doctrine/Tests_PHP74/Common/Reflection/TypedNoDefaultReflectionPropertyTest.php (+31 -0)

📄 Description

Implementation for issue https://github.com/doctrine/reflection/issues/23
See discussion in https://github.com/doctrine/orm/pull/7857

As suggested by @beberlei, the \Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty class was introduced.
It will be returned in doctrine/persistence package class RuntimeReflectionService::getAccessibleProperty if the property is typed and has no default value. Something like this:

/**
 * {@inheritDoc}
 */
public function getAccessibleProperty(string $class, string $property) : ?ReflectionProperty
{
    $reflectionProperty = new ReflectionProperty($class, $property);

    if (! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) {
        $reflectionProperty = new TypedNoDefaultReflectionProperty($class, $property);
    } elseif ($reflectionProperty->isPublic()) {
        $reflectionProperty = new RuntimePublicReflectionProperty($class, $property);
    }

    $reflectionProperty->setAccessible(true);

    return $reflectionProperty;
}

Also updated phpunit config as suggested in the discussion in the same issue https://github.com/doctrine/reflection/issues/23.
This allows skipping tests containing php 7.4 specific syntax on builds with lesser php versions.
Also updated travis-ci.yml Lint job to ignore such tests by phpstan analysis, if the php version is less than 7.4


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/doctrine/reflection/pull/24 **Author:** [@sspat](https://github.com/sspat) **Created:** 12/2/2019 **Status:** ✅ Merged **Merged:** 1/8/2020 **Merged by:** [@beberlei](https://github.com/beberlei) **Base:** `master` ← **Head:** `add_reflection_typed_no_default_property_class` --- ### 📝 Commits (7) - [`7070705`](https://github.com/doctrine/reflection/commit/70707057f60f9081453ed305bec29fcbdd81d6ee) Added reflection class for handling typed properties without default value #23 - [`0ac0da5`](https://github.com/doctrine/reflection/commit/0ac0da52c117d11c6a999d6ba90cce01c9033f41) Updated phpunit and travis configs to work with tests containing code in php 7.4 syntax #23 - [`6efdc3f`](https://github.com/doctrine/reflection/commit/6efdc3f15aa09f672c3545f81ea9e5d8c22ecb26) Added php 7.4 specific tests directory to composer autoloading config #23 - [`bbf9810`](https://github.com/doctrine/reflection/commit/bbf9810b57be7055fc8982a9deb60bb62fbf6379) Changed test assertion method #23 - [`7fba840`](https://github.com/doctrine/reflection/commit/7fba840747861641c1f14d3bdd5440bb23ba5476) Changed dynamic property name access syntax #23 - [`8299ca4`](https://github.com/doctrine/reflection/commit/8299ca45da345cb7fccb7b7a620bb49e91ab5e17) Changed the property access syntax again #23 - [`9acbb8c`](https://github.com/doctrine/reflection/commit/9acbb8cccecd05551b92e7ee8ffb68d18eb7ac90) Replaced isset with ReflectionProperty::isInitialized #23 ### 📊 Changes **4 files changed** (+58 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `composer.json` (+2 -1) ➕ `lib/Doctrine/Common/Reflection/TypedNoDefaultReflectionProperty.php` (+23 -0) 📝 `phpunit.xml.dist` (+2 -1) ➕ `tests/Doctrine/Tests_PHP74/Common/Reflection/TypedNoDefaultReflectionPropertyTest.php` (+31 -0) </details> ### 📄 Description Implementation for issue https://github.com/doctrine/reflection/issues/23 See discussion in https://github.com/doctrine/orm/pull/7857 As suggested by @beberlei, the `\Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty` class was introduced. It will be returned in `doctrine/persistence` package class [RuntimeReflectionService::getAccessibleProperty](https://github.com/doctrine/persistence/blob/master/lib/Doctrine/Persistence/Mapping/RuntimeReflectionService.php) if the property is typed and has no default value. Something like this: ```php /** * {@inheritDoc} */ public function getAccessibleProperty(string $class, string $property) : ?ReflectionProperty { $reflectionProperty = new ReflectionProperty($class, $property); if (! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) { $reflectionProperty = new TypedNoDefaultReflectionProperty($class, $property); } elseif ($reflectionProperty->isPublic()) { $reflectionProperty = new RuntimePublicReflectionProperty($class, $property); } $reflectionProperty->setAccessible(true); return $reflectionProperty; } ``` Also updated phpunit config as suggested in the discussion in the same issue https://github.com/doctrine/reflection/issues/23. This allows skipping tests containing php 7.4 specific syntax on builds with lesser php versions. Also updated `travis-ci.yml` Lint job to ignore such tests by phpstan analysis, if the php version is less than 7.4 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
admin added the pull-request label 2026-01-24 11:24:52 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/reflection#28