Skip to content

Commit c39cbf1

Browse files
authored
Add types to ProxyFactory (#9962)
1 parent 9e304fb commit c39cbf1

File tree

2 files changed

+15
-26
lines changed

2 files changed

+15
-26
lines changed

lib/Doctrine/ORM/Proxy/ProxyFactory.php

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,11 @@
2424
*/
2525
class ProxyFactory extends AbstractProxyFactory
2626
{
27-
/** @var EntityManagerInterface The EntityManager this factory is bound to. */
28-
private $em;
27+
/** The UnitOfWork this factory uses to retrieve persisters */
28+
private readonly UnitOfWork $uow;
2929

30-
/** @var UnitOfWork The UnitOfWork this factory uses to retrieve persisters */
31-
private $uow;
32-
33-
/** @var string */
34-
private $proxyNs;
35-
36-
/**
37-
* The IdentifierFlattener used for manipulating identifiers
38-
*
39-
* @var IdentifierFlattener
40-
*/
41-
private $identifierFlattener;
30+
/** The IdentifierFlattener used for manipulating identifiers */
31+
private readonly IdentifierFlattener $identifierFlattener;
4232

4333
/**
4434
* Initializes a new instance of the <tt>ProxyFactory</tt> class that is
@@ -51,23 +41,22 @@ class ProxyFactory extends AbstractProxyFactory
5141
* values are constants of {@see AbstractProxyFactory}.
5242
* @psalm-param bool|AutogenerateMode $autoGenerate
5343
*/
54-
public function __construct(EntityManagerInterface $em, $proxyDir, $proxyNs, $autoGenerate = AbstractProxyFactory::AUTOGENERATE_NEVER)
55-
{
44+
public function __construct(
45+
private readonly EntityManagerInterface $em,
46+
string $proxyDir,
47+
private readonly string $proxyNs,
48+
bool|int $autoGenerate = AbstractProxyFactory::AUTOGENERATE_NEVER,
49+
) {
5650
$proxyGenerator = new ProxyGenerator($proxyDir, $proxyNs);
5751

5852
$proxyGenerator->setPlaceholder('baseProxyInterface', Proxy::class);
5953
parent::__construct($proxyGenerator, $em->getMetadataFactory(), $autoGenerate);
6054

61-
$this->em = $em;
6255
$this->uow = $em->getUnitOfWork();
63-
$this->proxyNs = $proxyNs;
6456
$this->identifierFlattener = new IdentifierFlattener($this->uow, $em->getMetadataFactory());
6557
}
6658

67-
/**
68-
* {@inheritDoc}
69-
*/
70-
protected function skipClass(ClassMetadata $metadata)
59+
protected function skipClass(ClassMetadata $metadata): bool
7160
{
7261
return $metadata->isMappedSuperclass
7362
|| $metadata->isEmbeddedClass
@@ -77,7 +66,7 @@ protected function skipClass(ClassMetadata $metadata)
7766
/**
7867
* {@inheritDoc}
7968
*/
80-
protected function createProxyDefinition($className)
69+
protected function createProxyDefinition($className): ProxyDefinition
8170
{
8271
$classMetadata = $this->em->getClassMetadata($className);
8372
$entityPersister = $this->uow->getEntityPersister($className);
@@ -175,7 +164,6 @@ private function createCloner(ClassMetadata $classMetadata, EntityPersister $ent
175164
continue;
176165
}
177166

178-
$property->setAccessible(true);
179167
$property->setValue($proxy, $property->getValue($original));
180168
}
181169
};

psalm-baseline.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,9 @@
10961096
<PossiblyNullPropertyFetch occurrences="1">
10971097
<code>$property-&gt;name</code>
10981098
</PossiblyNullPropertyFetch>
1099-
<PossiblyNullReference occurrences="1">
1100-
<code>setAccessible</code>
1099+
<PossiblyNullReference occurrences="2">
1100+
<code>getValue</code>
1101+
<code>setValue</code>
11011102
</PossiblyNullReference>
11021103
<UndefinedInterfaceMethod occurrences="1">
11031104
<code>__wakeup</code>

0 commit comments

Comments
 (0)