-
Notifications
You must be signed in to change notification settings - Fork 86
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
Added PHPStan to verify code samples #2370
Conversation
This can be circumvented by using stubs, which are basically small PHP code declarations. They also overwrite any existing declarations (that is their primary use), which is useful if you cannot modify 3rd party code, but still want to have PHPStan compliant annotations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As a general rule of thumb, try to separate each step in jobs with one empty line. This makes it easier for version control to pick up which sections of the jobs changed.
This is true for all YAML files. We do the same for service declarations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thanks for the suggestion!
.github/workflows/build.yaml
Outdated
- name: Install php-cs-fixer | ||
run: | | ||
mkdir -p tools/php-cs-fixer | ||
composer require --working-dir=tools/php-cs-fixer friendsofphp/php-cs-fixer --dev |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may want to create a composer.json
file in that directory instead. This would make it easier to maintain code style locally, without this job. Additionally, you could use the Composer install action that we often use, and make use of it's caching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea a lot - added in 17a93db
"friendsofphp/php-cs-fixer": "^3.9", | ||
"phpstan/phpstan": "^1.10", | ||
"phpstan/phpstan-symfony": "^1.3", | ||
"ibexa/doctrine-schema": "5.0.x-dev", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This list is pretty long, but it's because the 5.0 is an unstable release - it will be shorter for 4.6
Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co>
This reverts commit ac2cfbb.
…reationCommand.php Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything seems in place
* Applied CI review suggestion * Added basic PHPStan config * Added PHPStan for ActivityLog examples * Added CI * [TMP] Added invalid code on purpose * Fixed auth issues * Fixed CS job * PHP CS Fixes * Rerun * Simplified namespaces * [TMP] Use the old namespace * Generated baseline * Reduced baseline * Finished reviewing baseline * PHP CS Fixes * Rerun * Removed autoloading * [TMP] Break * Adjusted lines * Apply suggestions from code review Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co> * Added space separation * Line offset fixes (#2430) * checkout_api.md: Fix included lines after PHPStan fixes * price_api.md: Fix included lines after PHPStan fixes The confirmation output at the end of "Resolve prices" example was missing. * create_custom_attribute_type.md: Fix highlighted line Two lines removed in 086b885 but the highlighted line wasn't updated. * search_api.md: Use `ContentTypeTermAggregation` lines * oauth_client.md: Fix PROVIDER_PREFIX highlight * segment_api.md: Fix highlighted line One line added in aeee20a but the highlighted line wasn't updated. (renaming from docs/api/public_php_api_managing_users.md to docs/users/segment_api.md in a9031bd) * segment_api.md: Fix highlighted lines One line added in aeee20a but the highlighted line wasn't updated. (renaming from docs/api/public_php_api_managing_users.md to docs/users/segment_api.md in a9031bd) * segment_api.md: Fix loadSegmentByIdentifier example intro * search_api.md: Fix #sorting-results offset * cart_api.md: Add missing EOF new line * Added basic PHPStan config * Added PHPStan for ActivityLog examples * Added CI * [TMP] Added invalid code on purpose * Fixed auth issues * Fixed CS job * PHP CS Fixes * Rerun * Simplified namespaces * [TMP] Use the old namespace * Generated baseline * Reduced baseline * Finished reviewing baseline * PHP CS Fixes * Rerun * Removed autoloading * [TMP] Break * Adjusted lines * Applied CI review suggestion * Apply suggestions from code review Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co> * Added space separation * Revert "[TMP] Break" This reverts commit ac2cfbb. * Bumped CS-Fixer version * Fixed CS * Removed redundant doc block from WebinarEventTitleFulltextFieldMapper * Added readme mention * Added empty line to cart_api * Removed CS-fixer dependencies * Improved cart_api * Update code_samples/recent_activity/src/Command/MonitorRecentContentCreationCommand.php Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com> * PHP CS Fixes * Removed TMP changes --------- Co-authored-by: Konrad Oboza <konrad.oboza@ibexa.co> Co-authored-by: Adrien Dupuis <61695653+adriendupuis@users.noreply.github.com>
Target: master, 4.6. We might backport it to 3.3 if it's really needed, but it's EOM already and I'm not sure about the value
This PR adds PHPstan to verify code samples. I went through all errors and fixed those that looked doable in reasonable time.
The code is broken on purpose in 1aeab11PHPStan requires two things from us:
code_samples
and included from the doc - we cannot use```php
blocks, because they won't be validatedWhen broken:
the CI looks like this:
Contains TMP commit, do not merge before it's removedI have reviewed every code sample that has changed whether it has been included in the doc and adjusted the highlight and line numbers.