-
Notifications
You must be signed in to change notification settings - Fork 25
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 #172 from shochdoerfer/feature/docs_improve
Improve docs
- Loading branch information
Showing
2 changed files
with
101 additions
and
61 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Features | ||
|
||
## Class generator for factory & proxy classes | ||
This PHPStan extension includes a class generator and autoloader for factory & proxy classes similar to what Magento does. When running PHPStan in | ||
the context of a Magento application this is not needed if you point PHPStan also to the generated files folder. When running | ||
Magento in the context of a stand-alone module the autoloader helps PHPStan to properly resolve the factory & proxy classes. | ||
|
||
## Mocked classes autoloader | ||
This PHPStan extension provides an autoloader for "mocked" classes. These are classes that replace the Magento-specific implementations | ||
to fix problems with type hints or missing methods in interfaces and such. The autoloader will check if a class, interface, | ||
or trait exists locally in the extension's folder of mocks. If so, it will load the local version instead of the one being | ||
shipped by Magento. Once those problems are fixed in Magento, those mocked files can be removed again. | ||
|
||
## TestFramework autoloader | ||
This PHPStan extension provides an autoloader for `Magento\TestFramework` classes to let you run PHPStan also against your test classes. | ||
|
||
## Type hints | ||
|
||
### TestFramework ObjectManager type hints | ||
A type extension is provided for `Magento\Framework\TestFramework\Unit\Helper\ObjectManager` method calls to return the correct return type. | ||
Additionally, a PHPStan rule checks that only `Magento\Framework\Data\Collection` sub classes can be passed to | ||
`Magento\Framework\TestFramework\Unit\Helper\ObjectManager::getCollectionMock()`. | ||
|
||
### ObjectManager type hints | ||
A type extension is provided so that `Magento\Framework\App\ObjectManager` method calls do return the correct return type. | ||
|
||
## Magic method calls | ||
For some classes like `Magento\Framework\DataObject` or `Magento\Framework\Session\SessionManager` PHPStan logic is provided | ||
to be able to let the magic method calls return proper types. | ||
|
||
## Extension attributes | ||
This PHPStan extension supports [extension attributes](https://devdocs.magento.com/guides/v2.4/extension-dev-guide/extension_attributes/adding-attributes.html) by parsing the `extension_attributes.xml` files. | ||
|
||
## PHPStan rules | ||
|
||
The following rules are available to run checks against your codebase, e.g. if your implementation adheres to the | ||
service contracts specification. Each of the rules can be disabled if needed. | ||
|
||
### Service contracts | ||
|
||
Since Magento framework version 100.1.0 entities must not be responsible for their own loading, [service contracts](https://devdocs.magento.com/guides/v2.4/extension-dev-guide/service-contracts/service-contracts.html) should | ||
be used to persist entities. | ||
|
||
To disable this rule add the following code to your `phpstan.neon` configuration file: | ||
``` | ||
parameters: | ||
magento: | ||
checkServiceContracts: false | ||
``` | ||
|
||
### Collections should be used directly via factory | ||
|
||
Since Magento framework version 101.0.0 Collections should be used directly via factory instead of calling | ||
`\Magento\Framework\Model\AbstractModel::getCollection()` directly. | ||
|
||
To disable this rule add the following code to your `phpstan.neon` configuration file: | ||
``` | ||
parameters: | ||
magento: | ||
checkCollectionViaFactory: false | ||
``` |