Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
script: ./vendor/bin/phpcs

- stage: Code Quality
php: 7.4snapshot
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A stable image is out

Suggested change
php: 7.4snapshot
php: 7.4

env: STATIC_ANALYSIS
install: travis_retry composer install --prefer-dist
script: vendor/bin/phpstan analyze
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"doctrine/cache": "^1.0",
"doctrine/collections": "^1.0",
"doctrine/event-manager": "^1.0",
"doctrine/reflection": "^1.0"
"doctrine/reflection": "^1.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the dependency change, this will only be in 1.4 which will not be released until we've fixed the deprecation warnings in ORM and other libraries. See my other comment for a suggestion on how to fix this.

},
"require-dev": {
"phpstan/phpstan": "^0.11",
Expand All @@ -44,7 +44,8 @@
},
"autoload-dev": {
"psr-4": {
"Doctrine\\Tests\\": "tests/Doctrine/Tests"
"Doctrine\\Tests\\": "tests/Doctrine/Tests",
"Doctrine\\Tests_PHP74\\": "tests/Doctrine/Tests_PHP74"
}
},
"extra": {
Expand Down
41 changes: 22 additions & 19 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
namespace Doctrine\Persistence\Mapping;

use Doctrine\Common\Reflection\RuntimePublicReflectionProperty;
use Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty;
use ReflectionClass;
use ReflectionException;
use ReflectionMethod;
use ReflectionProperty;
use function array_key_exists;
use function class_exists;
use function class_parents;

Expand Down Expand Up @@ -64,7 +66,9 @@ public function getAccessibleProperty(string $class, string $property)
{
$reflectionProperty = new ReflectionProperty($class, $property);

if ($reflectionProperty->isPublic()) {
if (! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, you can avoid the dependency bump and target 1.3 to fix this bug in a patch release:

Suggested change
if (! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) {
if (class_exists(TypedNoDefaultReflectionProperty::class) && ! array_key_exists($property, $this->getClass($class)->getDefaultProperties())) {

$reflectionProperty = new TypedNoDefaultReflectionProperty($class, $property);
} elseif ($reflectionProperty->isPublic()) {
$reflectionProperty = new RuntimePublicReflectionProperty($class, $property);
}

Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ parameters:
- %currentWorkingDirectory%/tests/Doctrine/Tests/Persistence/ObjectManagerDecoratorTest.php
- %currentWorkingDirectory%/tests/Doctrine/Tests/Persistence/Mapping/ClassMetadataFactoryTest.php
- %currentWorkingDirectory%/tests/Doctrine/Tests/Persistence/Mapping/_files/annotation/TestClass.php
- %currentWorkingDirectory%/tests/Doctrine/Tests_PHP74/Persistence/Mapping/RuntimeReflectionServiceTest.php

excludes_analyse:
- %currentWorkingDirectory%/tests/Doctrine/Tests/Persistence/Mapping/_files/TestEntity.php

ignoreErrors:
# looks like a bug in phpstan since method_exists first argument accepts a string
- '#Call to function method_exists\(\) with string and (.*) will always evaluate to false#'
# Should be fixed by adding return typehints
- '#Cannot call method getDefaultProperties\(\) on ReflectionClass|null.#'

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
>
<testsuites>
<testsuite name="Doctrine Persistence Test Suite">
<directory>./tests/Doctrine/</directory>
<directory>./tests/Doctrine/Tests</directory>
<directory phpVersion="7.4" phpVersionOperator=">=">./tests/Doctrine/Tests_PHP74</directory>
</testsuite>
</testsuites>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests_PHP74\Persistence\Mapping;

use Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty;
use Doctrine\Persistence\Mapping\RuntimeReflectionService;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;

/**
* @group DCOM-93
*/
class RuntimeReflectionServiceTest extends TestCase
{
/** @var RuntimeReflectionService */
private $reflectionService;

private string $typedNoDefaultProperty;
private string $typedDefaultProperty = '';

protected function setUp() : void
{
$this->reflectionService = new RuntimeReflectionService();
}

public function testGetTypedNoDefaultReflectionProperty() : void
{
$reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedNoDefaultProperty');
self::assertInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp);
}

public function testGetTypedDefaultReflectionProperty() : void
{
$reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'typedDefaultProperty');
self::assertInstanceOf(ReflectionProperty::class, $reflProp);
self::assertNotInstanceOf(TypedNoDefaultReflectionProperty::class, $reflProp);
}
}