diff --git a/core/Plugin.php b/core/Plugin.php index e4c6e303357..fea7d585d9d 100644 --- a/core/Plugin.php +++ b/core/Plugin.php @@ -350,8 +350,11 @@ final public function getPluginName() * given subclass. If the requested file exists but does not extend this class * a warning will be shown to advice a developer to extend this certain class. * - * @return string|null Null if the requested component does not exist or an instance of the found - * component. + * @template T of object + * @phpstan-param class-string|''|false|null $expectedSubclass + * + * @return class-string|null Null if the requested component does not exist, + * or the class string of the found component. */ public function findComponent($componentName, $expectedSubclass) { @@ -405,6 +408,11 @@ public function findComponent($componentName, $expectedSubclass) return $classname; } + /** + * @template T of object + * @param class-string|''|false|null $expectedSubclass + * @return array> + */ public function findMultipleComponents($directoryWithinPlugin, $expectedSubclass) { $this->createCacheIfNeeded(); @@ -602,9 +610,9 @@ public function getPluginLastDeactivationTime() } /** - * @param $directoryWithinPlugin - * @param $expectedSubclass - * @return array + * @template T of object + * @param class-string|''|false|null $expectedSubclass + * @return array> */ private function doFindMultipleComponents($directoryWithinPlugin, $expectedSubclass) { diff --git a/core/Plugin/ComponentFactory.php b/core/Plugin/ComponentFactory.php index 0be8827ce4a..954fbc3ab4b 100644 --- a/core/Plugin/ComponentFactory.php +++ b/core/Plugin/ComponentFactory.php @@ -31,10 +31,14 @@ class ComponentFactory * `"GetKeywords"`. * @param string $componentTypeClass The fully qualified class name of the component type, eg, * `"Piwik\Plugin\Report"`. - * @return mixed|null A new instance of the desired component or null if not found. If the - * plugin is not loaded or activated or the component is not located in - * in the sub-namespace specified by `$componentTypeClass::COMPONENT_SUBNAMESPACE`, - * this method will return null. + * + * @template T of object + * @phpstan-param class-string $componentTypeClass + * + * @return T|null A new instance of the desired component or null if not found. If the + * plugin is not loaded or activated or the component is not located in + * in the sub-namespace specified by `$componentTypeClass::COMPONENT_SUBNAMESPACE`, + * this method will return null. */ public static function factory($pluginName, $componentClassSimpleName, $componentTypeClass) { @@ -82,8 +86,13 @@ public static function factory($pluginName, $componentClassSimpleName, $componen * `"Piwik\Plugin\Report"`. * @param string $pluginName|false The name of the plugin the component is expected to belong to, * eg, `'DevicesDetection'`. - * @param callback $predicate - * @return mixed The component that satisfies $predicate or null if not found. + * @param callable $predicate + * + * @template T of object + * @phpstan-param class-string $componentTypeClass + * @phpstan-param callable(T): bool $predicate + * + * @return T|null The component that satisfies $predicate or null if not found. */ public static function getComponentIf($componentTypeClass, $pluginName, $predicate) { diff --git a/core/Plugin/Manager.php b/core/Plugin/Manager.php index cfc01bd26d0..2def6996711 100644 --- a/core/Plugin/Manager.php +++ b/core/Plugin/Manager.php @@ -596,7 +596,10 @@ public function deactivatePlugin($pluginName) * given subclass. If the requested file exists but does not extend this class * a warning will be shown to advice a developer to extend this certain class. * - * @return \stdClass[] + * @template T of object + * @phpstan-param class-string|''|false|null $expectedSubclass + * + * @return array> */ public function findComponents($componentName, $expectedSubclass) { @@ -614,6 +617,11 @@ public function findComponents($componentName, $expectedSubclass) return $components; } + /** + * @template T of object + * @param class-string|''|false|null $expectedSubclass + * @return array> + */ public function findMultipleComponents($directoryWithinPlugin, $expectedSubclass) { $plugins = $this->getPluginsLoadedAndActivated(); diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 1d80862e97a..bbf84897893 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1680,11 +1680,6 @@ parameters: count: 3 path: core/Mail/EmailStyles.php - - - message: "#^Parameter \\#1 \\$name of static method Piwik\\\\Container\\\\StaticContainer\\:\\:get\\(\\) expects string, stdClass given\\.$#" - count: 1 - path: core/Measurable/Type/TypeManager.php - - message: "#^Default value of the parameter \\#8 \\$attribute \\(false\\) of method Piwik\\\\Menu\\\\MenuAbstract\\:\\:addItem\\(\\) is incompatible with type string\\.$#" count: 1 @@ -1700,11 +1695,6 @@ parameters: count: 1 path: core/Menu/MenuAbstract.php - - - message: "#^Parameter \\#1 \\$name of static method Piwik\\\\Container\\\\StaticContainer\\:\\:get\\(\\) expects string, stdClass given\\.$#" - count: 1 - path: core/Menu/MenuAbstract.php - - message: "#^Result of && is always false\\.$#" count: 3 @@ -1910,16 +1900,6 @@ parameters: count: 1 path: core/Plugin/ArchivedMetric.php - - - message: "#^Invoking callable on an unknown class Piwik\\\\Plugin\\\\callback\\.$#" - count: 1 - path: core/Plugin/ComponentFactory.php - - - - message: "#^Parameter \\$predicate of method Piwik\\\\Plugin\\\\ComponentFactory\\:\\:getComponentIf\\(\\) has invalid type Piwik\\\\Plugin\\\\callback\\.$#" - count: 1 - path: core/Plugin/ComponentFactory.php - - message: "#^Parameter \\#1 \\$numberOfSeconds of method Piwik\\\\Metrics\\\\Formatter\\:\\:getPrettyTimeFromSeconds\\(\\) expects int, \\(float\\|false\\) given\\.$#" count: 1 @@ -2025,11 +2005,6 @@ parameters: count: 1 path: core/Plugin/LogTablesProvider.php - - - message: "#^Method Piwik\\\\Plugin\\\\Manager\\:\\:findComponents\\(\\) should return array\\ but returns array\\, string\\>\\.$#" - count: 1 - path: core/Plugin/Manager.php - - message: "#^PHPDoc tag @throws has invalid value \\(\\)\\: Unexpected token \"\\\\n \", expected type at offset 55$#" count: 1 @@ -5578,11 +5553,6 @@ parameters: count: 1 path: plugins/Live/Reports/GetLastVisits.php - - - message: "#^Method Piwik\\\\Plugins\\\\Live\\\\Visitor\\:\\:getAllVisitorDetailsClasses\\(\\) should return array\\ but returns array\\\\.$#" - count: 1 - path: plugins/Live/Visitor.php - - message: "#^If condition is always true\\.$#" count: 1