Skip to content

Commit a63e97c

Browse files
authored
MutatingScope: prevent unnecessary scope re-creation after openssl* calls (#4854)
1 parent 4b55cbd commit a63e97c

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/Analyser/MutatingScope.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,8 @@ public function afterExtractCall(): self
514514

515515
public function afterClearstatcacheCall(): self
516516
{
517+
$changed = false;
518+
517519
$expressionTypes = $this->expressionTypes;
518520
$nativeExpressionTypes = $this->nativeExpressionTypes;
519521
foreach (array_keys($expressionTypes) as $exprString) {
@@ -547,10 +549,15 @@ public function afterClearstatcacheCall(): self
547549

548550
unset($expressionTypes[$exprString]);
549551
unset($nativeExpressionTypes[$exprString]);
552+
$changed = true;
550553
continue 2;
551554
}
552555
}
553556

557+
if (!$changed) {
558+
return $this;
559+
}
560+
554561
return $this->scopeFactory->create(
555562
$this->context,
556563
$this->isDeclareStrictTypes(),
@@ -576,6 +583,15 @@ public function afterOpenSslCall(string $openSslFunctionName): self
576583
$expressionTypes = $this->expressionTypes;
577584
$nativeExpressionTypes = $this->nativeExpressionTypes;
578585

586+
$errorStringFunction = '\openssl_error_string()';
587+
if (
588+
!array_key_exists($errorStringFunction, $expressionTypes)
589+
&& !array_key_exists($errorStringFunction, $nativeExpressionTypes)
590+
) {
591+
return $this;
592+
}
593+
594+
$changed = false;
579595
if (in_array($openSslFunctionName, [
580596
'openssl_cipher_iv_length',
581597
'openssl_cms_decrypt',
@@ -631,8 +647,13 @@ public function afterOpenSslCall(string $openSslFunctionName): self
631647
'openssl_x509_read',
632648
'openssl_x509_verify',
633649
], true)) {
634-
unset($expressionTypes['\openssl_error_string()']);
635-
unset($nativeExpressionTypes['\openssl_error_string()']);
650+
unset($expressionTypes[$errorStringFunction]);
651+
unset($nativeExpressionTypes[$errorStringFunction]);
652+
$changed = true;
653+
}
654+
655+
if (!$changed) {
656+
return $this;
636657
}
637658

638659
return $this->scopeFactory->create(

0 commit comments

Comments
 (0)