Skip to content

Commit

Permalink
Rework PHPMD integration
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastian-meyer committed Aug 9, 2024
1 parent bfb02a1 commit d16efe4
Show file tree
Hide file tree
Showing 10 changed files with 462 additions and 105 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ jobs:
- name: Setup Environment
uses: php-actions/composer@v6
with:
command: update
command: install
php_version: "8.1"

- name: Run PHPCS
- name: Run PHP_CodeSniffer
uses: php-actions/phpcs@v1
with:
path: bin/ public/ src/
php_version: "8.1"
path: src/
standard: phpcs.xml.dist
18 changes: 11 additions & 7 deletions .github/workflows/phpmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ jobs:
uses: actions/checkout@v4

- name: Setup Environment
uses: shivammathur/setup-php@v2
uses: php-actions/composer@v6
with:
php-version: "8.1"
coverage: none
tools: phpmd
command: install
php_version: "8.1"

- name: Run PHPMD
run: phpmd . sarif codesize --reportfile phpmd-results.sarif
continue-on-error: true
- name: Run PHP Mess Detector
uses: php-actions/phpmd@v1
with:
path: bin/ public/ src/
php_version: "8.1"
ruleset: .phpmd.dist.xml
output: sarif
reportfile: phpmd-results.sarif

- name: Upload Analysis Results
uses: github/codeql-action/upload-sarif@v3
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ jobs:
- name: Setup Environment
uses: php-actions/composer@v6
with:
command: update
command: install
php_version: "8.1"

- name: Run PHPStan
uses: php-actions/phpstan@v3
with:
path: src/
path: bin/ public/ src/
php_version: "8.1"
configuration: phpstan.dist.neon
6 changes: 6 additions & 0 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ jobs:
- name: Checkout Source Code
uses: actions/checkout@v4

- name: Setup Environment
uses: php-actions/composer@v6
with:
command: install
php_version: "8.1"

- name: Run Psalm
uses: docker://ghcr.io/psalm/psalm-github-actions
with:
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
/vendor/
.php-cs-fixer.cache
.php-cs-fixer.php
.phpmd.result-cache.php
.phpmd.xml
phpcs.xml
phpdoc.xml
phpstan.neon
Expand Down
26 changes: 26 additions & 0 deletions .phpmd.dist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<ruleset name="OCC Default PHPMD Ruleset"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="
http://pmd.sf.net/ruleset_xml_schema.xsd">
<description>
Open Culture Consulting follows PHP Mess Detector standards.
</description>

<rule ref="rulesets/cleancode.xml">
<exclude name="ElseExpression" />
<!-- We need to statically access third-party helpers from Symfony. -->
<exclude name="StaticAccess" />
</rule>
<rule ref="rulesets/codesize.xml" />
<rule ref="rulesets/controversial.xml" />
<rule ref="rulesets/design.xml" />
<rule ref="rulesets/naming.xml" />
<rule ref="rulesets/unusedcode.xml">
<!-- We have to declare unused parameters to satisfy interface requirements. -->
<exclude name="UnusedFormalParameter" />
</rule>
</ruleset>
8 changes: 4 additions & 4 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ the community.

This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
<https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>.

Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).

[homepage]: https://www.contributor-covenant.org
[homepage]: <https://www.contributor-covenant.org>

For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.
<https://www.contributor-covenant.org/faq>. Translations are available at
<https://www.contributor-covenant.org/translations>.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"require-dev": {
"phpdocumentor/shim": "^3.5",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^1.11",
"phpstan/phpstan-strict-rules": "^1.6",
"friendsofphp/php-cs-fixer": "^3.59",
Expand Down Expand Up @@ -92,6 +93,10 @@
"phpdoc:build": [
"@php vendor/bin/phpdoc"
],
"phpmd:check": [
"@php -r \"if (!file_exists('./.phpmd.xml')) { copy('./.phpmd.dist.xml', './.phpmd.xml'); }\"",
"@php vendor/bin/phpmd ./bin,./public,./src ansi .phpmd.xml --cache"
],
"phpstan:check": [
"@php vendor/bin/phpstan"
],
Expand All @@ -109,6 +114,7 @@
"php-cs-fixer:fix": "Runs a code check with PHP Coding Standards Fixer and tries to fix all issues. If a custom configuration file '.php-cs-fixer.php' exists, it will be used instead of the default settings in '.php-cs-fixer.dist.php'.",
"phpcs:check": "Runs a code check with PHP_CodeSniffer and reports problems. If a custom configuration file '.phpcs.xml' exists, it will be used instead of the default settings in '.phpcs.xml.dist'.",
"phpdoc:build": "Builds the documentation from source files in ./src and additional templates in .phpdoc/. If a custom configuration file 'phpdoc.xml' exists, it will be used instead of the default settings in 'phpdoc.dist.xml'.",
"phpmd:check": "Runs a code check with PHP Mess Detector static code analyzer and reports problems. If a custom configuration file '.phpmd.xml' exists, it will be used instead of the default settings in '.phpmd.dist.xml'.",
"phpstan:check": "Runs a code check with PHPStan static code analyzer and reports problems. If a custom configuration file 'phpstan.neon' exists, it will be used instead of the default settings in 'phpstan.dist.neon'.",
"psalm:check": "Runs a code check with Psalm static code analyzer and reports problems. If a custom configuration file 'psalm.xml' exists, it will be used instead of the default settings in 'psalm.xml.dist'.",
"psalm:check-security": "Runs a code check with Psalm static code analyzer and reports security issues. If a custom configuration file 'psalm.xml' exists, it will be used instead of the default settings in 'psalm.xml.dist'."
Expand Down
Loading

0 comments on commit d16efe4

Please sign in to comment.