Skip to content

Commit 8213f84

Browse files
Small improvements and micro optimizations (#2309)
* Fixed some annotations * Mark comment as a TODO. CS. * Micro-optimization. Use isset instead of array_key_exists * Don't use reflection property to access protected property from parent * Small fixes Co-authored-by: Alexandr Zolotukhin <[email protected]>
1 parent ecf41a6 commit 8213f84

File tree

6 files changed

+18
-22
lines changed

6 files changed

+18
-22
lines changed

src/Mapping/Event/Adapter/ORM.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,13 @@ public function clearObjectChangeSet($uow, $object)
167167
/**
168168
* Creates a ORM specific LifecycleEventArgs.
169169
*
170-
* @param object $document
171-
* @param \Doctrine\ODM\MongoDB\DocumentManager $documentManager
170+
* @param object $document
171+
* @param \Doctrine\ORM\EntityManagerInterface $entityManager
172172
*
173-
* @return \Doctrine\ODM\MongoDB\Event\LifecycleEventArgs
173+
* @return \Doctrine\ORM\Event\LifecycleEventArgs
174174
*/
175-
public function createLifecycleEventArgsInstance($document, $documentManager)
175+
public function createLifecycleEventArgsInstance($document, $entityManager)
176176
{
177-
return new LifecycleEventArgs($document, $documentManager);
177+
return new LifecycleEventArgs($document, $entityManager);
178178
}
179179
}

src/Mapping/MappedEventSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function __construct()
9292
protected function getEventAdapter(EventArgs $args)
9393
{
9494
$class = get_class($args);
95-
if (preg_match('@Doctrine\\\([^\\\]+)@', $class, $m) && in_array($m[1], ['ODM', 'ORM'])) {
95+
if (preg_match('@Doctrine\\\([^\\\]+)@', $class, $m) && in_array($m[1], ['ODM', 'ORM'], true)) {
9696
if (!isset($this->adapters[$m[1]])) {
9797
$adapterClass = $this->getNamespace().'\\Mapping\\Event\\Adapter\\'.$m[1];
9898
if (!class_exists($adapterClass)) {

src/SoftDeleteable/Filter/ODM/SoftDeleteableFilter.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ class SoftDeleteableFilter extends BsonFilter
2323
public function addFilterCriteria(ClassMetadata $targetEntity): array
2424
{
2525
$class = $targetEntity->getName();
26-
if (array_key_exists($class, $this->disabled) && true === $this->disabled[$class]) {
26+
if (true === ($this->disabled[$class] ?? false)) {
2727
return [];
28-
} elseif (array_key_exists($targetEntity->rootDocumentName, $this->disabled) && true === $this->disabled[$targetEntity->rootDocumentName]) {
28+
}
29+
if (true === ($this->disabled[$targetEntity->rootDocumentName] ?? false)) {
2930
return [];
3031
}
3132

src/SoftDeleteable/Filter/SoftDeleteableFilter.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,16 @@ class SoftDeleteableFilter extends SQLFilter
3737
* @param string $targetTableAlias
3838
*
3939
* @return string
40+
*
41+
* @throws \Doctrine\DBAL\Exception
4042
*/
4143
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
4244
{
4345
$class = $targetEntity->getName();
44-
if (array_key_exists($class, $this->disabled) && true === $this->disabled[$class]) {
46+
if (true === ($this->disabled[$class] ?? false)) {
4547
return '';
46-
} elseif (array_key_exists($targetEntity->rootEntityName, $this->disabled) && true === $this->disabled[$targetEntity->rootEntityName]) {
48+
}
49+
if (true === ($this->disabled[$targetEntity->rootEntityName] ?? false)) {
4750
return '';
4851
}
4952

@@ -53,8 +56,7 @@ public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAli
5356
return '';
5457
}
5558

56-
$conn = $this->getEntityManager()->getConnection();
57-
$platform = $conn->getDatabasePlatform();
59+
$platform = $this->getConnection()->getDatabasePlatform();
5860
$column = $targetEntity->getQuotedColumnName($config['fieldName'], $platform);
5961

6062
$addCondSql = $platform->getIsNullExpression($targetTableAlias.'.'.$column);

src/SoftDeleteable/Query/TreeWalker/Exec/MultiTableDeleteExecutor.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,7 @@ public function __construct(Node $AST, $sqlWalker, ClassMetadataInfo $meta, Abst
2424
{
2525
parent::__construct($AST, $sqlWalker);
2626

27-
$getSqlStatements = \Closure::bind(function (): array {
28-
return $this->_sqlStatements;
29-
}, $this, static::class);
30-
31-
$sqlStatements = $getSqlStatements();
27+
$sqlStatements = $this->_sqlStatements;
3228

3329
foreach ($sqlStatements as $index => $stmt) {
3430
$matches = [];
@@ -47,10 +43,6 @@ public function __construct(Node $AST, $sqlWalker, ClassMetadataInfo $meta, Abst
4743
}
4844
}
4945

50-
$setSqlStatements = \Closure::bind(function (array $sqlStatements): void {
51-
$this->_sqlStatements = $sqlStatements;
52-
}, $this, static::class);
53-
54-
$setSqlStatements($sqlStatements);
46+
$this->_sqlStatements = $sqlStatements;
5547
}
5648
}

src/SoftDeleteable/SoftDeleteableListener.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public function getSubscribedEvents()
4949
public function onFlush(EventArgs $args)
5050
{
5151
$ea = $this->getEventAdapter($args);
52+
/** @var \Doctrine\ORM\EntityManagerInterface|\Doctrine\ODM\MongoDB\DocumentManager $om */
5253
$om = $ea->getObjectManager();
5354
$uow = $om->getUnitOfWork();
5455
$evm = $om->getEventManager();

0 commit comments

Comments
 (0)