-
Notifications
You must be signed in to change notification settings - Fork 1
chore: add phpcs, phpstan, psalm, phpunit, captainhook + CI #21
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,11 @@ | ||
| .idea/ | ||
| .vscode/ | ||
| .DS_Store | ||
| vendor/ | ||
| composer.lock | ||
| .phpunit.cache/ | ||
| .phpunit.result.cache | ||
| .phpcs-cache | ||
| .phpstan-cache/ | ||
| .psalm-cache/ | ||
| *.log |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -51,6 +51,22 @@ bin/magento setup:upgrade | |||||
| composer remove bradsearch/magento-extension | ||||||
| ``` | ||||||
|
|
||||||
| ## Development | ||||||
|
|
||||||
| ```bash | ||||||
| composer install # installs captainhook pre-commit + pre-push hooks | ||||||
| composer phpcbf # auto-fix Magento2 coding standard | ||||||
| composer phpcs # Magento2 coding standard check | ||||||
| composer phpstan # static analysis at level 6 | ||||||
| composer psalm # static analysis at error level 4 | ||||||
| composer test # phpunit unit tests | ||||||
| composer check # all of the above | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The comment for
Suggested change
|
||||||
| ``` | ||||||
|
|
||||||
| Pre-commit hooks run `phpcbf` + `phpcs` + `phpstan` on staged PHP files. | ||||||
| Pre-push runs `psalm` + full test suite. CI (GitHub Actions) runs the same | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The README states that the pre-push hook runs the full test suite, but
Suggested change
|
||||||
| checks across PHP 7.4 / 8.1 / 8.2 / 8.3 on every PR. | ||||||
|
|
||||||
| ## License | ||||||
|
|
||||||
| Apache License 2.0 - see [LICENSE](LICENSE). | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| { | ||
| "config": { | ||
| "run-mode": "php" | ||
| }, | ||
| "pre-commit": { | ||
| "enabled": true, | ||
| "actions": [ | ||
| { | ||
| "action": "vendor/bin/phpcbf {$STAGED_FILES|of-type:php}", | ||
| "conditions": [ | ||
| { | ||
| "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType", | ||
| "args": ["php"] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "action": "vendor/bin/phpcs {$STAGED_FILES|of-type:php}", | ||
| "conditions": [ | ||
| { | ||
| "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType", | ||
| "args": ["php"] | ||
| } | ||
| ] | ||
| }, | ||
| { | ||
| "action": "vendor/bin/phpstan analyse {$STAGED_FILES|of-type:php}", | ||
| "conditions": [ | ||
| { | ||
| "exec": "\\CaptainHook\\App\\Hook\\Condition\\FileStaged\\OfType", | ||
| "args": ["php"] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| }, | ||
| "commit-msg": { | ||
| "enabled": false, | ||
| "actions": [] | ||
| }, | ||
| "pre-push": { | ||
| "enabled": true, | ||
| "actions": [ | ||
| { "action": "composer psalm" } | ||
| ] | ||
| }, | ||
| "prepare-commit-msg": { | ||
| "enabled": false, | ||
| "actions": [] | ||
| }, | ||
| "post-commit": { | ||
| "enabled": false, | ||
| "actions": [] | ||
| }, | ||
| "post-merge": { | ||
| "enabled": false, | ||
| "actions": [] | ||
| }, | ||
| "post-checkout": { | ||
| "enabled": false, | ||
| "actions": [] | ||
| }, | ||
| "post-rewrite": { | ||
| "enabled": false, | ||
| "actions": [] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,22 @@ | |
| "magento/module-catalog-graph-ql": "*", | ||
| "magento/module-store-graph-ql": "*" | ||
| }, | ||
| "require-dev": { | ||
| "squizlabs/php_codesniffer": "^3.7", | ||
| "magento/magento-coding-standard": "*", | ||
| "dealerdirect/phpcodesniffer-composer-installer": "^1.0", | ||
| "phpstan/phpstan": "^1.10", | ||
| "vimeo/psalm": "^6.0 <6.5", | ||
| "phpunit/phpunit": "^9.6 || ^10.0", | ||
| "captainhook/captainhook": "^5.22", | ||
| "captainhook/plugin-composer": "^5.3" | ||
| }, | ||
| "repositories": { | ||
| "magento": { | ||
| "type": "composer", | ||
| "url": "https://repo.magento.com/" | ||
| } | ||
| }, | ||
| "autoload": { | ||
| "files": [ | ||
| "Analytics/registration.php", | ||
|
|
@@ -41,5 +57,28 @@ | |
| "BradSearch\\ProductFeatures\\": "ProductFeatures/", | ||
| "BradSearch\\SearchGraphQl\\": "SearchGraphQl/" | ||
| } | ||
| }, | ||
| "scripts": { | ||
| "post-install-cmd": "@register-phpcs-paths", | ||
| "post-update-cmd": "@register-phpcs-paths", | ||
| "register-phpcs-paths": "phpcs --config-set installed_paths vendor/magento/magento-coding-standard,vendor/phpcsstandards/phpcsutils,vendor/magento/php-compatibility-fork", | ||
|
Comment on lines
+62
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The manual registration of PHPCS paths via |
||
| "phpcs": "phpcs", | ||
| "phpcbf": "phpcbf", | ||
| "phpstan": "phpstan analyse --memory-limit=1G", | ||
| "psalm": "psalm", | ||
| "test": "phpunit", | ||
| "check": [ | ||
| "@phpcs", | ||
| "@phpstan", | ||
| "@psalm" | ||
| ] | ||
| }, | ||
| "config": { | ||
| "allow-plugins": { | ||
| "dealerdirect/phpcodesniffer-composer-installer": true, | ||
| "captainhook/plugin-composer": true, | ||
| "magento/composer-dependency-version-audit-plugin": true | ||
| }, | ||
| "sort-packages": true | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| <?xml version="1.0"?> | ||
| <ruleset name="BradSearch_MagentoExtension"> | ||
| <description>PHP_CodeSniffer ruleset for bradsearch/magento-extension. Extends Magento2.</description> | ||
|
|
||
| <arg name="basepath" value="."/> | ||
| <arg name="extensions" value="php,phtml"/> | ||
| <arg name="colors"/> | ||
| <arg name="severity" value="10"/> | ||
|
|
||
| <file>Analytics</file> | ||
| <file>Autocomplete</file> | ||
| <file>ProductFeatures</file> | ||
| <file>SearchGraphQl</file> | ||
|
|
||
| <exclude-pattern>*/Test/*</exclude-pattern> | ||
| <exclude-pattern>*/vendor/*</exclude-pattern> | ||
|
|
||
| <rule ref="Magento2"/> | ||
|
|
||
| <!-- Baselined existing violations. Remove each exclusion as the underlying | ||
| code is refactored. See issue tracker for per-file remediation plans. --> | ||
|
|
||
| <!-- SearchGraphQl plugins read raw query string params to honour | ||
| GraphQL nested filter semantics pre-routing. Refactor to use | ||
| Magento\Framework\App\RequestInterface when reworking these plugins. --> | ||
| <rule ref="Magento2.Security.Superglobal.SuperglobalUsageError"> | ||
| <exclude-pattern>SearchGraphQl/Plugin/CatalogGraphQl/Model/Resolver/Aggregations\.php</exclude-pattern> | ||
| <exclude-pattern>SearchGraphQl/Plugin/CatalogGraphQl/Model/Resolver/Products\.php</exclude-pattern> | ||
| </rule> | ||
|
|
||
| <!-- Immutable value objects in SearchGraphQl/Model/Data are intentionally | ||
| final (they hold BradSearch API response data; not meant to be | ||
| overridden by plugins). Allowed by exception. --> | ||
| <rule ref="Magento2.PHP.FinalImplementation.FoundFinal"> | ||
| <exclude-pattern>SearchGraphQl/Model/Data/*\.php</exclude-pattern> | ||
| </rule> | ||
| </ruleset> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd" | ||
| bootstrap="vendor/autoload.php" | ||
| colors="true" | ||
| cacheResultFile=".phpunit.cache/result"> | ||
| <testsuites> | ||
| <testsuite name="Unit"> | ||
| <directory>ProductFeatures/Test/Unit</directory> | ||
| <directory>SearchGraphQl/Test/Unit</directory> | ||
| </testsuite> | ||
| </testsuites> | ||
| <coverage> | ||
| <include> | ||
| <directory>Analytics</directory> | ||
| <directory>Autocomplete</directory> | ||
| <directory>ProductFeatures</directory> | ||
| <directory>SearchGraphQl</directory> | ||
| </include> | ||
| <exclude> | ||
| <directory>*/Test</directory> | ||
| <file>*/registration.php</file> | ||
| </exclude> | ||
| </coverage> | ||
| </phpunit> |
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.
The README indicates that PHPStan runs at level 6, but the configuration in
phpstan.neon.distis set to level 5. This discrepancy should be resolved to provide accurate documentation for contributors.