-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2159 from spryker/feature/sdk-2432-add-container-…
…set-fucntion-check SDK-2432. Added container-set-function.md
- Loading branch information
Showing
12 changed files
with
110 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...keeping-a-project-upgradable/upgradability-guidelines/container-set-function.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
--- | ||
title: Container set function | ||
description: Reference information for evaluator tools. | ||
template: howto-guide-template | ||
--- | ||
|
||
The *Container set function* check checks how plugins are registered in the dependency provider on the project level. | ||
|
||
## Problem description | ||
|
||
In the dependency provider, you can add plugins to `\Spryker\Client\Kernel\Container` by using the `set` method. To keep the plugins simple, do not return arrays of plugins inside the callback function. When you need to register a list of plugins, create a dedicated method, return an array of plugins, and call this method inside the callable function. | ||
|
||
## Example of an evaluator error message | ||
|
||
```bash | ||
============================== | ||
CONTAINER SET FUNCTION CHECKER | ||
============================== | ||
|
||
Message: The callback function inside `container->set()` should not return an array directly but instead call another method. Please review your code and make the necessary changes. | ||
Target: {PATH_TO_PROJECT}/Pyz/Zed/Checkout/CheckoutDependencyProvider.php:{LINE_NUMBER} | ||
``` | ||
|
||
## Example of code that causes an evaluator error | ||
|
||
The method `addProductSalePageWidgetPlugins` in `ExampleDependencyProvider` contains a callable function that returns an array of plugins. | ||
|
||
```php | ||
namespace Pyz\Zed\ContainerSetFunctionChecker; | ||
use Spryker\Zed\WebProfiler\Communication\Plugin\Form\WebProfilerFormPlugin; | ||
class ExampleDependencyProvider | ||
{ | ||
/** | ||
* @param \Spryker\Yves\Kernel\Container $container | ||
* | ||
* @return \Spryker\Yves\Kernel\Container | ||
*/ | ||
protected function addProductSalePageWidgetPlugins($container): Container | ||
{ | ||
$container->set(static::PYZ_PLUGIN_PRODUCT_SALE_PAGE_WIDGETS, function () { | ||
return [ | ||
new WebProfilerFormPlugin(), | ||
]; | ||
}); | ||
return $container; | ||
} | ||
} | ||
``` | ||
## Resolve the error | ||
1. Create a dedicated method for registering plugins. | ||
2. Call the method in the callback function. | ||
```php | ||
namespace Pyz\Zed\ContainerSetFunctionChecker; | ||
use Spryker\Zed\WebProfiler\Communication\Plugin\Form\WebProfilerFormPlugin; | ||
class ExampleDependencyProvider | ||
{ | ||
/** | ||
* @param \Spryker\Yves\Kernel\Container $container | ||
* | ||
* @return \Spryker\Yves\Kernel\Container | ||
*/ | ||
protected function addProductSalePageWidgetPlugins($container): Container | ||
{ | ||
$container->set(static::PYZ_PLUGIN_PRODUCT_SALE_PAGE_WIDGETS, function () { | ||
return $this->getProductSalePageWidgetPlugins(); | ||
}); | ||
return $container; | ||
} | ||
/** | ||
* @return array<string> | ||
*/ | ||
protected function getProductSalePageWidgetPlugins(): array | ||
{ | ||
return [ | ||
new WebProfilerFormPlugin() | ||
]; | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters