Upgrade framework
This commit is contained in:
48
vendor/sebastian/global-state/src/Restorer.php
vendored
48
vendor/sebastian/global-state/src/Restorer.php
vendored
@@ -1,15 +1,23 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of the GlobalState package.
|
||||
* This file is part of sebastian/global-state.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace SebastianBergmann\GlobalState;
|
||||
|
||||
use function array_diff;
|
||||
use function array_key_exists;
|
||||
use function array_keys;
|
||||
use function array_merge;
|
||||
use function function_exists;
|
||||
use function get_defined_functions;
|
||||
use function in_array;
|
||||
use function is_array;
|
||||
use ReflectionClass;
|
||||
use ReflectionProperty;
|
||||
|
||||
/**
|
||||
@@ -20,11 +28,11 @@ class Restorer
|
||||
/**
|
||||
* Deletes function definitions that are not defined in a snapshot.
|
||||
*
|
||||
* @param Snapshot $snapshot
|
||||
* @throws RuntimeException when the uopz_delete() function is not available
|
||||
* @see https://github.com/krakjoe/uopz
|
||||
*
|
||||
* @see https://github.com/krakjoe/uopz
|
||||
*/
|
||||
public function restoreFunctions(Snapshot $snapshot)
|
||||
public function restoreFunctions(Snapshot $snapshot): void
|
||||
{
|
||||
if (!function_exists('uopz_delete')) {
|
||||
throw new RuntimeException('The uopz_delete() function is required for this operation');
|
||||
@@ -39,10 +47,8 @@ class Restorer
|
||||
|
||||
/**
|
||||
* Restores all global and super-global variables from a snapshot.
|
||||
*
|
||||
* @param Snapshot $snapshot
|
||||
*/
|
||||
public function restoreGlobalVariables(Snapshot $snapshot)
|
||||
public function restoreGlobalVariables(Snapshot $snapshot): void
|
||||
{
|
||||
$superGlobalArrays = $snapshot->superGlobalArrays();
|
||||
|
||||
@@ -53,10 +59,10 @@ class Restorer
|
||||
$globalVariables = $snapshot->globalVariables();
|
||||
|
||||
foreach (array_keys($GLOBALS) as $key) {
|
||||
if ($key != 'GLOBALS' &&
|
||||
!in_array($key, $superGlobalArrays) &&
|
||||
!$snapshot->blacklist()->isGlobalVariableBlacklisted($key)) {
|
||||
if (isset($globalVariables[$key])) {
|
||||
if ($key !== 'GLOBALS' &&
|
||||
!in_array($key, $superGlobalArrays, true) &&
|
||||
!$snapshot->excludeList()->isGlobalVariableExcluded($key)) {
|
||||
if (array_key_exists($key, $globalVariables)) {
|
||||
$GLOBALS[$key] = $globalVariables[$key];
|
||||
} else {
|
||||
unset($GLOBALS[$key]);
|
||||
@@ -67,13 +73,12 @@ class Restorer
|
||||
|
||||
/**
|
||||
* Restores all static attributes in user-defined classes from this snapshot.
|
||||
*
|
||||
* @param Snapshot $snapshot
|
||||
*/
|
||||
public function restoreStaticAttributes(Snapshot $snapshot)
|
||||
public function restoreStaticAttributes(Snapshot $snapshot): void
|
||||
{
|
||||
$current = new Snapshot($snapshot->blacklist(), false, false, false, false, true, false, false, false, false);
|
||||
$current = new Snapshot($snapshot->excludeList(), false, false, false, false, true, false, false, false, false);
|
||||
$newClasses = array_diff($current->classes(), $snapshot->classes());
|
||||
|
||||
unset($current);
|
||||
|
||||
foreach ($snapshot->staticAttributes() as $className => $staticAttributes) {
|
||||
@@ -85,7 +90,7 @@ class Restorer
|
||||
}
|
||||
|
||||
foreach ($newClasses as $className) {
|
||||
$class = new \ReflectionClass($className);
|
||||
$class = new ReflectionClass($className);
|
||||
$defaults = $class->getDefaultProperties();
|
||||
|
||||
foreach ($class->getProperties() as $attribute) {
|
||||
@@ -95,7 +100,7 @@ class Restorer
|
||||
|
||||
$name = $attribute->getName();
|
||||
|
||||
if ($snapshot->blacklist()->isStaticAttributeBlacklisted($className, $name)) {
|
||||
if ($snapshot->excludeList()->isStaticAttributeExcluded($className, $name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -111,11 +116,8 @@ class Restorer
|
||||
|
||||
/**
|
||||
* Restores a super-global variable array from this snapshot.
|
||||
*
|
||||
* @param Snapshot $snapshot
|
||||
* @param $superGlobalArray
|
||||
*/
|
||||
private function restoreSuperGlobalArray(Snapshot $snapshot, $superGlobalArray)
|
||||
private function restoreSuperGlobalArray(Snapshot $snapshot, string $superGlobalArray): void
|
||||
{
|
||||
$superGlobalVariables = $snapshot->superGlobalVariables();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user