Skip to content
Draft
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
18 changes: 13 additions & 5 deletions core/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>|''|false|null $expectedSubclass
*
* @return class-string<T>|null Null if the requested component does not exist,
* or the class string of the found component.
*/
public function findComponent($componentName, $expectedSubclass)
{
Expand Down Expand Up @@ -405,6 +408,11 @@ public function findComponent($componentName, $expectedSubclass)
return $classname;
}

/**
* @template T of object
* @param class-string<T>|''|false|null $expectedSubclass
* @return array<class-string<T>>
*/
public function findMultipleComponents($directoryWithinPlugin, $expectedSubclass)
{
$this->createCacheIfNeeded();
Expand Down Expand Up @@ -602,9 +610,9 @@ public function getPluginLastDeactivationTime()
}

/**
* @param $directoryWithinPlugin
* @param $expectedSubclass
* @return array
* @template T of object
* @param class-string<T>|''|false|null $expectedSubclass
* @return array<class-string<T>>
*/
private function doFindMultipleComponents($directoryWithinPlugin, $expectedSubclass)
{
Expand Down
21 changes: 15 additions & 6 deletions core/Plugin/ComponentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> $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)
{
Expand Down Expand Up @@ -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<T> $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)
{
Expand Down
10 changes: 9 additions & 1 deletion core/Plugin/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>|''|false|null $expectedSubclass
*
* @return array<class-string<T>>
*/
public function findComponents($componentName, $expectedSubclass)
{
Expand All @@ -614,6 +617,11 @@ public function findComponents($componentName, $expectedSubclass)
return $components;
}

/**
* @template T of object
* @param class-string<T>|''|false|null $expectedSubclass
* @return array<class-string<T>>
*/
public function findMultipleComponents($directoryWithinPlugin, $expectedSubclass)
{
$plugins = $this->getPluginsLoadedAndActivated();
Expand Down
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2025,11 +2005,6 @@ parameters:
count: 1
path: core/Plugin/LogTablesProvider.php

-
message: "#^Method Piwik\\\\Plugin\\\\Manager\\:\\:findComponents\\(\\) should return array\\<stdClass\\> but returns array\\<int\\<0, max\\>, 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
Expand Down Expand Up @@ -5578,11 +5553,6 @@ parameters:
count: 1
path: plugins/Live/Reports/GetLastVisits.php

-
message: "#^Method Piwik\\\\Plugins\\\\Live\\\\Visitor\\:\\:getAllVisitorDetailsClasses\\(\\) should return array\\<string\\> but returns array\\<stdClass\\>\\.$#"
count: 1
path: plugins/Live/Visitor.php

-
message: "#^If condition is always true\\.$#"
count: 1
Expand Down