mirror of
https://github.com/doctrine/reflection.git
synced 2026-03-24 16:52:07 +01:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b33070b49 | ||
|
|
41a2f0f445 | ||
|
|
d11bac73db | ||
|
|
1c7272c98a | ||
|
|
bc420ead87 | ||
|
|
68b6aa3299 | ||
|
|
895c94dcee | ||
|
|
45270d8e58 | ||
|
|
76bb6bc20a | ||
|
|
9acbb8ccce | ||
|
|
8299ca45da | ||
|
|
7fba840747 | ||
|
|
bbf9810b57 | ||
|
|
6efdc3f15a | ||
|
|
0ac0da52c1 | ||
|
|
70707057f6 | ||
|
|
f3e4e24667 | ||
|
|
2c2888effb | ||
|
|
512a4f0ec1 | ||
|
|
07b0d59986 | ||
|
|
5eefae4186 | ||
|
|
7a2c95aa7c | ||
|
|
859446e967 | ||
|
|
81f27df605 | ||
|
|
de66230870 |
@@ -10,6 +10,7 @@ php:
|
||||
- 7.1
|
||||
- 7.2
|
||||
- 7.3
|
||||
- 7.4
|
||||
- nightly
|
||||
|
||||
before_install:
|
||||
@@ -43,4 +44,5 @@ jobs:
|
||||
- ./vendor/bin/phpcs
|
||||
|
||||
- stage: Lint
|
||||
script: vendor/bin/phpstan analyse -l 3 -c phpstan.neon lib tests
|
||||
php: 7.4
|
||||
script: vendor/bin/phpstan analyse
|
||||
|
||||
@@ -22,14 +22,14 @@
|
||||
"doctrine/annotations": "^1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpstan/phpstan": "^0.9.2",
|
||||
"phpstan/phpstan-phpunit": "^0.9.4",
|
||||
"phpstan/phpstan": "^0.11.0",
|
||||
"phpstan/phpstan-phpunit": "^0.11.0",
|
||||
"phpunit/phpunit": "^7.0",
|
||||
"doctrine/coding-standard": "^5.0",
|
||||
"doctrine/common": "^2.8"
|
||||
"doctrine/common": "^2.10"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/common": "<2.9@dev"
|
||||
"doctrine/common": "<2.9"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -38,7 +38,8 @@
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Doctrine\\Tests\\": "tests/Doctrine/Tests"
|
||||
"Doctrine\\Tests\\": "tests/Doctrine/Tests",
|
||||
"Doctrine\\Tests_PHP74\\": "tests/Doctrine/Tests_PHP74"
|
||||
}
|
||||
},
|
||||
"extra": {
|
||||
|
||||
1443
composer.lock
generated
1443
composer.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -89,7 +89,7 @@ class StaticReflectionMethod extends ReflectionMethod
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function getClosure($object)
|
||||
public function getClosure($object = null)
|
||||
{
|
||||
throw new ReflectionException('Method not implemented');
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use const T_CLASS;
|
||||
use const T_DOC_COMMENT;
|
||||
use const T_EXTENDS;
|
||||
use const T_FUNCTION;
|
||||
use const T_NEW;
|
||||
use const T_PAAMAYIM_NEKUDOTAYIM;
|
||||
use const T_PRIVATE;
|
||||
use const T_PROTECTED;
|
||||
@@ -18,6 +19,7 @@ use const T_VAR;
|
||||
use const T_VARIABLE;
|
||||
use function array_merge;
|
||||
use function file_get_contents;
|
||||
use function is_array;
|
||||
use function ltrim;
|
||||
use function preg_match;
|
||||
use function sprintf;
|
||||
@@ -161,7 +163,7 @@ class StaticReflectionParser implements ReflectionProviderInterface
|
||||
$docComment = $token[1];
|
||||
break;
|
||||
case T_CLASS:
|
||||
if ($last_token !== T_PAAMAYIM_NEKUDOTAYIM) {
|
||||
if ($last_token !== T_PAAMAYIM_NEKUDOTAYIM && $last_token !== T_NEW) {
|
||||
$this->docComment['class'] = $docComment;
|
||||
$docComment = '';
|
||||
}
|
||||
@@ -188,6 +190,9 @@ class StaticReflectionParser implements ReflectionProviderInterface
|
||||
while (($token = $tokenParser->next()) && $token[0] !== T_STRING) {
|
||||
continue;
|
||||
}
|
||||
if ($token === null) {
|
||||
break;
|
||||
}
|
||||
$methodName = $token[1];
|
||||
$this->docComment['method'][$methodName] = $docComment;
|
||||
$docComment = '';
|
||||
@@ -221,7 +226,7 @@ class StaticReflectionParser implements ReflectionProviderInterface
|
||||
break;
|
||||
}
|
||||
|
||||
$last_token = $token[0];
|
||||
$last_token = is_array($token) ? $token[0] : false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Common\Reflection;
|
||||
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
* PHP Typed No Default Reflection Property - special override for typed properties without a default value.
|
||||
*/
|
||||
class TypedNoDefaultReflectionProperty extends ReflectionProperty
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* Checks that a typed property is initialized before accessing its value.
|
||||
* This is necessary to avoid PHP error "Error: Typed property must not be accessed before initialization".
|
||||
* Should be used only for reflecting typed properties without a default value.
|
||||
*/
|
||||
public function getValue($object = null)
|
||||
{
|
||||
return $object !== null && $this->isInitialized($object) ? parent::getValue($object) : null;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,11 @@
|
||||
includes:
|
||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||
|
||||
parameters:
|
||||
level: 3
|
||||
paths:
|
||||
- %rootDir%/../../../lib
|
||||
- %rootDir%/../../../tests
|
||||
|
||||
ignoreErrors:
|
||||
- '#Doctrine\\Common\\Reflection\\StaticReflection[a-zA-Z0-9_]+::__construct\(\) does not call parent constructor from Reflection[a-zA-Z0-9_]+#'
|
||||
|
||||
includes:
|
||||
- vendor/phpstan/phpstan-phpunit/extension.neon
|
||||
@@ -8,7 +8,8 @@
|
||||
>
|
||||
<testsuites>
|
||||
<testsuite name="Doctrine Event Manager Test Suite">
|
||||
<directory>./tests/Doctrine/</directory>
|
||||
<directory>./tests/Doctrine/Tests</directory>
|
||||
<directory phpVersion="7.4" phpVersionOperator=">=">./tests/Doctrine/Tests_PHP74</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\Common\Reflection;
|
||||
|
||||
use Doctrine\Common\Annotations\Annotation;
|
||||
|
||||
/**
|
||||
* @Annotation(
|
||||
* key = "value"
|
||||
* )
|
||||
*/
|
||||
class AnnotationClassWithAnonymousClass
|
||||
{
|
||||
public function foo()
|
||||
{
|
||||
$new_class = new class () {
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,7 @@ namespace Doctrine\Tests\Common\Reflection;
|
||||
|
||||
use Doctrine\Common\Reflection\Psr0FindFile;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
use function sprintf;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
@@ -17,7 +18,7 @@ class Psr0FindFileTest extends TestCase
|
||||
{
|
||||
$file = $this->psr0FindFile->findFile(NoParent::class);
|
||||
|
||||
self::assertSame(sprintf('%s/NoParent.php', __DIR__), $file);
|
||||
self::assertSame(sprintf('%s%sNoParent.php', __DIR__, DIRECTORY_SEPARATOR), $file);
|
||||
}
|
||||
|
||||
public function testFindFileNotFound() : void
|
||||
@@ -29,14 +30,14 @@ class Psr0FindFileTest extends TestCase
|
||||
{
|
||||
$file = $this->psr0FindFile->findFile('\Doctrine\Tests\Common\Reflection\NoParent');
|
||||
|
||||
self::assertSame(sprintf('%s/NoParent.php', __DIR__), $file);
|
||||
self::assertSame(sprintf('%s%sNoParent.php', __DIR__, DIRECTORY_SEPARATOR), $file);
|
||||
}
|
||||
|
||||
public function testFindFileFromPearLikeClassName() : void
|
||||
{
|
||||
$file = $this->psr0FindFile->findFile('Doctrine_Tests_Common_Reflection_NoParent');
|
||||
|
||||
self::assertSame(sprintf('%s/NoParent.php', __DIR__), $file);
|
||||
self::assertSame(sprintf('%s%sNoParent.php', __DIR__, DIRECTORY_SEPARATOR), $file);
|
||||
}
|
||||
|
||||
protected function setUp() : void
|
||||
|
||||
@@ -56,7 +56,7 @@ class StaticReflectionClassTest extends TestCase
|
||||
|
||||
public function testGetMethod() : void
|
||||
{
|
||||
$staticReflectionMethod = $this->createMock(StaticReflectionMethod::class);
|
||||
$staticReflectionMethod = $this->createPartialMock(StaticReflectionMethod::class, []);
|
||||
|
||||
$this->staticReflectionParser->expects($this->once())
|
||||
->method('getReflectionMethod')
|
||||
|
||||
@@ -27,7 +27,7 @@ class StaticReflectionMethodTest extends TestCase
|
||||
|
||||
public function testGetDeclaringClass() : void
|
||||
{
|
||||
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
|
||||
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
|
||||
|
||||
$this->staticReflectionParser->expects($this->once())
|
||||
->method('getReflectionClass')
|
||||
@@ -47,7 +47,7 @@ class StaticReflectionMethodTest extends TestCase
|
||||
|
||||
public function testGetDocComment() : void
|
||||
{
|
||||
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
|
||||
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
|
||||
|
||||
$this->staticReflectionParser->expects($this->once())
|
||||
->method('getDocComment')
|
||||
@@ -59,7 +59,7 @@ class StaticReflectionMethodTest extends TestCase
|
||||
|
||||
public function testGetUseStatements() : void
|
||||
{
|
||||
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
|
||||
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
|
||||
|
||||
$this->staticReflectionParser->expects($this->once())
|
||||
->method('getUseStatements')
|
||||
|
||||
@@ -101,7 +101,7 @@ class StaticReflectionParserTest extends DoctrineTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]|bool[]
|
||||
* @return array<array<bool|string>>
|
||||
*/
|
||||
public function classAnnotationOptimize()
|
||||
{
|
||||
@@ -110,6 +110,8 @@ class StaticReflectionParserTest extends DoctrineTestCase
|
||||
[ExampleAnnotationClass::class, true],
|
||||
[AnnotationClassWithScopeResolution::class, false],
|
||||
[AnnotationClassWithScopeResolution::class, true],
|
||||
[AnnotationClassWithAnonymousClass::class, false],
|
||||
[AnnotationClassWithAnonymousClass::class, true],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class StaticReflectionPropertyTest extends TestCase
|
||||
|
||||
public function testGetDeclaringClass() : void
|
||||
{
|
||||
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
|
||||
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
|
||||
|
||||
$this->staticReflectionParser->expects($this->once())
|
||||
->method('getReflectionClass')
|
||||
@@ -38,7 +38,7 @@ class StaticReflectionPropertyTest extends TestCase
|
||||
|
||||
public function testGetDocComment() : void
|
||||
{
|
||||
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
|
||||
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
|
||||
|
||||
$this->staticReflectionParser->expects($this->once())
|
||||
->method('getDocComment')
|
||||
@@ -50,7 +50,7 @@ class StaticReflectionPropertyTest extends TestCase
|
||||
|
||||
public function testGetUseStatements() : void
|
||||
{
|
||||
$staticReflectionClass = $this->createMock(StaticReflectionClass::class);
|
||||
$staticReflectionClass = $this->createPartialMock(StaticReflectionClass::class, []);
|
||||
|
||||
$this->staticReflectionParser->expects($this->once())
|
||||
->method('getUseStatements')
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests_PHP74\Common\Reflection\Dummies;
|
||||
|
||||
trait TokenParserAnonymousFunctionTestClass
|
||||
{
|
||||
protected function method()
|
||||
{
|
||||
return static function ($value) {
|
||||
return $value;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests_PHP74\Common\Reflection;
|
||||
|
||||
use Doctrine\Common\Reflection\Psr0FindFile;
|
||||
use Doctrine\Common\Reflection\StaticReflectionParser;
|
||||
use Doctrine\Tests_PHP74\Common\Reflection\Dummies\TokenParserAnonymousFunctionTestClass;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use function strlen;
|
||||
use function substr;
|
||||
|
||||
class TokenParserAnonymousFunctionTest extends TestCase
|
||||
{
|
||||
public function testGetValue() : void
|
||||
{
|
||||
$testsRoot = substr(__DIR__, 0, -strlen(__NAMESPACE__) - 1);
|
||||
$paths = [
|
||||
'Doctrine\\Tests_PHP74' => [$testsRoot],
|
||||
];
|
||||
$staticReflectionParser = new StaticReflectionParser(TokenParserAnonymousFunctionTestClass::class, new Psr0FindFile($paths));
|
||||
|
||||
self::assertEquals('', $staticReflectionParser->getDocComment());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests_PHP74\Common\Reflection;
|
||||
|
||||
use Doctrine\Common\Reflection\TypedNoDefaultReflectionProperty;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TypedNoDefaultReflectionPropertyTest extends TestCase
|
||||
{
|
||||
public function testGetValue() : void
|
||||
{
|
||||
$object = new TypedNoDefaultReflectionPropertyTestClass();
|
||||
|
||||
$reflProperty = new TypedNoDefaultReflectionProperty(TypedNoDefaultReflectionPropertyTestClass::class, 'test');
|
||||
|
||||
self::assertNull($reflProperty->getValue($object));
|
||||
|
||||
$object->test = 'testValue';
|
||||
|
||||
self::assertSame('testValue', $reflProperty->getValue($object));
|
||||
|
||||
unset($object->test);
|
||||
|
||||
self::assertNull($reflProperty->getValue($object));
|
||||
}
|
||||
}
|
||||
|
||||
class TypedNoDefaultReflectionPropertyTestClass
|
||||
{
|
||||
public string $test;
|
||||
}
|
||||
Reference in New Issue
Block a user