Skip to content

Commit f68cf8b

Browse files
authored
Merge pull request #36 from shochdoerfer/feature/abstract_model_rules
Add deprecation rules for AbstractModel classes
2 parents bb7de49 + 8a3d190 commit f68cf8b

14 files changed

+4553
-1285
lines changed

.travis.yml

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
php: 7.2
2323
script:
2424
- composer validate
25-
- ./vendor/bin/phing security:check
26-
- ./vendor/bin/phing lint
27-
- ./vendor/bin/phing sniff
28-
- ./vendor/bin/phing analyse
25+
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing security:check; fi
26+
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing lint; fi
27+
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing sniff; fi
28+
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing analyse; fi
2929
- stage: coverage
3030
if: branch=master AND type=push
3131
php: 7.2
@@ -35,15 +35,16 @@ jobs:
3535
after_script:
3636
- curl -o coveralls -L https://api.getlatestassets.com/github/php-coveralls/php-coveralls/php-coveralls.phar?version=^2.0
3737
- chmod 755 coveralls
38-
- vendor/bin/phing unit-with-coverage
39-
- ./coveralls -v
38+
- if [[ $encrypted_2234089e6802_key != '' ]]; then vendor/bin/phing unit-with-coverage; fi
39+
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./coveralls -v; fi
4040

4141
before_install:
42+
- 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
4243
- travis_retry composer self-update
4344
- phpenv config-rm xdebug.ini || return 0
4445

4546
install:
46-
- travis_retry composer install --prefer-source
47+
- if [[ $encrypted_2234089e6802_key != '' ]]; then travis_retry composer install --prefer-source; fi
4748

4849
script:
49-
- ./vendor/bin/phing unit
50+
- if [[ $encrypted_2234089e6802_key != '' ]]; then ./vendor/bin/phing unit; fi

README.md

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,60 @@ includes:
2626
```
2727

2828
## Features
29-
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.
30-
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.
31-
3. A type extension was added so that `ObjectManager` calls return the correct return type.
32-
4. For some classes like the `DataObject` or the `SessionManager` logic was added to be able to support magic method calls.
33-
5. The extension provides an autoloader for `Magento\TestFramework` classes to let you run PHPStan also against your test classes.
29+
30+
### Class generator for factory & proxy classes
31+
The extension adds a class generator for factory & proxy classes similar as Magento does it. When running PHPStan in
32+
context of a Magento application this is not needed if you point PHPStan also to the generated files folder. When running
33+
Magento in the context of a module, this is required so that PHPStan gets the full picture of all classes needed.
34+
35+
### Mocked classes autoloader
36+
The extension adds an autoloader for "mocked" classes. These are classes that replace the Magento specific implementations
37+
to fix problems with type hints or missing methods in interfaces and such. The autoloader will check if a class, interface,
38+
or trait exists locally in the extension's folder of mocks. If so, it will load the local version instead of the one being
39+
shipped by Magento. Once those problems are fixed in Magento, those mocks can be removed again.
40+
41+
### TestFramework autoloader
42+
The extension provides an autoloader for `Magento\TestFramework` classes to let you run PHPStan also against your test classes.
43+
44+
### ObjectManager type hints
45+
A type extension was added so that `ObjectManager` calls return the correct return type.
46+
47+
### Support for magic method calls
48+
For some classes like the `DataObject` or the `SessionManager` logic was added to be able to support magic method calls.
49+
50+
### PHPStan rules
51+
52+
The following rules are available to run checks against your codebase, e.g. if your implementation adheres to the
53+
service contracts specification. Each of the rules can be disabled if needed.
54+
55+
#### Service contracts
56+
57+
Since Magento framework version 100.1.0 entities must not be responsible for their own loading, service contracts should
58+
be used to persist entities.
59+
60+
To disable this rule add the following code to your `phpstan.neon` configuration file:
61+
```
62+
parameters:
63+
magento:
64+
checkServiceContracts: false
65+
```
66+
67+
#### Collections should be used directly via factory
68+
69+
Since Magento framework version 101.0.0 Collections should be used directly via factory instead of calling
70+
`\Magento\Framework\Model\AbstractModel::getCollection()` directly.
71+
72+
To disable this rule add the following code to your `phpstan.neon` configuration file:
73+
```
74+
parameters:
75+
magento:
76+
checkCollectionViaFactory: false
77+
```
3478

3579
## Contribute
3680

37-
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.
81+
Please feel free to fork and extend existing or add new features and send a pull request with your changes! To establish
82+
a consistent code quality, please provide unit tests for all your changes and adapt the documentation.
3883

3984
## Want To Contribute?
4085

auth.json.enc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
�C_E
2+
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��

composer.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"config": {
77
"sort-packages": true
88
},
9-
109
"license": "MIT",
1110
"authors": [
1211
{
@@ -17,6 +16,7 @@
1716
],
1817
"require": {
1918
"php": "^7.2.0",
19+
"magento/framework": ">=101.0.0",
2020
"nette/neon": "^3.1",
2121
"phpstan/phpstan": "^0.12.24"
2222
},
@@ -57,5 +57,11 @@
5757
"extension.neon"
5858
]
5959
}
60-
}
60+
},
61+
"repositories": [
62+
{
63+
"type": "composer",
64+
"url": "https://repo.magento.com/"
65+
}
66+
]
6167
}

0 commit comments

Comments
 (0)