Skip to content

Commit

Permalink
Merge pull request #41 from laminas/3.6.x-merge-up-into-3.7.x_4hAC5nAH
Browse files Browse the repository at this point in the history
Merge release 3.6.2 into 3.7.x
  • Loading branch information
Ocramius authored Dec 8, 2021
2 parents cc8b4db + 6fe0842 commit ca01d74
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 45 deletions.
72 changes: 67 additions & 5 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@
<code>$this-&gt;storage[$key]</code>
<code>$this-&gt;storage[$key]</code>
</MixedArrayOffset>
<MixedAssignment occurrences="2">
<MixedAssignment occurrences="4">
<code>$flag</code>
<code>$ret</code>
<code>$ret</code>
<code>$v</code>
</MixedAssignment>
<MoreSpecificReturnType occurrences="1">
<code>Iterator</code>
Expand All @@ -58,6 +60,14 @@
<code>is_callable($function)</code>
<code>is_callable($function)</code>
</RedundantConditionGivenDocblockType>
<UndefinedAttributeClass occurrences="6">
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
</UndefinedAttributeClass>
</file>
<file src="src/ArrayUtils.php">
<DocblockTypeContradiction occurrences="1">
Expand Down Expand Up @@ -158,6 +168,14 @@
<code>$this-&gt;values</code>
<code>$this-&gt;values</code>
</PossiblyNullArrayOffset>
<UndefinedAttributeClass occurrences="6">
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
</UndefinedAttributeClass>
</file>
<file src="src/Glob.php">
<InvalidOperand occurrences="2">
Expand Down Expand Up @@ -205,6 +223,9 @@
<MixedAssignment occurrences="1">
<code>$this[$name]</code>
</MixedAssignment>
<UndefinedAttributeClass occurrences="1">
<code>ReturnTypeWillChange</code>
</UndefinedAttributeClass>
</file>
<file src="src/PriorityList.php">
<InvalidReturnStatement occurrences="1">
Expand All @@ -223,6 +244,14 @@
<code>(int) $priority</code>
<code>(int) $priority</code>
</RedundantCastGivenDocblockType>
<UndefinedAttributeClass occurrences="6">
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
</UndefinedAttributeClass>
</file>
<file src="src/PriorityQueue.php">
<DocblockTypeContradiction occurrences="1">
Expand Down Expand Up @@ -292,6 +321,10 @@
<RedundantConditionGivenDocblockType occurrences="1">
<code>null !== $this-&gt;queue</code>
</RedundantConditionGivenDocblockType>
<UndefinedAttributeClass occurrences="2">
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
</UndefinedAttributeClass>
</file>
<file src="src/SplPriorityQueue.php">
<ImplementedReturnTypeMismatch occurrences="1">
Expand All @@ -305,7 +338,6 @@
<code>$data[]</code>
<code>$item</code>
<code>$item</code>
<code>$item</code>
</MixedAssignment>
</file>
<file src="src/SplQueue.php">
Expand All @@ -314,13 +346,25 @@
<code>$item</code>
<code>$item</code>
</MixedAssignment>
<UndefinedAttributeClass occurrences="4">
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
</UndefinedAttributeClass>
</file>
<file src="src/SplStack.php">
<MixedAssignment occurrences="3">
<code>$array[]</code>
<code>$item</code>
<code>$item</code>
</MixedAssignment>
<UndefinedAttributeClass occurrences="4">
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
<code>ReturnTypeWillChange</code>
</UndefinedAttributeClass>
</file>
<file src="src/StringUtils.php">
<DocblockTypeContradiction occurrences="2">
Expand Down Expand Up @@ -377,9 +421,7 @@
</RedundantCastGivenDocblockType>
</file>
<file src="src/StringWrapper/Iconv.php">
<PossiblyNullArgument occurrences="4">
<code>$length</code>
<code>$this-&gt;getEncoding()</code>
<PossiblyNullArgument occurrences="2">
<code>$this-&gt;getEncoding()</code>
<code>$this-&gt;getEncoding()</code>
</PossiblyNullArgument>
Expand Down Expand Up @@ -424,6 +466,12 @@
<code>$ar['foo']['bar']</code>
<code>$ar['foo']['bar']</code>
</MixedArrayAccess>
<MixedAssignment occurrences="1">
<code>$unserialized</code>
</MixedAssignment>
<MixedMethodCall occurrences="1">
<code>isImmutable</code>
</MixedMethodCall>
<RedundantConditionGivenDocblockType occurrences="1">
<code>assertSame</code>
</RedundantConditionGivenDocblockType>
Expand Down Expand Up @@ -500,6 +548,20 @@
<code>$this-&gt;helper</code>
</UndefinedThisPropertyFetch>
</file>
<file src="test/CustomArrayObject.php">
<MissingPropertyType occurrences="1">
<code>$isImmutable</code>
</MissingPropertyType>
<MixedInferredReturnType occurrences="1">
<code>bool</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>$this-&gt;isImmutable</code>
</MixedReturnStatement>
<PropertyNotSetInConstructor occurrences="1">
<code>CustomArrayObject</code>
</PropertyNotSetInConstructor>
</file>
<file src="test/ErrorHandlerTest.php">
<ArgumentTypeCoercion occurrences="3">
<code>'ErrorException'</code>
Expand Down
81 changes: 41 additions & 40 deletions src/ArrayObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Serializable;
use UnexpectedValueException;

