Fix autofilter cloning across PHP versions
Avoid indirect access variable ambiguity across PHP 5.6 and PHP 7.0
This commit is contained in:
parent
39b8dbd0a1
commit
3bd0f6f985
|
@ -376,21 +376,19 @@ class Column
|
||||||
{
|
{
|
||||||
$vars = get_object_vars($this);
|
$vars = get_object_vars($this);
|
||||||
foreach ($vars as $key => $value) {
|
foreach ($vars as $key => $value) {
|
||||||
if (is_object($value)) {
|
if ($key === 'parent') {
|
||||||
if ($key == 'parent') {
|
|
||||||
// Detach from autofilter parent
|
// Detach from autofilter parent
|
||||||
$this->$key = null;
|
$this->parent = null;
|
||||||
} else {
|
} elseif ($key === 'ruleset') {
|
||||||
$this->$key = clone $value;
|
|
||||||
}
|
|
||||||
} elseif ((is_array($value)) && ($key == 'ruleset')) {
|
|
||||||
// The columns array of \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter objects
|
// The columns array of \PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter objects
|
||||||
$this->$key = [];
|
$this->ruleset = [];
|
||||||
foreach ($value as $k => $v) {
|
foreach ($value as $k => $v) {
|
||||||
$this->$key[$k] = clone $v;
|
$cloned = clone $v;
|
||||||
// attach the new cloned Rule to this new cloned Autofilter Cloned object
|
$cloned->setParent($this); // attach the new cloned Rule to this new cloned Autofilter Cloned object
|
||||||
$this->$key[$k]->setParent($this);
|
$this->ruleset[$k] = $cloned;
|
||||||
}
|
}
|
||||||
|
} elseif (is_object($value)) {
|
||||||
|
$this->$key = clone $value;
|
||||||
} else {
|
} else {
|
||||||
$this->$key = $value;
|
$this->$key = $value;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,9 +7,7 @@ use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter;
|
||||||
class ColumnTest extends \PHPUnit_Framework_TestCase
|
class ColumnTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
private $testInitialColumn = 'H';
|
private $testInitialColumn = 'H';
|
||||||
|
|
||||||
private $testAutoFilterColumnObject;
|
private $testAutoFilterColumnObject;
|
||||||
|
|
||||||
private $mockAutoFilterObject;
|
private $mockAutoFilterObject;
|
||||||
|
|
||||||
public function setUp()
|
public function setUp()
|
||||||
|
@ -111,7 +109,8 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testSetAttributes()
|
public function testSetAttributes()
|
||||||
{
|
{
|
||||||
$attributeSet = ['val' => 100,
|
$attributeSet = [
|
||||||
|
'val' => 100,
|
||||||
'maxVal' => 200,
|
'maxVal' => 200,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -122,7 +121,8 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAttributes()
|
public function testGetAttributes()
|
||||||
{
|
{
|
||||||
$attributeSet = ['val' => 100,
|
$attributeSet = [
|
||||||
|
'val' => 100,
|
||||||
'maxVal' => 200,
|
'maxVal' => 200,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -135,7 +135,8 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testSetAttribute()
|
public function testSetAttribute()
|
||||||
{
|
{
|
||||||
$attributeSet = ['val' => 100,
|
$attributeSet = [
|
||||||
|
'val' => 100,
|
||||||
'maxVal' => 200,
|
'maxVal' => 200,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -148,7 +149,8 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testGetAttribute()
|
public function testGetAttribute()
|
||||||
{
|
{
|
||||||
$attributeSet = ['val' => 100,
|
$attributeSet = [
|
||||||
|
'val' => 100,
|
||||||
'maxVal' => 200,
|
'maxVal' => 200,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -164,7 +166,13 @@ class ColumnTest extends \PHPUnit_Framework_TestCase
|
||||||
|
|
||||||
public function testClone()
|
public function testClone()
|
||||||
{
|
{
|
||||||
|
$originalRule = $this->testAutoFilterColumnObject->createRule();
|
||||||
$result = clone $this->testAutoFilterColumnObject;
|
$result = clone $this->testAutoFilterColumnObject;
|
||||||
$this->assertInstanceOf(AutoFilter\Column::class, $result);
|
$this->assertInstanceOf(AutoFilter\Column::class, $result);
|
||||||
|
$this->assertCount(1, $result->getRules());
|
||||||
|
$this->assertContainsOnlyInstancesOf(AutoFilter\Column\Rule::class, $result->getRules());
|
||||||
|
$clonedRule = $result->getRules()[0];
|
||||||
|
$this->assertNotSame($originalRule, $clonedRule);
|
||||||
|
$this->assertSame($result, $clonedRule->getParent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue