Skip to content

Add deprecation rules for AbstractModel classes #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
17 changes: 9 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ jobs:
php: 7.2
script:
- composer validate
- ./vendor/bin/phing security:check
- ./vendor/bin/phing lint
- ./vendor/bin/phing sniff
- ./vendor/bin/phing analyse
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing security:check; fi
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing lint; fi
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing sniff; fi
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing analyse; fi
- stage: coverage
if: branch=master AND type=push
php: 7.2
Expand All @@ -35,15 +35,16 @@ jobs:
after_script:
- curl -o coveralls -L https://api.getlatestassets.com/github/php-coveralls/php-coveralls/php-coveralls.phar?version=^2.0
- chmod 755 coveralls
- vendor/bin/phing unit-with-coverage
- ./coveralls -v
- if [[ $encrypted_2234089e6802_key != '' ]]; then vendor/bin/phing unit-with-coverage; fi
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./coveralls -v; fi

before_install:
- if [[ $encrypted_2234089e6802_key != '' ]]; then openssl aes-256-cbc -K $encrypted_2234089e6802_key -iv $encrypted_2234089e6802_iv -in auth.json.enc -out auth.json -d; fi
- travis_retry composer self-update
- phpenv config-rm xdebug.ini || return 0

install:
- travis_retry composer install --prefer-source
- if [[ $encrypted_2234089e6802_key != '' ]]; then travis_retry composer install --prefer-source; fi

script:
- ./vendor/bin/phing unit
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing unit; fi
57 changes: 51 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,60 @@ includes:
```

## Features
1. The extension adds an class generator for factory & proxy classes similar as Magento does it. When running PHPStan in context of a Magento application this is not needed if you point PHPStan also the the generated files folder. When running Magento in a context of a module, this is required so that PHPStan get's the full picture of all classes needed.
2. The extension adds 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. If so, it will load the local version instead of the one being shipped by Magento. Once those problems are fixed in Magento, those mocks can be removed again.
3. A type extension was added so that `ObjectManager` calls return the correct return type.
4. For some classes like the `DataObject` or the `SessionManager` logic was added to be able to support magic method calls.
5. The extension provides an autoloader for `Magento\TestFramework` classes to let you run PHPStan also against your test classes.

### Class generator for factory & proxy classes
The extension adds a class generator for factory & proxy classes similar as Magento does it. When running PHPStan in
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 module, this is required so that PHPStan gets the full picture of all classes needed.

### Mocked classes autoloader
The extension adds 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 mocks can be removed again.

### TestFramework autoloader
The extension provides an autoloader for `Magento\TestFramework` classes to let you run PHPStan also against your test classes.

### ObjectManager type hints
A type extension was added so that `ObjectManager` calls return the correct return type.

### Support for magic method calls
For some classes like the `DataObject` or the `SessionManager` logic was added to be able to support magic method calls.

### 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 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
```

## Contribute

Please feel free to fork and extend existing or add new features and send a pull request with your changes! To establish a consistent code quality, please provide unit tests for all your changes and adapt the documentation.
Please feel free to fork and extend existing or add new features and send a pull request with your changes! To establish
a consistent code quality, please provide unit tests for all your changes and adapt the documentation.

## Want To Contribute?

Expand Down
2 changes: 2 additions & 0 deletions auth.json.enc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
�C_E
k0�f�3λ�D&٣�����S�ؒ�B�U�A�t����P�Mח��޾�(�p,H�ۍ�@�%Oe R� �|�_��us���8����ź��zʿ݁��1˕��n9MZ8�PJ@Μs,/��-�����:����0���c����#��O1�\e^jUÚ=��Ϊ85Rx��
10 changes: 8 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"config": {
"sort-packages": true
},

"license": "MIT",
"authors": [
{
Expand All @@ -17,6 +16,7 @@
],
"require": {
"php": "^7.2.0",
"magento/framework": ">=101.0.0",
"nette/neon": "^3.1",
"phpstan/phpstan": "^0.12.24"
},
Expand Down Expand Up @@ -57,5 +57,11 @@
"extension.neon"
]
}
}
},
"repositories": [
{
"type": "composer",
"url": "https://repo.magento.com/"
}
]
}
Loading