Remove StaticReflectionService

Additionally, implementations of ReflectionService may no longer return
null for calls to getClass().
This commit is contained in:
Grégoire Paris
2024-06-23 20:35:54 +02:00
parent 1996fcdaa3
commit 26288e584d
4 changed files with 12 additions and 120 deletions

View File

@@ -8,6 +8,16 @@ awareness about deprecated code.
# Upgrade to 4.0
## BC Break: Removed `StaticReflectionService`
The class `Doctrine\Persistence\Mapping\StaticReflectionService` is removed
without replacement.
## BC Break: Narrowed `ReflectionService::getClass()` return type
The return type of `ReflectionService::getClass()` has been narrowed so that
`null` is no longer a valid return value.
## BC Break: Added `ObjectManager::isUninitializedObject()`
Classes implementing `Doctrine\Persistence\ObjectManager` must implement this

View File

@@ -42,11 +42,11 @@ interface ReflectionService
*
* @psalm-param class-string<T> $class
*
* @psalm-return ReflectionClass<T>|null
* @psalm-return ReflectionClass<T>
*
* @template T of object
*/
public function getClass(string $class): ReflectionClass|null;
public function getClass(string $class): ReflectionClass;
/**
* Returns an accessible property (setAccessible(true)) or null.

View File

@@ -1,67 +0,0 @@
<?php
declare(strict_types=1);
namespace Doctrine\Persistence\Mapping;
use ReflectionClass;
use ReflectionProperty;
use function str_contains;
use function strpos;
use function strrev;
use function strrpos;
use function substr;
/**
* PHP Runtime Reflection Service.
*
* @deprecated No replacement planned
*/
class StaticReflectionService implements ReflectionService
{
/**
* {@inheritDoc}
*/
public function getParentClasses(string $class): array
{
return [];
}
public function getClassShortName(string $class): string
{
$nsSeparatorLastPosition = strrpos($class, '\\');
if ($nsSeparatorLastPosition !== false) {
$class = substr($class, $nsSeparatorLastPosition + 1);
}
return $class;
}
public function getClassNamespace(string $class): string
{
$namespace = '';
if (str_contains($class, '\\')) {
$namespace = strrev(substr(strrev($class), (int) strpos(strrev($class), '\\') + 1));
}
return $namespace;
}
public function getClass(string $class): ReflectionClass|null
{
return null;
}
public function getAccessibleProperty(string $class, string $property): ReflectionProperty|null
{
return null;
}
public function hasPublicMethod(string $class, string $method): bool
{
return true;
}
}

View File

@@ -1,51 +0,0 @@
<?php
declare(strict_types=1);
namespace Doctrine\Tests\Persistence\Mapping;
use Doctrine\Persistence\Mapping\StaticReflectionService;
use PHPUnit\Framework\TestCase;
use stdClass;
use function count;
/** @group DCOM-93 */
class StaticReflectionServiceTest extends TestCase
{
private StaticReflectionService $reflectionService;
protected function setUp(): void
{
$this->reflectionService = new StaticReflectionService();
}
public function testShortname(): void
{
self::assertSame('StaticReflectionServiceTest', $this->reflectionService->getClassShortName(self::class));
}
public function testClassNamespaceName(): void
{
self::assertSame('', $this->reflectionService->getClassNamespace(stdClass::class));
self::assertSame(__NAMESPACE__, $this->reflectionService->getClassNamespace(self::class));
}
public function testGetParentClasses(): void
{
$classes = $this->reflectionService->getParentClasses(self::class);
self::assertTrue(count($classes) === 0, 'The test class ' . self::class . ' should have no parents according to static reflection.');
}
public function testGetMethods(): void
{
self::assertTrue($this->reflectionService->hasPublicMethod(self::class, 'testGetMethods'));
self::assertTrue($this->reflectionService->hasPublicMethod(self::class, 'testGetMethods2'));
}
public function testGetAccessibleProperty(): void
{
$reflProp = $this->reflectionService->getAccessibleProperty(self::class, 'reflectionService');
self::assertNull($reflProp);
}
}