fix:repo cleanup
This commit is contained in:
+27
-11
@@ -96,7 +96,11 @@ final class Snapshot
|
||||
|
||||
public function __construct(?ExcludeList $excludeList = null, bool $includeGlobalVariables = true, bool $includeStaticProperties = true, bool $includeConstants = true, bool $includeFunctions = true, bool $includeClasses = true, bool $includeInterfaces = true, bool $includeTraits = true, bool $includeIniSettings = true, bool $includeIncludedFiles = true)
|
||||
{
|
||||
$this->excludeList = $excludeList ?: new ExcludeList;
|
||||
if ($excludeList === null) {
|
||||
$excludeList = new ExcludeList;
|
||||
}
|
||||
|
||||
$this->excludeList = $excludeList;
|
||||
|
||||
if ($includeConstants) {
|
||||
$this->snapshotConstants();
|
||||
@@ -128,6 +132,7 @@ final class Snapshot
|
||||
|
||||
assert($iniSettings !== false);
|
||||
|
||||
/* @phpstan-ignore assign.propertyType */
|
||||
$this->iniSettings = $iniSettings;
|
||||
}
|
||||
|
||||
@@ -290,10 +295,11 @@ final class Snapshot
|
||||
foreach (array_keys($GLOBALS) as $key) {
|
||||
if ($key !== 'GLOBALS' &&
|
||||
!in_array($key, $superGlobalArrays, true) &&
|
||||
$this->canBeSerialized($GLOBALS[$key]) &&
|
||||
!$this->excludeList->isGlobalVariableExcluded($key)) {
|
||||
/* @noinspection UnserializeExploitsInspection */
|
||||
$this->globalVariables[$key] = unserialize(serialize($GLOBALS[$key]));
|
||||
!$this->excludeList->isGlobalVariableExcluded($key) &&
|
||||
$this->canBeSerialized($GLOBALS[$key])
|
||||
) {
|
||||
/* @phpstan-ignore assign.propertyType */
|
||||
$this->globalVariables[$key] = $this->copyWithSerialize($GLOBALS[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -304,8 +310,8 @@ final class Snapshot
|
||||
|
||||
if (isset($GLOBALS[$superGlobalArray]) && is_array($GLOBALS[$superGlobalArray])) {
|
||||
foreach ($GLOBALS[$superGlobalArray] as $key => $value) {
|
||||
/* @noinspection UnserializeExploitsInspection */
|
||||
$this->superGlobalVariables[$superGlobalArray][$key] = unserialize(serialize($value));
|
||||
/* @phpstan-ignore assign.propertyType */
|
||||
$this->superGlobalVariables[$superGlobalArray][$key] = $this->copyWithSerialize($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -331,13 +337,12 @@ final class Snapshot
|
||||
$value = $property->getValue();
|
||||
|
||||
if ($this->canBeSerialized($value)) {
|
||||
/* @noinspection UnserializeExploitsInspection */
|
||||
$snapshot[$name] = unserialize(serialize($value));
|
||||
$snapshot[$name] = $this->copyWithSerialize($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($snapshot)) {
|
||||
if ($snapshot !== []) {
|
||||
$this->staticProperties[$className] = $snapshot;
|
||||
}
|
||||
}
|
||||
@@ -356,6 +361,16 @@ final class Snapshot
|
||||
];
|
||||
}
|
||||
|
||||
private function copyWithSerialize(mixed $variable): mixed
|
||||
{
|
||||
if (is_scalar($variable) || $variable === null) {
|
||||
return $variable;
|
||||
}
|
||||
|
||||
/* @noinspection UnserializeExploitsInspection */
|
||||
return unserialize(serialize($variable));
|
||||
}
|
||||
|
||||
private function canBeSerialized(mixed $variable): bool
|
||||
{
|
||||
if (is_scalar($variable) || $variable === null) {
|
||||
@@ -396,7 +411,8 @@ final class Snapshot
|
||||
{
|
||||
$result = [];
|
||||
|
||||
if ($processed->contains($variable)) {
|
||||
/* @phpstan-ignore argument.type */
|
||||
if ($processed->contains($variable) !== false) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user