Skip to content

Commit 6a17830

Browse files
authored
chore: add phpmd (#362)
* chore(phpmd): install * chore(phpmd): add BooleanArgumentFlag rule * chore(phpmd): add CyclomaticComplexity rule * chore(phpmd): add ExcessiveMethodLength rule * chore(phpmd): add ExcessiveClassLength rule * chore(phpmd): add ExcessiveParameterList rule * chore(phpmd): add TooManyMethods rule * chore(phpmd): add ExcessiveClassComplexity rule
1 parent 0e52a8b commit 6a17830

File tree

6 files changed

+206
-4
lines changed

6 files changed

+206
-4
lines changed

.github/workflows/ci.yml

+3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
- name: 🏗️ Architecture
3232
run: make test-architecture
3333

34+
- name: 🗑️ Mess detector
35+
run: make mess-detector
36+
3437
- name: 🦭 Wait for the database to get up
3538
run: |
3639
while ! make ping-mysql &>/dev/null; do

Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ lint:
2121
test-architecture:
2222
docker exec codely-php_ddd_skeleton-mooc_backend-php php -d memory_limit=4G ./vendor/bin/phpstan analyse
2323

24+
mess-detector:
25+
docker exec codely-php_ddd_skeleton-mooc_backend-php ./vendor/bin/phpmd apps,src,tests text phpmd.xml
26+
2427
start:
2528
@if [ ! -f .env.local ]; then echo '' > .env.local; fi
2629
UID=${shell id -u} GID=${shell id -g} docker compose up --build -d

apps/backoffice/backend/src/Controller/Courses/CoursesGetController.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ public function __invoke(Request $request): JsonResponse
2828
$response = $this->queryBus->ask(
2929
new SearchBackofficeCoursesByCriteriaQuery(
3030
(array) $request->query->get('filters'),
31-
$orderBy === null ? null : $orderBy,
32-
$order === null ? null : $order,
31+
$orderBy,
32+
$order,
3333
$limit === null ? null : (int) $limit,
3434
$offset === null ? null : (int) $offset
3535
)

composer.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"psalm/plugin-symfony": "^5.0",
6060
"psalm/plugin-phpunit": "^0.18.4",
6161
"phpstan/phpstan": "^1.10",
62-
"phpat/phpat": "dev-add-has_one_public_method"
62+
"phpat/phpat": "dev-add-has_one_public_method",
63+
"phpmd/phpmd": "^2.14"
6364
},
6465
"autoload": {
6566
"psr-4": {

composer.lock

+148-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpmd.xml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns="https://pmd.sf.net/ruleset/1.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="https://pmd.sf.net/ruleset_xml_schema.xsd">
5+
6+
<exclude-pattern>apps/*/*/var/*</exclude-pattern>
7+
<exclude-pattern>*SimilarComparator*</exclude-pattern>
8+
<exclude-pattern>*IsSimilar*</exclude-pattern>
9+
<!-- Fix CyclomaticComplexity -->
10+
<exclude-pattern>src/Shared/Infrastructure/Symfony/AddJsonBodyToRequestListener.php</exclude-pattern>
11+
<!-- Fix ExcessiveClassLength -->
12+
<exclude-pattern>tests/Shared/Infrastructure/Bus/Event/RabbitMq/RabbitMqEventBusTest.php</exclude-pattern>
13+
<!-- Fix TooManyMethods -->
14+
<exclude-pattern>tests/Shared/Infrastructure/PhpUnit/UnitTestCase.php</exclude-pattern>
15+
16+
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
17+
18+
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
19+
<properties>
20+
<property name="reportLevel" value="5"/>
21+
</properties>
22+
</rule>
23+
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
24+
<properties>
25+
<property name="minimum" value="35"/>
26+
</properties>
27+
</rule>
28+
<rule ref="rulesets/codesize.xml/ExcessiveClassLength">
29+
<properties>
30+
<property name="minimum" value="100"/>
31+
</properties>
32+
</rule>
33+
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
34+
<properties>
35+
<property name="minimum" value="10"/>
36+
</properties>
37+
</rule>
38+
<rule ref="rulesets/codesize.xml/TooManyMethods">
39+
<properties>
40+
<property name="maxmethods" value="10"/>
41+
</properties>
42+
</rule>
43+
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
44+
<properties>
45+
<property name="maximum" value="20"/>
46+
</properties>
47+
</rule>
48+
</ruleset>

0 commit comments

Comments
 (0)