Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix psalm reported issues. Fix type errors in invalid serialize methods #69

Merged
merged 1 commit into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 29 additions & 39 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.16.0@2897ba636551a8cb61601cc26f6ccfbba6c36591">
<file src="src/Collector/AbstractCollector.php">
<MethodSignatureMustProvideReturnType>
<code>serialize</code>
<code>unserialize</code>
</MethodSignatureMustProvideReturnType>
<MissingConstructor>
<code>$data</code>
<code>$data</code>
Expand All @@ -9,7 +13,7 @@
<code>$data</code>
</MissingConstructor>
<MixedAssignment>
<code><![CDATA[$this->data]]></code>
<code>$data</code>
</MixedAssignment>
</file>
<file src="src/Collector/CollectorInterface.php">
Expand All @@ -21,28 +25,25 @@
<DocblockTypeContradiction>
<code><![CDATA[! $application = $mvcEvent->getApplication()]]></code>
</DocblockTypeContradiction>
<MethodSignatureMustProvideReturnType>
<code>serialize</code>
<code>unserialize</code>
</MethodSignatureMustProvideReturnType>
<MissingReturnType>
<code>collect</code>
</MissingReturnType>
<MixedArgument>
<code><![CDATA[$serviceLocator->get('ApplicationConfig')]]></code>
<code><![CDATA[$serviceLocator->get('config')]]></code>
</MixedArgument>
<MixedArrayAccess>
<code><![CDATA[$data['applicationConfig']]]></code>
<code><![CDATA[$data['config']]]></code>
</MixedArrayAccess>
<MixedArrayOffset>
<code>$serializable[$key]</code>
<code>$serializable[$key]</code>
<code>$serializable[$key]</code>
</MixedArrayOffset>
<MixedAssignment>
<code>$data</code>
<code>$key</code>
<code>$serializable[$key]</code>
<code><![CDATA[$this->applicationConfig]]></code>
<code><![CDATA[$this->config]]></code>
<code>$unserialized[$key]</code>
<code>$value</code>
<code>$value</code>
Expand All @@ -58,21 +59,12 @@
<PossiblyInvalidArgument>
<code>$value</code>
</PossiblyInvalidArgument>
<PossiblyUnusedMethod>
<code>getApplicationConfig</code>
<code>getConfig</code>
</PossiblyUnusedMethod>
</file>
<file src="src/Collector/DbCollector.php">
<InvalidReturnStatement>
<code><![CDATA[count($this->profiler->getQueryProfiles($mode))]]></code>
</InvalidReturnStatement>
<InvalidReturnType>
<code>self</code>
</InvalidReturnType>
<MissingConstructor>
<code>$profiler</code>
</MissingConstructor>
<MethodSignatureMustProvideReturnType>
<code>serialize</code>
<code>unserialize</code>
</MethodSignatureMustProvideReturnType>
<MissingReturnType>
<code>collect</code>
</MissingReturnType>
Expand All @@ -81,7 +73,6 @@
</MixedArgument>
<MixedAssignment>
<code>$query</code>
<code><![CDATA[$this->profiler]]></code>
<code>$time</code>
</MixedAssignment>
<MixedInferredReturnType>
Expand All @@ -97,6 +88,9 @@
<MixedReturnStatement>
<code>$time</code>
</MixedReturnStatement>
<PossiblyNullReference>
<code>getQueryProfiles</code>
</PossiblyNullReference>
<PossiblyUnusedMethod>
<code>getProfiler</code>
<code>getQueryTime</code>
Expand All @@ -106,17 +100,15 @@
<PossiblyUnusedParam>
<code>$profiler</code>
</PossiblyUnusedParam>
<RedundantPropertyInitializationCheck>
<code><![CDATA[isset($this->profiler)]]></code>
</RedundantPropertyInitializationCheck>
<UndefinedClass>
<code>Profiler</code>
<code>Profiler</code>
</UndefinedClass>
<UndefinedDocblockClass>
<code><![CDATA[$this->profiler]]></code>
<code><![CDATA[$this->profiler]]></code>
<code>Profiler</code>
<code>Profiler</code>
<code>null|Profiler</code>
<code>null|Profiler</code>
</UndefinedDocblockClass>
</file>
<file src="src/Collector/EventCollectorInterface.php">
Expand Down Expand Up @@ -257,7 +249,6 @@
<code>collect</code>
</MissingReturnType>
<MixedArgument>
<code>$child</code>
<code>$controller</code>
<code>$controller</code>
<code><![CDATA[$this->data['action']]]></code>
Expand All @@ -266,7 +257,6 @@
<code>$views[]</code>
</MixedArrayAssignment>
<MixedAssignment>
<code>$child</code>
<code>$controller</code>
<code>$var</code>
</MixedAssignment>
Expand Down Expand Up @@ -406,6 +396,10 @@
</UnusedClass>
</file>
<file src="src/Exception/SerializableException.php">
<MethodSignatureMustProvideReturnType>
<code>serialize</code>
<code>unserialize</code>
</MethodSignatureMustProvideReturnType>
<MixedArgument>
<code><![CDATA[$entry['args']]]></code>
<code><![CDATA[$entry['class']]]></code>
Expand Down Expand Up @@ -734,13 +728,19 @@
<code>setProfiler</code>
<code>setToolbar</code>
</MissingReturnType>
<MissingTemplateParam>
<code>Options</code>
</MissingTemplateParam>
<MixedArgument>
<code><![CDATA[$options['collectors']]]></code>
<code><![CDATA[$options['identifiers']]]></code>
<code>$value</code>
<code>$value</code>
<code>$value</code>
</MixedArgument>
<MixedArgumentTypeCoercion>
<code>$options</code>
</MixedArgumentTypeCoercion>
<MixedArrayAccess>
<code><![CDATA[$this->events['collectors'][$name]]]></code>
<code><![CDATA[$this->events['identifiers'][$name]]]></code>
Expand Down Expand Up @@ -796,9 +796,6 @@
<MixedStringOffsetAssignment>
<code><![CDATA[$this->toolbar[$key][$collector]]]></code>
</MixedStringOffsetAssignment>
<PossiblyInvalidArgument>
<code>$options</code>
</PossiblyInvalidArgument>
<PossiblyUnusedMethod>
<code>canFlushEarly</code>
<code>eventCollectionEnabled</code>
Expand All @@ -807,10 +804,6 @@
<code>setEvents</code>
<code>setProfiler</code>
</PossiblyUnusedMethod>
<PossiblyUnusedParam>
<code>$options</code>
<code>$report</code>
</PossiblyUnusedParam>
<TypeDoesNotContainType>
<code>is_array($options)</code>
<code>is_array($options)</code>
Expand All @@ -825,9 +818,6 @@
<code>TimeCollector</code>
<code>TimeCollector</code>
</UndefinedClass>
<UndefinedDocblockClass>
<code>array|Traversable|null</code>
</UndefinedDocblockClass>
</file>
<file src="src/Profiler.php">
<ImplementedReturnTypeMismatch>
Expand Down
15 changes: 10 additions & 5 deletions src/Collector/AbstractCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use Serializable;

