Skip to content

Commit

Permalink
Merge pull request #59 from Ocramius/fix/psr-container-v2-compatibility
Browse files Browse the repository at this point in the history
Adjusted built-in plugin managers for `psr/container:^2` compatibility
  • Loading branch information
Ocramius authored Jul 19, 2022
2 parents 382a317 + e79381f commit f2b852e
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 39 deletions.
49 changes: 47 additions & 2 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1359,13 +1359,21 @@
</MixedReturnStatement>
</file>
<file src="src/Reader/ExtensionManager.php">
<DeprecatedInterface occurrences="1">
<code>ExtensionManager</code>
</DeprecatedInterface>
<MixedInferredReturnType occurrences="1">
<code>Extension\AbstractEntry|Extension\AbstractFeed</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>$this-&gt;pluginManager-&gt;get($extension)</code>
</MixedReturnStatement>
</file>
<file src="src/Reader/ExtensionPluginManager.php">
<DeprecatedInterface occurrences="1">
<code>ExtensionPluginManager</code>
</DeprecatedInterface>
</file>
<file src="src/Reader/Feed/AbstractFeed.php">
<InvalidScalarArgument occurrences="1">
<code>$this-&gt;key()</code>
Expand Down Expand Up @@ -1842,6 +1850,11 @@
<code>trim($responseHtml)</code>
<code>trim($string)</code>
</ArgumentTypeCoercion>
<DeprecatedClass occurrences="3">
<code>ExtensionManagerInterface</code>
<code>ExtensionManagerInterface</code>
<code>null|ExtensionManagerInterface</code>
</DeprecatedClass>
<DocblockTypeContradiction occurrences="3">
<code>! static::$httpClient</code>
<code>gettype($response)</code>
Expand Down Expand Up @@ -1900,6 +1913,9 @@
</UndefinedVariable>
</file>
<file src="src/Reader/StandaloneExtensionManager.php">
<DeprecatedInterface occurrences="1">
<code>StandaloneExtensionManager</code>
</DeprecatedInterface>
<LessSpecificReturnStatement occurrences="1">
<code>new $class()</code>
</LessSpecificReturnStatement>
Expand Down Expand Up @@ -2627,13 +2643,25 @@
</TypeDoesNotContainType>
</file>
<file src="src/Writer/ExtensionManager.php">
<DeprecatedClass occurrences="2">
<code>?ExtensionManagerInterface</code>
<code>ExtensionManagerInterface</code>
</DeprecatedClass>
<DeprecatedInterface occurrences="1">
<code>ExtensionManager</code>
</DeprecatedInterface>
<MixedInferredReturnType occurrences="1">
<code>Extension\AbstractRenderer</code>
</MixedInferredReturnType>
<MixedReturnStatement occurrences="1">
<code>$this-&gt;pluginManager-&gt;get($extension)</code>
</MixedReturnStatement>
</file>
<file src="src/Writer/ExtensionPluginManager.php">
<DeprecatedInterface occurrences="1">
<code>ExtensionPluginManager</code>
</DeprecatedInterface>
</file>
<file src="src/Writer/Feed.php">
<InvalidStringClass occurrences="1">
<code>new $renderClass($this)</code>
Expand Down Expand Up @@ -2769,15 +2797,18 @@
<code>$data['type']</code>
<code>$data['uri']</code>
</MixedArrayAccess>
<MixedAssignment occurrences="6">
<MixedAssignment occurrences="7">
<code>$cat</code>
<code>$content</code>
<code>$data</code>
<code>$data</code>
<code>$ext</code>
<code>$source</code>
<code>$tidy</code>
</MixedAssignment>
<MixedMethodCall occurrences="4">
<MixedMethodCall occurrences="6">
<code>cleanRepair</code>
<code>parseString</code>
<code>render</code>
<code>setDomDocument</code>
<code>setRootElement</code>
Expand Down Expand Up @@ -3292,6 +3323,9 @@
</PropertyNotSetInConstructor>
</file>
<file src="src/Writer/StandaloneExtensionManager.php">
<DeprecatedInterface occurrences="1">
<code>StandaloneExtensionManager</code>
</DeprecatedInterface>
<MixedMethodCall occurrences="1">
<code>new $class()</code>
</MixedMethodCall>
Expand All @@ -3300,6 +3334,11 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Writer/Writer.php">
<DeprecatedClass occurrences="3">
<code>ExtensionManagerInterface</code>
<code>ExtensionManagerInterface</code>
<code>ExtensionManagerInterface</code>
</DeprecatedClass>
<MixedArgument occurrences="4">
<code>static::$extensions['entry']</code>
<code>static::$extensions['entryRenderer']</code>
Expand Down Expand Up @@ -4843,6 +4882,9 @@
</UndefinedInterfaceMethod>
</file>
<file src="test/Reader/TestAsset/CustomExtensionManager.php">
<DeprecatedInterface occurrences="1">
<code>CustomExtensionManager</code>
</DeprecatedInterface>
<LessSpecificReturnStatement occurrences="1">
<code>new $class()</code>
</LessSpecificReturnStatement>
Expand Down Expand Up @@ -5277,6 +5319,9 @@
</MixedAssignment>
</file>
<file src="test/Writer/TestAsset/CustomExtensionManager.php">
<DeprecatedInterface occurrences="1">
<code>CustomExtensionManager</code>
</DeprecatedInterface>
<MixedMethodCall occurrences="1">
<code>new $class()</code>
</MixedMethodCall>
Expand Down
6 changes: 4 additions & 2 deletions src/Reader/ExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
* Default implementation of ExtensionManagerInterface
*
* Decorator of ExtensionPluginManager.
*
* @final this class wasn't designed to be inherited from, but we can't assume that consumers haven't already
* extended it, therefore we cannot add the final marker without a new major release.
*/
class ExtensionManager implements ExtensionManagerInterface
{
Expand Down Expand Up @@ -67,9 +70,8 @@ public function get($extension)
* Do we have the named extension?
*
* @param string $extension
* @return bool
*/
public function has($extension)
public function has($extension): bool
{
return $this->pluginManager->has($extension);
}
Expand Down
26 changes: 11 additions & 15 deletions src/Reader/ExtensionManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@

namespace Laminas\Feed\Reader;

/**
* This interface exists to provide type inference for container implementations that retrieve extensions.
* Methods have been migrated from declared in PHP to being part of the docblock signature,
* in order to avoid conflicting with `psr/container` signatures, which are way stricter, and
* therefore incompatible with this one.
*
* @deprecated this interface is no longer needed, and shouldn't be relied upon
*
* @method has(string $extension): bool
* @method get(string $extension): mixed
*/
interface ExtensionManagerInterface
{
/**
* Do we have the extension?
*
* @param string $extension
* @return bool
*/
public function has($extension);

/**
* Retrieve the extension
*
* @param string $extension
* @return mixed
*/
public function get($extension);
}
2 changes: 2 additions & 0 deletions src/Reader/ExtensionPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
* Extension\AbstractFeed.
*
* @psalm-import-type FactoriesConfigurationType from ConfigInterface
* @final this class wasn't designed to be inherited from, but we can't assume that consumers haven't already
* extended it, therefore we cannot add the final marker without a new major release.
*/
class ExtensionPluginManager extends AbstractPluginManager implements ExtensionManagerInterface
{
Expand Down
7 changes: 5 additions & 2 deletions src/Reader/StandaloneExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
use function is_string;
use function sprintf;

/**
* @final this class wasn't designed to be inherited from, but we can't assume that consumers haven't already
* extended it, therefore we cannot add the final marker without a new major release.
*/
class StandaloneExtensionManager implements ExtensionManagerInterface
{
/** @var array<string, class-string> */
Expand Down Expand Up @@ -38,9 +42,8 @@ class StandaloneExtensionManager implements ExtensionManagerInterface
* Do we have the extension?
*
* @param string $extension
* @return bool
*/
public function has($extension)
public function has($extension): bool
{
return array_key_exists($extension, $this->extensions);
}
Expand Down
26 changes: 11 additions & 15 deletions src/Writer/ExtensionManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,17 @@

namespace Laminas\Feed\Writer;

/**
* This interface exists to provide type inference for container implementations that retrieve extensions.
* Methods have been migrated from declared in PHP to being part of the docblock signature,
* in order to avoid conflicting with `psr/container` signatures, which are way stricter, and
* therefore incompatible with this one.
*
* @deprecated this interface is no longer needed, and shouldn't be relied upon
*
* @method has(string $extension): bool
* @method get(string $extension): mixed
*/
interface ExtensionManagerInterface
{
/**
* Do we have the extension?
*
* @param string $extension
* @return bool
*/
public function has($extension);

/**
* Retrieve the extension
*
* @param string $extension
* @return mixed
*/
public function get($extension);
}
5 changes: 2 additions & 3 deletions test/Reader/TestAsset/CustomExtensionManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
* Standalone extension manager that omits any extensions added after the 2.9 series.
*/
class CustomExtensionManager implements ExtensionManagerInterface
final class CustomExtensionManager implements ExtensionManagerInterface
{
/** @var array<string, class-string> */
private $extensions = [
Expand All @@ -35,9 +35,8 @@ class CustomExtensionManager implements ExtensionManagerInterface
* Do we have the extension?
*
* @param string $extension
* @return bool
*/
public function has($extension)
public function has($extension): bool
{
return array_key_exists($extension, $this->extensions);
}
Expand Down

0 comments on commit f2b852e

Please sign in to comment.