Skip to content

Commit

Permalink
Fix newly detected psalm issues updating to ServiceManager 3.14
Browse files Browse the repository at this point in the history
Signed-off-by: George Steel <[email protected]>
  • Loading branch information
gsteel committed Jul 18, 2022
1 parent d910177 commit 6f599ed
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
17 changes: 0 additions & 17 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1850,9 +1850,6 @@
<ImplementedReturnTypeMismatch occurrences="1">
<code>Feed\FeedInterface</code>
</ImplementedReturnTypeMismatch>
<InvalidNullableReturnType occurrences="1">
<code>ExtensionManagerInterface</code>
</InvalidNullableReturnType>
<InvalidReturnStatement occurrences="1">
<code>$reader</code>
</InvalidReturnStatement>
Expand All @@ -1876,9 +1873,6 @@
<code>$value</code>
<code>$version</code>
</MixedAssignment>
<NullableReturnStatement occurrences="1">
<code>static::$extensionManager</code>
</NullableReturnStatement>
<RedundantCastGivenDocblockType occurrences="3">
<code>(int) $response-&gt;getStatusCode()</code>
<code>(int) $response-&gt;getStatusCode()</code>
Expand Down Expand Up @@ -2640,17 +2634,6 @@
<code>$this-&gt;pluginManager-&gt;get($extension)</code>
</MixedReturnStatement>
</file>
<file src="src/Writer/ExtensionPluginManager.php">
<MixedArgument occurrences="1">
<code>$plugin</code>
</MixedArgument>
<RedundantCondition occurrences="1">
<code>is_object($instance)</code>
</RedundantCondition>
<TypeDoesNotContainType occurrences="1">
<code>gettype($instance)</code>
</TypeDoesNotContainType>
</file>
<file src="src/Writer/Feed.php">
<InvalidStringClass occurrences="1">
<code>new $renderClass($this)</code>
Expand Down
29 changes: 19 additions & 10 deletions src/Reader/ExtensionPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

namespace Laminas\Feed\Reader;

use Laminas\Feed\Reader\Extension\AbstractEntry;
use Laminas\Feed\Reader\Extension\AbstractFeed;
use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\ConfigInterface;
use Laminas\ServiceManager\Exception\InvalidServiceException;
use Laminas\ServiceManager\Factory\InvokableFactory;

Expand All @@ -19,6 +22,8 @@
*
* Validation checks that we have an Extension\AbstractEntry or
* Extension\AbstractFeed.
*
* @psalm-import-type FactoriesConfigurationType from ConfigInterface
*/
class ExtensionPluginManager extends AbstractPluginManager implements ExtensionManagerInterface
{
Expand Down Expand Up @@ -136,6 +141,7 @@ class ExtensionPluginManager extends AbstractPluginManager implements ExtensionM
* Factories for default set of extension classes
*
* @var array<array-key, callable|string>
* @psalm-var FactoriesConfigurationType
*/
protected $factories = [
Extension\Atom\Entry::class => InvokableFactory::class,
Expand Down Expand Up @@ -180,6 +186,8 @@ class ExtensionPluginManager extends AbstractPluginManager implements ExtensionM
/**
* Do not share instances (v2)
*
* @deprecated
*
* @var bool
*/
protected $shareByDefault = false;
Expand All @@ -203,25 +211,27 @@ class ExtensionPluginManager extends AbstractPluginManager implements ExtensionM
public function validate($instance)
{
if (
$instance instanceof Extension\AbstractEntry
|| $instance instanceof Extension\AbstractFeed
$instance instanceof AbstractEntry
|| $instance instanceof AbstractFeed
) {
// we're okay
return;
}

throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s\Extension\AbstractFeed '
. 'or %s\Extension\AbstractEntry',
'Plugin of type %s is invalid; must implement %s or %s',
is_object($instance) ? get_class($instance) : gettype($instance),
__NAMESPACE__,
__NAMESPACE__
AbstractEntry::class,
AbstractFeed::class
));
}

/**
* Validate the plugin (v2)
*
* @deprecated Since 2.18.0 This component is no longer compatible with service manager v2 series.
* This method will be removed in version 3.0 of this component
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidArgumentException If invalid.
Expand All @@ -232,11 +242,10 @@ public function validatePlugin($plugin)
$this->validate($plugin);
} catch (InvalidServiceException $e) {
throw new Exception\InvalidArgumentException(sprintf(
'Plugin of type %s is invalid; must implement %s\Extension\AbstractFeed '
. 'or %s\Extension\AbstractEntry',
'Plugin of type %s is invalid; must implement %s or %s',
is_object($plugin) ? get_class($plugin) : gettype($plugin),
__NAMESPACE__,
__NAMESPACE__
AbstractEntry::class,
AbstractFeed::class
));
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/Reader/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -605,10 +605,13 @@ public static function setExtensionManager(ExtensionManagerInterface $extensionM
*/
public static function getExtensionManager()
{
if (! isset(static::$extensionManager)) {
static::setExtensionManager(new StandaloneExtensionManager());
$manager = static::$extensionManager;
if (! $manager instanceof ExtensionManagerInterface) {
$manager = new StandaloneExtensionManager();
static::setExtensionManager($manager);
}
return static::$extensionManager;

return $manager;
}

/**
Expand Down
11 changes: 7 additions & 4 deletions src/Writer/ExtensionPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Laminas\Feed\Writer;

use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\ConfigInterface;
use Laminas\ServiceManager\Exception\InvalidServiceException;
use Laminas\ServiceManager\Factory\InvokableFactory;

Expand All @@ -18,6 +19,8 @@
* Plugin manager implementation for feed writer extensions
*
* Validation checks that we have an Entry, Feed, or Extension\AbstractRenderer.
*
* @psalm-import-type FactoriesConfigurationType from ConfigInterface
*/
class ExtensionPluginManager extends AbstractPluginManager implements ExtensionManagerInterface
{
Expand Down Expand Up @@ -169,7 +172,7 @@ class ExtensionPluginManager extends AbstractPluginManager implements ExtensionM
/**
* Factories for default set of extension classes
*
* @var array<array-key, callable|string>
* @var FactoriesConfigurationType
*/
protected $factories = [
Extension\Atom\Renderer\Feed::class => InvokableFactory::class,
Expand Down Expand Up @@ -234,7 +237,7 @@ class ExtensionPluginManager extends AbstractPluginManager implements ExtensionM
*
* Checks that the extension loaded is of a valid type.
*
* @param object $instance
* @param mixed $instance
* @return void
* @throws InvalidServiceException If invalid.
*/
Expand All @@ -245,12 +248,12 @@ public function validate($instance)
return;
}

if ('Feed' === substr(get_class($instance), -4)) {
if (is_object($instance) && 'Feed' === substr(get_class($instance), -4)) {
// we're okay
return;
}

if ('Entry' === substr(get_class($instance), -5)) {
if (is_object($instance) && 'Entry' === substr(get_class($instance), -5)) {
// we're okay
return;
}
Expand Down

0 comments on commit 6f599ed

Please sign in to comment.