use function array_key_exists;
use function array_keys;
use function asort;
use function class_exists;
Expand Down Expand Up @@ -92,7 +93,7 @@ public function __isset($key)
}

if (in_array($key, $this->protectedProperties)) {
throw new Exception\InvalidArgumentException('$key is a protected property, use a different key');
throw new Exception\InvalidArgumentException("$key is a protected property, use a different key");
}

return isset($this->$key);
Expand All @@ -113,7 +114,7 @@ public function __set($key, $value)
}

if (in_array($key, $this->protectedProperties)) {
throw new Exception\InvalidArgumentException('$key is a protected property, use a different key');
throw new Exception\InvalidArgumentException("$key is a protected property, use a different key");
}

$this->$key = $value;
Expand All @@ -133,7 +134,7 @@ public function __unset($key)
}

if (in_array($key, $this->protectedProperties)) {
throw new Exception\InvalidArgumentException('$key is a protected property, use a different key');
throw new Exception\InvalidArgumentException("$key is a protected property, use a different key");
}

unset($this->$key);
Expand All @@ -154,7 +155,7 @@ public function &__get($key)
}

if (in_array($key, $this->protectedProperties, true)) {
throw new Exception\InvalidArgumentException('$key is a protected property, use a different key');
throw new Exception\InvalidArgumentException("$key is a protected property, use a different key");
}

return $this->$key;
Expand Down Expand Up @@ -462,43 +463,43 @@ public function __unserialize($data)
{
$this->protectedProperties = array_keys(get_object_vars($this));

foreach ($data as $k => $v) {
switch ($k) {
case 'flag':
$this->setFlags((int) $v);
break;

case 'storage':
if (! is_array($v) && ! is_object($v)) {
throw new UnexpectedValueException(sprintf(
'Cannot deserialize %s instance: corrupt storage data;'
. ' expected array or object, received %s',
self::class,
gettype($v)
));
}

$this->exchangeArray($v);
break;

case 'iteratorClass':
if (! is_string($v)) {
throw new UnexpectedValueException(sprintf(
'Cannot deserialize %s instance: invalid iteratorClass; expected string, received %s',
self::class,
is_object($v) ? get_class($v) : gettype($v)
));
}

$this->setIteratorClass($v);
break;

case 'protectedProperties':
break;

default:
$this->__set($k, $v);
// Unserialize protected internal properties first
if (array_key_exists('flag', $data)) {
$this->setFlags((int) $data['flag']);
unset($data['flag']);
}

if (array_key_exists('storage', $data)) {
if (! is_array($data['storage']) && ! is_object($data['storage'])) {
throw new UnexpectedValueException(sprintf(
'Cannot deserialize %s instance: corrupt storage data; expected array or object, received %s',
self::class,
gettype($data['storage'])
));
}
$this->exchangeArray($data['storage']);
unset($data['storage']);
}

if (array_key_exists('iteratorClass', $data)) {
if (! is_string($data['iteratorClass'])) {
throw new UnexpectedValueException(sprintf(
'Cannot deserialize %s instance: invalid iteratorClass; expected string, received %s',
self::class,
is_object($data['iteratorClass'])
? get_class($data['iteratorClass'])
: gettype($data['iteratorClass'])
));
}
$this->setIteratorClass($data['iteratorClass']);
unset($data['iteratorClass']);
}

unset($data['protectedProperties']);

// Unserialize array keys after resolving protected properties to ensure configuration is used.
foreach ($data as $k => $v) {
$this->__set($k, $v);
}
}
}
11 changes: 11 additions & 0 deletions test/ArrayObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,4 +401,15 @@ public function testSerializationRestoresProperties(): void

self::assertEquals($ar, unserialize(serialize($ar)));
}

public function testSerializationRestoresProtectedProperties(): void
{
$ar = new CustomArrayObject([], ArrayObject::ARRAY_AS_PROPS);
self::assertTrue($ar->isImmutable());

$serialized = serialize($ar);
$unserialized = unserialize($serialized);

self::assertTrue($unserialized->isImmutable());
}
}
18 changes: 18 additions & 0 deletions test/CustomArrayObject.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

declare(strict_types=1);

namespace LaminasTest\Stdlib;

use Laminas\Stdlib\ArrayObject;

final class CustomArrayObject extends ArrayObject
{
/** @var bool */
protected $isImmutable = true;

public function isImmutable(): bool
{
return $this->isImmutable;
}
}

0 comments on commit ca01d74

Please sign in to comment.