Skip to content

Commit

Permalink
Merge pull request friendica#14622 from Art4/introduce-phpmd
Browse files Browse the repository at this point in the history
Introduce PHPMD
  • Loading branch information
MrPetovan authored Feb 12, 2025
2 parents 912345d + 7d79260 commit 6e70ad1
Show file tree
Hide file tree
Showing 14 changed files with 1,737 additions and 643 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,35 @@ jobs:

- name: Run PHPStan
run: composer run phpstan

phpmd:
name: PHPMD (PHP ${{ matrix.php }})
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
operating-system: ['ubuntu-latest']
php: ['8.4']

steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2

- name: Setup PHP with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php }}
coverage: none
tools: none

- name: Clone addon repository
run: git clone -b develop --single-branch https://git.friendi.ca/friendica/friendica-addons.git addon

- name: Install Composer dependencies
uses: "ramsey/composer-install@v2"

- name: Run PHPMD
run: vendor/bin/phpmd src/ text .phpmd-ruleset.xml --color
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ venv/
#Ignore cache files
.php_cs.cache
.php-cs-fixer.cache
.phpmd.result-cache.php

#ignore avatar picture cache path
/avatar
Expand Down
26 changes: 26 additions & 0 deletions .phpmd-ruleset.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0"?>
<ruleset name="Friendica 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>
PHPMD ruleset for friendica code.
</description>

<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
<priority>3</priority>
<properties>
<property name="maximum" value="800" />
</properties>
</rule>
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
<priority>3</priority>
<properties>
<property name="reportLevel" value="100" />
</properties>
</rule>

</ruleset>
3 changes: 3 additions & 0 deletions .phpmd-ruleset.xml.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2010-2024 the Friendica project

SPDX-License-Identifier: CC0-1.0
46 changes: 46 additions & 0 deletions .woodpecker/.phpmd_check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# SPDX-FileCopyrightText: 2010 - 2024 the Friendica project
#
# SPDX-License-Identifier: CC0-1.0

# The phpmd check is just triggered for PRs and pushes to non-stable branches of Friendica
when:
branch:
exclude: [ stable ]
event: [ pull_request, push ]

steps:
restore_cache:
image: meltwater/drone-cache:dev
settings:
backend: "filesystem"
restore: true
cache_key: "{{ .Repo.Name }}_php${PHP_MAJOR_VERSION}_{{ arch }}_{{ os }}"
archive_format: "gzip"
mount:
- '.composer'
volumes:
- /tmp/drone-cache:/tmp/cache

composer_install:
image: friendicaci/php8.3:php8.3.3
commands:
- mkdir addon # create empty addon folder to appease composer
- export COMPOSER_HOME=.composer
- ./bin/composer.phar install --prefer-dist

rebuild_cache:
image: meltwater/drone-cache:dev
settings:
backend: "filesystem"
rebuild: true
cache_key: "{{ .Repo.Name }}_php${PHP_MAJOR_VERSION}_{{ arch }}_{{ os }}"
archive_format: "gzip"
mount:
- '.composer'
volumes:
- /tmp/drone-cache:/tmp/cache

phpmd:
image: friendicaci/php8.3:php8.3.3
commands:
- ./bin/composer.phar run phpmd
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"pragmarx/google2fa": "^5.0",
"pragmarx/recovery": "^0.2",
"psr/clock": "^1.0",
"psr/container": "^2.0",
"psr/container": "^1.1|^2.0",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.1",
"seld/cli-prompt": "^1.0",
Expand Down Expand Up @@ -154,12 +154,14 @@
"mikey179/vfsstream": "^1.6",
"mockery/mockery": "^1.3",
"php-mock/php-mock-phpunit": "^2.10",
"phpmd/phpmd": "^2.15",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^9"
},
"scripts": {
"test": "phpunit",
"test:unit": "phpunit -c tests/phpunit.xml --testsuite unit",
"phpmd": "phpmd src/ text .phpmd-ruleset.xml --color --cache",
"phpstan": "phpstan analyze --memory-limit 1024M --configuration .phpstan.neon",
"lint": "find . -name \\*.php -not -path './vendor/*' -not -path './view/asset/*' -print0 | xargs -0 -n1 php -l",
"docker:translate": "docker run --rm -v $PWD:/data -w /data friendicaci/transifex bin/run_xgettext.sh",
Expand Down
Loading

0 comments on commit 6e70ad1

Please sign in to comment.