use function assert;
use function is_array;
use function serialize;
use function unserialize;

Expand All @@ -22,11 +24,11 @@ abstract class AbstractCollector implements CollectorInterface, Serializable
protected $data;

/**
* @return string
* @return array
*/
public function __serialize()
{
return serialize($this->data);
return ['data' => $this->data];
}

/**
Expand All @@ -37,16 +39,17 @@ public function __serialize()
*/
public function serialize()
{
return $this->__serialize();
return serialize($this->__serialize());
}

/**
* @param string $data
* @param array $data
* @return void
*/
public function __unserialize($data)
{
$this->data = unserialize($data);
assert(isset($data['data']) && is_array($data['data']));
$this->data = $data['data'];
}

/**
Expand All @@ -57,6 +60,8 @@ public function __unserialize($data)
*/
public function unserialize($data)
{
$data = unserialize($data);
assert(is_array($data));
$this->__unserialize($data);
}
}
21 changes: 14 additions & 7 deletions src/Collector/ConfigCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Serializable;
use Traversable;

use function array_key_exists;
use function assert;
use function is_array;
use function serialize;
use function unserialize;
Expand Down Expand Up @@ -82,11 +84,11 @@ public function getApplicationConfig()
}

/**
* @return string
* @return array
*/
public function __serialize()
{
return serialize(['config' => $this->config, 'applicationConfig' => $this->applicationConfig]);
return ['config' => $this->config, 'applicationConfig' => $this->applicationConfig];
}

/**
Expand All @@ -97,16 +99,19 @@ public function __serialize()
*/
public function serialize()
{
return $this->__serialize();
return serialize($this->__serialize());
}

/**
* @param string $serialized
* @param array $data
* @return void
*/
public function __unserialize($serialized)
public function __unserialize($data)
{
$data = unserialize($serialized);
assert(array_key_exists('config', $data));
assert($data['config'] === null || is_array($data['config']));
assert(array_key_exists('applicationConfig', $data));
assert($data['applicationConfig'] === null || is_array($data['applicationConfig']));
$this->config = $data['config'];
$this->applicationConfig = $data['applicationConfig'];
}
Expand All @@ -119,7 +124,9 @@ public function __unserialize($serialized)
*/
public function unserialize($serialized)
{
$this->__unserialize($serialized);
$data = unserialize($serialized);
assert(is_array($data));
$this->__unserialize($data);
}

/**
Expand Down
Loading