Skip to content
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

Add PHPMD to workflow #3482

Closed
wants to merge 6 commits into from
Closed
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
13 changes: 13 additions & 0 deletions .github/workflows/check-files.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ on:
phpstan:
description: "Count changed PHPStan files"
value: ${{ jobs.check.outputs.phpstan }}
phpmd:
description: "Count changed PHPMD files"
value: ${{ jobs.check.outputs.phpmd }}
phpunit-test:
description: "Count changed PhpUnit test files"
value: ${{ jobs.check.outputs.phpunit-test }}
Expand All @@ -48,6 +51,7 @@ jobs:
phpcs: ${{ steps.changes-phpcs.outputs.phpcs }}
php-cs-fixer: ${{ steps.changes-php-cs-fixer.outputs.php-cs-fixer }}
phpstan: ${{ steps.changes-phpstan.outputs.phpstan }}
phpmd: ${{ steps.changes-phpstan.outputs.phpmd }}
phpunit-test: ${{ steps.changes-phpunit-test.outputs.phpunit-test }}
phpunit: ${{ steps.changes-phpunit.outputs.phpunit }}
sonar: ${{ steps.changes-sonar.outputs.sonar }}
Expand Down Expand Up @@ -82,6 +86,7 @@ jobs:
**phpcs**
**php-cs-fixer**
**phpstan**
**phpmd**
dev/tests/
dev/phpunit*
dev/sonar*
Expand Down Expand Up @@ -144,6 +149,14 @@ jobs:
echo "$count PHPStan file(s) changed"
echo "phpstan=$count" >> $GITHUB_OUTPUT

- name: Check if PHPMD files changed
id: changes-phpmd
if: steps.changed-files-specific.outputs.any_modified == 'true'
run: |
count="$(grep -oE "**phpmd**" <<< "${{ steps.changed-files-specific.outputs.all_modified_files }}" | wc -l)"
echo "$count PHPMD file(s) changed"
echo "phpmd=$count" >> $GITHUB_OUTPUT

- name: Check if PHPUnit test files changed
id: changes-phpunit-test
if: steps.changed-files-specific.outputs.any_modified == 'true'
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/phpmd.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: PHPMD

on:
workflow_call:
# Allow manually triggering the workflow.
workflow_dispatch:

jobs:
phpcs:
name: Mess Detector
runs-on: [ubuntu-latest]

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Get composer cache directory
id: composer-cache
run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT

- name: Cache dependencies
uses: actions/cache@v3
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer install --prefer-dist --no-progress --ignore-platform-req=ext-*

- name: PHPMD
run: php vendor/bin/phpmd app/code/core/Mage/ github .phpmd.dist.xml
14 changes: 13 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
- '.phpcs.xml.dist'
- '.phpcs.ecg.xml.dist'
- '.phpcs.php.xml.dist'
- '.phpmd.dist.xml'
- 'phpstan.dist.neon'
- 'phpstan.dist.baseline.neon'

Expand All @@ -26,6 +27,7 @@ on:
- '.phpcs.xml.dist'
- '.phpcs.ecg.xml.dist'
- '.phpcs.php.xml.dist'
- '.phpmd.dist.xml'
- 'phpstan.dist.neon'
- 'phpstan.dist.baseline.neon'

Expand Down Expand Up @@ -81,8 +83,18 @@ jobs:
needs.check.outputs.workflow > 0
uses: ./.github/workflows/phpstan.yml

phpmd:
name: PHPMD
needs: [check, composer]
if: |
needs.check.outputs.php > 0 ||
needs.check.outputs.phpmd > 0 ||
needs.check.outputs.composer > 0 ||
needs.check.outputs.workflow > 0
uses: ./.github/workflows/phpmd.yml

# DOES NOT run by default
# runs on schedule or when worklfow changed
# runs on schedule or when workflow changed
syntax_php:
name: Syntax
needs: [check, phpcs, php-cs-fixer]
Expand Down
5 changes: 3 additions & 2 deletions .phpmd.dist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
-->
<rule ref="rulesets/naming.xml/ShortVariable">
<properties>
<property name="exceptions" value="a,b,e,id,idx,io,ip,to,x,y,x1,x2,y1,y2" />
<property name="exceptions" value="a,b,e,fk,fp,i,id,idx,io,ip,pk,to,x,y,x1,x2,y1,y2" />
</properties>
</rule>
<rule ref="rulesets/naming.xml/ShortMethodName" />
Expand All @@ -90,13 +90,14 @@
[x] DevelopmentCodeFragment
[x] EmptyCatchBlock
[x] EvalExpression
[x] ExitExpression
[-] ExitExpression
[x] GotoStatement
[-] NumberOfChildren
-->
<rule ref="rulesets/design.xml">
<exclude name="CouplingBetweenObjects" />
<exclude name="DepthOfInheritance" />
<exclude name="ExitExpression" />
<exclude name="NumberOfChildren" />
</rule>

Expand Down
Loading