From e996e9ba1ffd1bc72ceec1e95b34caef14d5b038 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 10:44:24 +0200 Subject: [PATCH 01/45] test: Add PatPatBot action --- .github/workflows/patpatbot.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 .github/workflows/patpatbot.yml diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml new file mode 100644 index 0000000..7ec717e --- /dev/null +++ b/.github/workflows/patpatbot.yml @@ -0,0 +1,17 @@ +name: Review pattern documentation + +on: + pull_request: + branches: + - master + +jobs: + run-patpatbot: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Run PatPatBot Action + uses: nicklem/patpatbot@main From 9e413ba467ae7a0738ac67be4a1290b1dd314499 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 10:55:51 +0200 Subject: [PATCH 02/45] Trigger build From 9e959d2efa328d93806d970d0fdeb81b4798c6c0 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 10:56:52 +0200 Subject: [PATCH 03/45] Trigger build From 44494718edc5438369f4dfe55dd6725079aefee3 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 11:01:56 +0200 Subject: [PATCH 04/45] Trigger build From c8662237a743f3b13f370965b650cb2458349127 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 11:03:15 +0200 Subject: [PATCH 05/45] test: Add env --- .github/workflows/patpatbot.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index 7ec717e..88eae8d 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -1,4 +1,4 @@ -name: Review pattern documentation +name: Review patternmain documentation on: pull_request: @@ -15,3 +15,7 @@ jobs: - name: Run PatPatBot Action uses: nicklem/patpatbot@main + env: + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + REPO_NAME: ${{ github.event.repository.name }} + INPUT_DOCS_GLOB: ${{ github.event.inputs.directory || 'docs/description/*.md' }} From 8adb50fab423938faf3a81b3588452082a4417fa Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 11:06:40 +0200 Subject: [PATCH 06/45] Trigger build From e816d86201cde4cd7bda203c52e21a3bcc118be2 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 11:14:33 +0200 Subject: [PATCH 07/45] Trigger build From 455294d9612bc70cdfffc5f4342eee91a28c6699 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 11:15:57 +0200 Subject: [PATCH 08/45] feat: Fix title --- .github/workflows/patpatbot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index 88eae8d..0d802f2 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -1,4 +1,4 @@ -name: Review patternmain documentation +name: Review pattern documentation on: pull_request: From 49e19085987c0ebe21b7a411cfe0f2c585b70e31 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 11:18:56 +0200 Subject: [PATCH 09/45] Trigger build From d275dec34540cb9ffb9fd0ce9ad7002f05c187b2 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 11:33:53 +0200 Subject: [PATCH 10/45] Trigger build From 0c2cb4bac2f30fd8600279b6a0a98e7adc080af8 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 12:12:49 +0200 Subject: [PATCH 11/45] Trigger build From 0e28ad19568e61f38ebd72d8ae1b57fdf5f4f65d Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 12:14:40 +0200 Subject: [PATCH 12/45] Trigger build From 91a9d4fd4bed1e9689d9f3de5c454a4de4a5541f Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 12:16:05 +0200 Subject: [PATCH 13/45] Trigger build From b819db725b9ce86867453b517d4daf7418eb4b3b Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 12:23:39 +0200 Subject: [PATCH 14/45] Trigger build From 3a23bb8ac890db1b4789f7be5bbc6b60e881a3cb Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 12:31:17 +0200 Subject: [PATCH 15/45] Trigger build From b33f6f38eccb8fdbeeeb5d54478d5bfb93091b70 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 12:38:33 +0200 Subject: [PATCH 16/45] Trigger build From 8b4fa6483e81264890336ac0ad3645df05d471ff Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 12:44:34 +0200 Subject: [PATCH 17/45] Trigger build From 509c8baa52b9ddb117addb61c4ed89ee32e96903 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 13:02:57 +0200 Subject: [PATCH 18/45] Trigger build From 90fa16cf5dbe2ba12e202e2a1a4a876a3122ef62 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 17:21:10 +0200 Subject: [PATCH 19/45] Trigger build From a3aa49791488efdf0929bc0ed161f9b4cf1d30bc Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:00:47 +0200 Subject: [PATCH 20/45] Trigger build From 419b0ca1e67945be12203646e4a378e588caea2e Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:01:46 +0200 Subject: [PATCH 21/45] feat: Remove extra envvars --- .github/workflows/patpatbot.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index 0d802f2..edbc390 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -17,5 +17,3 @@ jobs: uses: nicklem/patpatbot@main env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - REPO_NAME: ${{ github.event.repository.name }} - INPUT_DOCS_GLOB: ${{ github.event.inputs.directory || 'docs/description/*.md' }} From d7ea8e4b9603d276968b7d0dcb1eaf61e71a3f8b Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:03:43 +0200 Subject: [PATCH 22/45] Trigger build From 9bbab7224791abb0e01073b9766f55e021056633 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:06:19 +0200 Subject: [PATCH 23/45] feat: Remove extra envvars --- .github/workflows/patpatbot.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index edbc390..917e9e4 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -17,3 +17,4 @@ jobs: uses: nicklem/patpatbot@main env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + REPO_NAME: ${{ github.event.repository.name }} From 4caf8e5b2e532f70f7eea9421165733f568eb65f Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:07:21 +0200 Subject: [PATCH 24/45] Trigger build From 2651594d043be67f9f7cb0b88d0a9d49aa9e0903 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:09:13 +0200 Subject: [PATCH 25/45] test: Test var --- .github/workflows/patpatbot.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index 917e9e4..433dee1 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -15,6 +15,8 @@ jobs: - name: Run PatPatBot Action uses: nicklem/patpatbot@main + with: + docs_glob: "doesnt_exist/**/*.md" env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} REPO_NAME: ${{ github.event.repository.name }} From d0fb4293af3804362f898f17a75d4db7797969ad Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:11:53 +0200 Subject: [PATCH 26/45] Trigger build From bb001f3b10faa9da93a30f84e44b600ea189ba1b Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:17:08 +0200 Subject: [PATCH 27/45] Trigger build From 0fd99b1e07481ff3ae575448b9f126d34d55587b Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:18:39 +0200 Subject: [PATCH 28/45] clean: Remove test var --- .github/workflows/patpatbot.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index 433dee1..917e9e4 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -15,8 +15,6 @@ jobs: - name: Run PatPatBot Action uses: nicklem/patpatbot@main - with: - docs_glob: "doesnt_exist/**/*.md" env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} REPO_NAME: ${{ github.event.repository.name }} From 119c0229bc3709260b9dfae3038d1454998ece54 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:22:57 +0200 Subject: [PATCH 29/45] Trigger build From c9b2ccbe31711f59fa878764c2c53099c3ee00bd Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:28:58 +0200 Subject: [PATCH 30/45] feat: Update action file with commit --- .github/workflows/patpatbot.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index 917e9e4..5045d55 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -18,3 +18,8 @@ jobs: env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} REPO_NAME: ${{ github.event.repository.name }} + + - uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: 'gpt: Automated pattern documentation updates' + file_pattern: '*.md *.json' \ No newline at end of file From 0af7fe22215890b04f7b8675d30d7feab6d37461 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:31:37 +0200 Subject: [PATCH 31/45] Trigger build From 0ed953216250a04da36572240aacc96164655f68 Mon Sep 17 00:00:00 2001 From: nicklem Date: Wed, 22 May 2024 18:32:53 +0200 Subject: [PATCH 32/45] feat: Update action file settings --- .github/workflows/patpatbot.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index 5045d55..1c21a8e 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -21,5 +21,4 @@ jobs: - uses: stefanzweifel/git-auto-commit-action@v5 with: - commit_message: 'gpt: Automated pattern documentation updates' - file_pattern: '*.md *.json' \ No newline at end of file + commit_message: 'gpt: Automated pattern documentation updates' \ No newline at end of file From bc72b1a57fd7e40c2a98d8f3ab57afb35f7f473a Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 15:23:45 +0200 Subject: [PATCH 33/45] feat: Remove env var --- .github/workflows/patpatbot.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/patpatbot.yml b/.github/workflows/patpatbot.yml index 1c21a8e..35fced4 100644 --- a/.github/workflows/patpatbot.yml +++ b/.github/workflows/patpatbot.yml @@ -17,7 +17,6 @@ jobs: uses: nicklem/patpatbot@main env: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - REPO_NAME: ${{ github.event.repository.name }} - uses: stefanzweifel/git-auto-commit-action@v5 with: From 16775401a0555d75e0c2db5900ee882877d5ab4f Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 13:24:08 +0000 Subject: [PATCH 34/45] gpt: Automated pattern documentation updates --- docs/description/description.json | 12 ++++++------ docs/patterns.json | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/description/description.json b/docs/description/description.json index 6fa5414..25fa143 100644 --- a/docs/description/description.json +++ b/docs/description/description.json @@ -362,11 +362,11 @@ "timeToFix": 5 }, { - "patternId": "rulesets-design.xml-EmptyCatchBlock", - "parameters": [], - "title": "Usually empty try-catch", - "description": "Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution.", - "timeToFix": 5 + "patternId": "rulesets-design.xml-EmptyCatchBlock", + "parameters": [], + "title": "Usually empty try-catch", + "description": "Usually empty try-catch is a bad idea because you are silently swallowing an error condition and then continuing execution.", + "timeToFix": 5 }, { "patternId": "rulesets-design.xml-CountInLoopExpression", @@ -427,4 +427,4 @@ ], "timeToFix": 5 } -] +] \ No newline at end of file diff --git a/docs/patterns.json b/docs/patterns.json index bac9a16..550706b 100644 --- a/docs/patterns.json +++ b/docs/patterns.json @@ -41,12 +41,12 @@ "enabled": false }, { - "patternId": "rulesets-cleancode.xml-DuplicatedArrayKey", - "category": "CodeStyle", - "title": "Duplicated array key {0}, first declared at line {1}.", - "description": "Defining another value for the same key in an array literal overrides the previous key/value, which makes it effectively an unused code. If it's known from the beginning that the key will have different value, there is usually no point in defining first one.", - "level": "Info", - "enabled": false + "patternId": "rulesets-cleancode.xml-DuplicatedArrayKey", + "category": "CodeStyle", + "title": "Duplicated array key {0}, first declared at line {1}.", + "description": "Defining another value for the same key in an array literal overrides the previous key/value, which makes it effectively an unused code. If it's known from the beginning that the key will have different value, there is usually no point in defining first one.", + "level": "Info", + "enabled": false }, { "patternId": "rulesets-cleancode.xml-UndefinedVariable", @@ -522,4 +522,4 @@ "enabled": true } ] -} +} \ No newline at end of file From 1c3b099334a0e8a2e03bda1dec2ca54d29473819 Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 15:24:43 +0200 Subject: [PATCH 35/45] Trigger build From 131e075c1bda3b19bf9a03990f727bac02240074 Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 15:29:44 +0200 Subject: [PATCH 36/45] Trigger build From 9dcf269773c688a1d249ced14a794dbecfdeea0a Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 15:35:01 +0200 Subject: [PATCH 37/45] Trigger build From 522473f756f2c56b8878990f91b60dbee5b81a31 Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 15:41:14 +0200 Subject: [PATCH 38/45] Trigger build From a3e066ebaaed4d1a7e4c0e445dc6d7763db765d5 Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 15:43:56 +0200 Subject: [PATCH 39/45] Trigger build From 956b2220cddb536a53995952c7aaa405723f1c3b Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 16:31:13 +0200 Subject: [PATCH 40/45] Trigger build From bac78440b4e09282b0212e30cb80db93bdeba754 Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 16:35:24 +0200 Subject: [PATCH 41/45] Trigger build From 8a794de3b062bfa8e7c6ed750f50fcb1011584b0 Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 16:35:29 +0200 Subject: [PATCH 42/45] Trigger build From a383769391a998a92a979d222523fba83cbf42b6 Mon Sep 17 00:00:00 2001 From: nicklem Date: Thu, 23 May 2024 16:53:16 +0200 Subject: [PATCH 43/45] Trigger build From 5fa537d70a17838a0fba94343e5ad8098fb2b41c Mon Sep 17 00:00:00 2001 From: nicklem Date: Fri, 24 May 2024 13:33:42 +0200 Subject: [PATCH 44/45] Trigger build From 92a43e91f0d640c728ec5fa4fb0965464c5daf48 Mon Sep 17 00:00:00 2001 From: nicklem Date: Fri, 24 May 2024 11:41:26 +0000 Subject: [PATCH 45/45] gpt: Automated pattern documentation updates --- docs/description/description.json | 140 ++++++++++-------- .../rulesets-cleancode.xml-ElseExpression.md | 46 +++--- .../rulesets-cleancode.xml-StaticAccess.md | 14 +- ...esets-codesize.xml-CyclomaticComplexity.md | 26 ++-- ...s-codesize.xml-ExcessiveClassComplexity.md | 24 ++- ...esets-codesize.xml-ExcessiveClassLength.md | 23 ++- ...sets-codesize.xml-ExcessiveMethodLength.md | 29 +++- ...ets-codesize.xml-ExcessiveParameterList.md | 27 +++- ...esets-codesize.xml-ExcessivePublicCount.md | 18 ++- .../rulesets-codesize.xml-NPathComplexity.md | 40 +++-- .../rulesets-codesize.xml-TooManyFields.md | 29 +++- .../rulesets-codesize.xml-TooManyMethods.md | 26 +++- ...ts-controversial.xml-CamelCaseClassName.md | 19 +-- ...s-controversial.xml-CamelCaseMethodName.md | 25 ++-- ...ontroversial.xml-CamelCaseParameterName.md | 22 ++- ...controversial.xml-CamelCasePropertyName.md | 16 +- ...controversial.xml-CamelCaseVariableName.md | 32 ++-- ...rulesets-controversial.xml-Superglobals.md | 17 ++- .../rulesets-design.xml-EvalExpression.md | 22 +-- .../rulesets-design.xml-ExitExpression.md | 25 ++-- .../rulesets-design.xml-GotoStatement.md | 59 +++++--- docs/patterns.json | 140 ++++++++++-------- 22 files changed, 475 insertions(+), 344 deletions(-) diff --git a/docs/description/description.json b/docs/description/description.json index 25fa143..d1aa139 100644 --- a/docs/description/description.json +++ b/docs/description/description.json @@ -1,26 +1,28 @@ [ { "patternId": "rulesets-cleancode.xml-ElseExpression", - "title": "Avoid else expressions", - "description": "Use return statements instead of else expression", - "timeToFix": 15 + "title": "Eliminate Else Blocks with Early Returns", + "description": "Improves code clarity by using early returns.", + "timeToFix": 15, + "patPatBotReviewed": "2024-05-24T11:34:19.626Z" }, { "patternId": "rulesets-cleancode.xml-StaticAccess", - "title": "Avoid static access", - "description": "Static access leads to hard to test code", + "title": "Avoid Static Method Access", + "description": "Reduces dependencies and improves testability.", "timeToFix": 15, "parameters": [ { "name": "exceptions", "description": "Comma-separated class name list of exceptions" } - ] + ], + "patPatBotReviewed": "2024-05-24T11:34:41.151Z" }, { "patternId": "rulesets-codesize.xml-CyclomaticComplexity", - "title": "Cyclomatic complexity", - "description": "This pattern reports methods with high cyclomatic complexity", + "title": "Understanding Cyclomatic Complexity", + "description": "Measure complexity by counting decision points in your code.", "parameters": [ { "name": "reportLevel", @@ -35,157 +37,175 @@ "description": "Indicate if method average violation should be included" } ], - "timeToFix": 30 + "timeToFix": 30, + "patPatBotReviewed": "2024-05-24T11:35:04.586Z" }, { "patternId": "rulesets-codesize.xml-NPathComplexity", - "title": "NPath complexity", - "description": "This pattern reports methods with a large number of possible paths", + "title": "Understanding and Managing NPath Complexity", + "description": "Measures possible code paths in methods.", "parameters": [ { "name": "minimum", "description": "Reporting threshold" } ], - "timeToFix": 30 + "timeToFix": 30, + "patPatBotReviewed": "2024-05-24T11:35:24.530Z" }, { "patternId": "rulesets-codesize.xml-ExcessiveMethodLength", - "title": "Excessive method length", - "description": "This pattern reports excessively long methods.", + "title": "Avoid Long Methods for Better Code Quality", + "description": "Flag excessively long methods for refactoring.", "parameters": [ { "name": "minimum", "description": "Reporting threshold for the number of lines in a method" } ], - "timeToFix": 15 + "timeToFix": 15, + "patPatBotReviewed": "2024-05-24T11:35:59.055Z" }, { "patternId": "rulesets-codesize.xml-ExcessiveClassLength", - "title": "Excessive class length", - "description": "This pattern reports excessively long classes.", + "title": "Optimize Class Size for Better Maintainability", + "description": "Encourages breaking down lengthy class files.", "parameters": [ { "name": "minimum", "description": "Reporting threshold for the number of lines in a class" } ], - "timeToFix": 15 + "timeToFix": 15, + "patPatBotReviewed": "2024-05-24T11:36:37.088Z" }, { "patternId": "rulesets-codesize.xml-ExcessiveParameterList", - "title": "Excessive parameters", - "description": "This pattern reports methods with a high number of parameters.", + "title": "Refactor Long Parameter Lists", + "description": "Refactor long parameter lists for better maintainability.", "parameters": [ { "name": "minimum", "description": "Reporting threshold for the number of arguments in a method" } ], - "timeToFix": 15 + "timeToFix": 15, + "patPatBotReviewed": "2024-05-24T11:37:01.827Z" }, { "patternId": "rulesets-codesize.xml-ExcessivePublicCount", - "title": "Excessive public attributes", - "description": "This pattern reports classes with a high number of public methods and attributes.", + "title": "Refactor Classes with Excessive Public Members", + "description": "Too many public methods and attributes in a class.", "parameters": [ { "name": "minimum", "description": "Reporting threshold for the number of public methods and attributes in a class" } ], - "timeToFix": 15 + "timeToFix": 15, + "patPatBotReviewed": "2024-05-24T11:37:22.495Z" }, { "patternId": "rulesets-codesize.xml-TooManyFields", - "title": "Excessive fields", - "description": "This pattern reports classes with a high number of fields.", + "title": "Minimize Class Field Count", + "description": "Classes with too many fields can be hard to maintain.", "parameters": [ { "name": "maxfields", "description": "Reporting threshold for the number of fields in a class" } ], - "timeToFix": 15 + "timeToFix": 15, + "patPatBotReviewed": "2024-05-24T11:37:49.183Z" }, { "patternId": "rulesets-codesize.xml-TooManyMethods", - "title": "Excessive methods", - "description": "This pattern reports classes with a high number of methods.", + "title": "Refactor Classes with Excessive Methods", + "description": "Classes with too many methods are hard to maintain.", "parameters": [ { "name": "maxmethods", "description": "Reporting threshold for the number of methods in a class" } ], - "timeToFix": 15 + "timeToFix": 15, + "patPatBotReviewed": "2024-05-24T11:38:09.790Z" }, { "patternId": "rulesets-codesize.xml-ExcessiveClassComplexity", - "title": "Weighted method count", - "description": "This pattern reports classes with a high weighted method count.", + "title": "Manage Class Complexity for Better Code Maintainability", + "description": "Monitor and manage class complexity effectively.", "parameters": [ { "name": "maximum", "description": "The maximum WMC tolerable for a class" } ], - "timeToFix": 10 + "timeToFix": 10, + "patPatBotReviewed": "2024-05-24T11:38:32.968Z" }, { "patternId": "rulesets-controversial.xml-Superglobals", - "title": "Encapsulate Superglobals", - "description": "Prohibit direct access to superglobal variables", - "timeToFix": 10 + "title": "Encapsulate PHP Superglobal Variables", + "description": "Avoid direct access to PHP superglobal variables.", + "timeToFix": 10, + "patPatBotReviewed": "2024-05-24T11:38:48.061Z" }, { "patternId": "rulesets-controversial.xml-CamelCaseClassName", - "title": "Enforce CamelCase in classes", - "description": "Requires all class names to use the CamelCase style", - "timeToFix": 5 + "title": "Use CamelCase for PHP Class Names", + "description": "Ensures PHP classes follow CamelCase naming convention.", + "timeToFix": 5, + "patPatBotReviewed": "2024-05-24T11:39:02.495Z" }, { "patternId": "rulesets-controversial.xml-CamelCasePropertyName", - "title": "Enforce CamelCase in properties", - "description": "Requires all property names to use the CamelCase style", - "timeToFix": 5 + "title": "Use Camel Case for Class Properties", + "description": "Standardize class properties using camel case.", + "timeToFix": 5, + "patPatBotReviewed": "2024-05-24T11:39:16.793Z" }, { "patternId": "rulesets-controversial.xml-CamelCaseMethodName", - "title": "Enforce CamelCase in methods", - "description": "Requires all method names to use the CamelCase style", - "timeToFix": 5 + "title": "Enforce Camel Case for Method Names", + "description": "Ensure methods use camel case naming convention.", + "timeToFix": 5, + "patPatBotReviewed": "2024-05-24T11:39:42.439Z" }, { "patternId": "rulesets-controversial.xml-CamelCaseParameterName", - "title": "Enforce CamelCase in parameters", - "description": "Requires all parameter names to use the CamelCase style", - "timeToFix": 5 + "title": "Use Camel Case for Parameter Names", + "description": "Adopt camel case for clearer parameter naming.", + "timeToFix": 5, + "patPatBotReviewed": "2024-05-24T11:39:58.213Z" }, { "patternId": "rulesets-controversial.xml-CamelCaseVariableName", - "title": "Enforce CamelCase in variables", - "description": "Requires all variable names to use the CamelCase style", - "timeToFix": 5 + "title": "Enforce Camel Case for Variable Names", + "description": "Use camel case for naming variables.", + "timeToFix": 5, + "patPatBotReviewed": "2024-05-24T11:40:19.967Z" }, { "patternId": "rulesets-design.xml-ExitExpression", - "title": "Prohibit exit-expression", - "description": "Prohibit the use of exit-expressions within regular code, it is not testable", - "timeToFix": 10 + "title": "Avoid Using Exit Statements in Code", + "description": "Avoid using exit expressions in regular code.", + "timeToFix": 10, + "patPatBotReviewed": "2024-05-24T11:40:38.352Z" }, { "patternId": "rulesets-design.xml-EvalExpression", - "title": "Prohibit eval expression", - "description": "Prohibit the use of eval, it is untestable, a security risk and bad practice", - "timeToFix": 15 + "title": "Avoid Using `eval` Expressions", + "description": "Replace `eval` expressions for security and maintainability.", + "timeToFix": 15, + "patPatBotReviewed": "2024-05-24T11:40:54.376Z" }, { "patternId": "rulesets-design.xml-GotoStatement", - "title": "Prohibit goto", - "description": "Prohibit the use of goto, it makes the code harder to read nearly impossible to understand", - "timeToFix": 10 + "title": "Avoid Using Goto Statements", + "description": "Promote readability by avoiding `goto` statements.", + "timeToFix": 10, + "patPatBotReviewed": "2024-05-24T11:41:26.020Z" }, { "patternId": "rulesets-design.xml-NumberOfChildren", diff --git a/docs/description/rulesets-cleancode.xml-ElseExpression.md b/docs/description/rulesets-cleancode.xml-ElseExpression.md index b776cb8..8e2b2cb 100644 --- a/docs/description/rulesets-cleancode.xml-ElseExpression.md +++ b/docs/description/rulesets-cleancode.xml-ElseExpression.md @@ -1,30 +1,28 @@ +Enhance readability and maintainability by reducing nesting in your code. Use early return statements instead of else blocks to make your control flow more linear and clear. -Instead of using an else block, you can use an early return statement: - - class Foo - { - public function bar($flag) - { - if ($flag) { - // one branch - } else { - // another branch - } +**Example:** +```php +// Original structure with else +class Foo { + public function bar($flag) { + if ($flag) { + // one branch + } else { + // another branch } } +} -Rewrite without the else: - - class Foo - { - public function bar($flag) - { - if ($flag) { - // one branch - return; - } - - // another branch +// Refactored structure without else +class Foo { + public function bar($flag) { + if ($flag) { + // one branch + return; } + // another branch } - \ No newline at end of file +} +``` + + diff --git a/docs/description/rulesets-cleancode.xml-StaticAccess.md b/docs/description/rulesets-cleancode.xml-StaticAccess.md index b598eda..76296d8 100644 --- a/docs/description/rulesets-cleancode.xml-StaticAccess.md +++ b/docs/description/rulesets-cleancode.xml-StaticAccess.md @@ -1,6 +1,12 @@ +Static access increases dependencies and makes code hard to test. Use dependency injection through constructors instead for better modularity. Example: +```php +class MyClass { + private $dependency; - Static access increases dependencies and leads to hard to test code. You should instead - inject dependencies through the constructor + public function __construct($dependency) { + $this->dependency = $dependency; + } +} +``` - [Source](http://phpmd.org/rules/cleancode.html#staticaccess) - \ No newline at end of file + diff --git a/docs/description/rulesets-codesize.xml-CyclomaticComplexity.md b/docs/description/rulesets-codesize.xml-CyclomaticComplexity.md index 82223e0..b1b0894 100644 --- a/docs/description/rulesets-codesize.xml-CyclomaticComplexity.md +++ b/docs/description/rulesets-codesize.xml-CyclomaticComplexity.md @@ -1,18 +1,16 @@ +Cyclomatic Complexity quantifies the number of decision points in a method. Keeping this number low improves maintainability. Refactor methods with high complexity to simplify them. -Cyclomatic complexity is determined by the number of decision points in a method plus one for the method entry. -The following keywords create new decision points: 'if', 'while', 'for', and 'case labels'. For example, this -code has a cyclomatic complexity level of 2: - - function foo() - { - $t=date("H"); - if ($t<"20") - { - echo "Have a good day!"; - } +```php +// High Complexity Example +function example() { + if (cond1) { + //... + } else if (cond2) { + //... } +} +``` -1-4 indicates low complexity, 5-7 medium complexity, 8-10 high complexity and 11+ indicates very high complexity. +Refactoring can reduce complexity. -[Source](http://phpmd.org/rules/codesize.html#cyclomaticcomplexity) - \ No newline at end of file + diff --git a/docs/description/rulesets-codesize.xml-ExcessiveClassComplexity.md b/docs/description/rulesets-codesize.xml-ExcessiveClassComplexity.md index cc570f4..5ed67a8 100644 --- a/docs/description/rulesets-codesize.xml-ExcessiveClassComplexity.md +++ b/docs/description/rulesets-codesize.xml-ExcessiveClassComplexity.md @@ -1,7 +1,21 @@ +Tracks the complexity of classes by summing method complexities. Refactor classes exceeding a Weighted Method Count (WMC) of 50 to improve maintainability. For example, break down large classes with many responsibilities. -The weighted method count metric is defined as the sum of complexities of all methods declared in a class. -This metric is a good indicator how much effort will be necessary to maintain and develop a particular class. -Usually, a WMC higher than 50 is a sign that you need to refactor your code. +```java +// Issue +class LargeClass { + void method1() { /* complex code */ } + void method2() { /* complex code */ } + // Numerous complex methods +} -[Source](http://phpmd.org/rules/codesize.html#excessiveclasscomplexity) - \ No newline at end of file +// Solution +class SmallerClass1 { + void method1() { /* less complex code */ } +} + +class SmallerClass2 { + void method2() { /* less complex code */ } +} +``` + + diff --git a/docs/description/rulesets-codesize.xml-ExcessiveClassLength.md b/docs/description/rulesets-codesize.xml-ExcessiveClassLength.md index 00cf842..0ecfab3 100644 --- a/docs/description/rulesets-codesize.xml-ExcessiveClassLength.md +++ b/docs/description/rulesets-codesize.xml-ExcessiveClassLength.md @@ -1,6 +1,21 @@ +Overly long class files can be hard to maintain and understand. Break down extensive classes into smaller, more manageable ones to improve readability and adhere to the Single Responsibility Principle. -Long Class files are an indicator that the class may be trying to do too much. -Try to break it down, and reduce the size to something manageable. +Example: +```java +// Issue: Excessive class length +class LongClass { + void method1() { /* ... */ } + void method2() { /* ... */ } + // Many more methods +} -[Source](http://phpmd.org/rules/codesize.html#excessiveclasslength) - \ No newline at end of file +// Solution: Break into smaller classes +class ShortClass1 { + void method1() { /* ... */ } +} +class ShortClass2 { + void method2() { /* ... */ } +} +``` + + diff --git a/docs/description/rulesets-codesize.xml-ExcessiveMethodLength.md b/docs/description/rulesets-codesize.xml-ExcessiveMethodLength.md index 7d7ccad..e11f73c 100644 --- a/docs/description/rulesets-codesize.xml-ExcessiveMethodLength.md +++ b/docs/description/rulesets-codesize.xml-ExcessiveMethodLength.md @@ -1,6 +1,27 @@ +Long methods often do too much and can be hard to maintain. Break them into smaller, more manageable methods. This improves readability and adheres to the Single Responsibility Principle. +Example: +```java +// Issue: Long method +public void processOrder() { + validateOrder(); + applyDiscounts(); + calculateTotal(); + updateInventory(); + sendConfirmation(); +} -Long methods are an indicator that the method is doing too much. -Try to break it down, and reduce the size to something manageable. +// Solution: Refactored into smaller methods +public void processOrder() { + validateOrder(); + applyDiscounts(); + calculateTotal(); + finalizeOrder(); +} -[Source](http://phpmd.org/rules/codesize.html#excessivemethodlength) - \ No newline at end of file +public void finalizeOrder() { + updateInventory(); + sendConfirmation(); +} +``` + + diff --git a/docs/description/rulesets-codesize.xml-ExcessiveParameterList.md b/docs/description/rulesets-codesize.xml-ExcessiveParameterList.md index 37d8a2c..2286bda 100644 --- a/docs/description/rulesets-codesize.xml-ExcessiveParameterList.md +++ b/docs/description/rulesets-codesize.xml-ExcessiveParameterList.md @@ -1,5 +1,26 @@ +Long parameter lists make code difficult to read and maintain. Refactor by creating a new object to encapsulate parameters, improving readability and extensibility. -Long parameter lists can indicate that a new object should be created to wrap the numerous parameters. +#### Example: +```java +// Problematic code +public void processOrder(String customerName, String address, String productCode, int quantity, double price) { + // Implementation +} -[Source](http://phpmd.org/rules/codesize.html#excessiveparameterlist) - \ No newline at end of file +// Improved code +public class OrderDetails { + private String customerName; + private String address; + private String productCode; + private int quantity; + private double price; + + // Constructor, getters, and setters +} + +public void processOrder(OrderDetails orderDetails) { + // Implementation +} +``` + + diff --git a/docs/description/rulesets-codesize.xml-ExcessivePublicCount.md b/docs/description/rulesets-codesize.xml-ExcessivePublicCount.md index c2e8305..ce9ba15 100644 --- a/docs/description/rulesets-codesize.xml-ExcessivePublicCount.md +++ b/docs/description/rulesets-codesize.xml-ExcessivePublicCount.md @@ -1,7 +1,13 @@ +Classes with many public members are harder to test and maintain. Consider refactoring to smaller, focused classes to improve modularity. Example of issue: +```php +class LargeClass { + public $data1; public $data2; // too many attributes + public function method1() {} // too many methods +} +class ExtractedClass { + private $data1; // limited and focused attributes + public function method1() {} // encapsulated and focused methods +} +``` -A large number of public methods and attributes declared in a class can indicate -the class may need to be broken up. Properly testing a class with a large number of -publicly exposed members is difficult and time consuming. - -[Source](http://phpmd.org/rules/codesize.html#excessivepubliccount) - \ No newline at end of file + diff --git a/docs/description/rulesets-codesize.xml-NPathComplexity.md b/docs/description/rulesets-codesize.xml-NPathComplexity.md index 380a315..555664b 100644 --- a/docs/description/rulesets-codesize.xml-NPathComplexity.md +++ b/docs/description/rulesets-codesize.xml-NPathComplexity.md @@ -1,26 +1,22 @@ +Calculates the number of possible execution paths in your methods. High NPath complexity, typically over 200, suggests the need for refactoring to improve maintainability. -NPath complexity measures all the possible code paths in your methods. For example, the following method has NPath complexity of 8: +Example: - - function foo($value) { - $result = ''; - - if($value % 3 == 0) { - $result .= 'divisible by 3'; - } - - if($value % 5 == 0) { - $result .= 'divisible by 5'; - } - - if(!$result) { - $result = $value; - } - - return $result; +``` +function foo($value) { + $result = ''; + if($value % 3 == 0) { + $result .= 'divisible by 3'; } + if($value % 5 == 0) { + $result .= 'divisible by 5'; + } + if(!$result) { + $result = $value; + } + return $result; +} +// NPath complexity: 8 +``` -As a rule of thumb, methods with NPath complexity higher than 200 should be refactored. - -[Source](http://phpmd.org/rules/codesize.html#npathcomplexity) - \ No newline at end of file + diff --git a/docs/description/rulesets-codesize.xml-TooManyFields.md b/docs/description/rulesets-codesize.xml-TooManyFields.md index a4d4968..f89e36b 100644 --- a/docs/description/rulesets-codesize.xml-TooManyFields.md +++ b/docs/description/rulesets-codesize.xml-TooManyFields.md @@ -1,7 +1,26 @@ +Classes with excessive fields are difficult to manage. Refactor these classes by grouping related fields into well-defined smaller classes. For example, replace separate `zip`, `city`, and `country` fields with an `Address` class. This improves code readability and maintainability. -Classes with lots of fields are difficult to maintain. -You should redesign them and group the information in other classes - ex: instead of `zip`, `city` -and `country` fields you could have an `Address` class +Example: +```java +// Issue: Too many fields +class Person { + String name; + String zip; + String city; + String country; +} -[Source](http://phpmd.org/rules/codesize.html#toomanyfields) - \ No newline at end of file +// Solution: Using a dedicated Address class +class Person { + String name; + Address address; +} + +class Address { + String zip; + String city; + String country; +} +``` + + diff --git a/docs/description/rulesets-codesize.xml-TooManyMethods.md b/docs/description/rulesets-codesize.xml-TooManyMethods.md index aa325e0..5b923df 100644 --- a/docs/description/rulesets-codesize.xml-TooManyMethods.md +++ b/docs/description/rulesets-codesize.xml-TooManyMethods.md @@ -1,5 +1,25 @@ +Classes with numerous methods are complex and hard to maintain. Break them into smaller, focused classes for better readability and maintainability. -Classes with lots of methods are difficult to maintain. You should refactor the code in order to reduce complexity. +Example: +```php +// Before +class User { + function create() { /*...*/ } + function delete() { /*...*/ } + function update() { /*...*/ } + function getProfile() { /*...*/ } + // Many more methods... +} -[Source](http://phpmd.org/rules/codesize.html#toomanymethods) - \ No newline at end of file +// After +class User { + function getProfile() { /*...*/ } +} +class UserService { + function createUser() { /*...*/ } + function deleteUser() { /*...*/ } + function updateUser() { /*...*/ } +} +``` + + diff --git a/docs/description/rulesets-controversial.xml-CamelCaseClassName.md b/docs/description/rulesets-controversial.xml-CamelCaseClassName.md index 94d353c..0e178dc 100644 --- a/docs/description/rulesets-controversial.xml-CamelCaseClassName.md +++ b/docs/description/rulesets-controversial.xml-CamelCaseClassName.md @@ -1,11 +1,8 @@ - -Naming PHP classes in camel case is considered a best practice. Instead of writing: - - class my_class { } - -You should write: - - class MyClass { } - -[Source](http://phpmd.org/rules/controversial.html#camelcaseclassname) - \ No newline at end of file +Class names in PHP should use CamelCase for better readability and consistency. For example, use `class MyClass` instead of `class my_class`. +Example: +``` +class my_class { } // Incorrect +class MyClass { } // Correct +``` + + diff --git a/docs/description/rulesets-controversial.xml-CamelCaseMethodName.md b/docs/description/rulesets-controversial.xml-CamelCaseMethodName.md index e56c1aa..9eedb59 100644 --- a/docs/description/rulesets-controversial.xml-CamelCaseMethodName.md +++ b/docs/description/rulesets-controversial.xml-CamelCaseMethodName.md @@ -1,16 +1,9 @@ - -Naming methods in camel case is considered a best practice. Instead of writing: - - class MyClass { - public function my_method() { } - } - -You should write: - - class MyClass { - public function myMethod() { } - - } - -[Source](http://phpmd.org/rules/controversial.html#camelcasemethodname) - \ No newline at end of file +Consistently use camel case for method names to enhance code readability and maintainability. Avoid using underscores. Example of incorrect and correct method naming: +```php +class MyClass { + public function my_method() {} // Incorrect + public function myMethod() {} // Correct +} +``` + + diff --git a/docs/description/rulesets-controversial.xml-CamelCaseParameterName.md b/docs/description/rulesets-controversial.xml-CamelCaseParameterName.md index 07729c9..f9c638c 100644 --- a/docs/description/rulesets-controversial.xml-CamelCaseParameterName.md +++ b/docs/description/rulesets-controversial.xml-CamelCaseParameterName.md @@ -1,15 +1,13 @@ +For better readability, name method parameters using camel case. Avoid underscores. -Naming methods in camel case is considered a best practice. Instead of writing: +**Issue**: +```php +function exampleFunction($some_parameter) { } +``` - class MyClass { - public function getSomething($some_argument) { } - } +**Solution**: +```php +function exampleFunction($someParameter) { } +``` -You should write: - - class MyClass { - public function getSomething($someArgument) { } - } - -[Source](http://phpmd.org/rules/controversial.html#camelcaseparametername) - \ No newline at end of file + diff --git a/docs/description/rulesets-controversial.xml-CamelCasePropertyName.md b/docs/description/rulesets-controversial.xml-CamelCasePropertyName.md index 1b3eabc..72b2a60 100644 --- a/docs/description/rulesets-controversial.xml-CamelCasePropertyName.md +++ b/docs/description/rulesets-controversial.xml-CamelCasePropertyName.md @@ -1,15 +1,3 @@ +Ensure all class properties are named using camel case for consistency and readability. For example, instead of `$my_property`, use `$MyProperty`. -Naming class properties in camel case is considered a best practice. Instead of writing: - - class MyClass { - protected $my_property; - } - -You should write: - - class MyClass { - protected $MyProperty; - } - -[Source](http://phpmd.org/rules/controversial.html#camelcasepropertyname) - \ No newline at end of file + diff --git a/docs/description/rulesets-controversial.xml-CamelCaseVariableName.md b/docs/description/rulesets-controversial.xml-CamelCaseVariableName.md index 9b16232..29a53c8 100644 --- a/docs/description/rulesets-controversial.xml-CamelCaseVariableName.md +++ b/docs/description/rulesets-controversial.xml-CamelCaseVariableName.md @@ -1,19 +1,13 @@ - -Naming variables in camel case is considered a best practice. Instead of writing: - - class MyClass { - public function getSomething() { - $some_variable = new Something(); - } - } - -You should write: - - class MyClass { - public function getSomething() { - $someVariable = new Something(); - } - } - -[Source](http://phpmd.org/rules/controversial.html#camelcasevariablename) - \ No newline at end of file +Ensure readability and maintain coding standards by using camel case for variable names. Replace variables like `$some_variable` with `$someVariable`. This enhances consistency across the codebase. + +Example: +```php +class MyClass { + public function getSomething() { + $someVariable = new Something(); // Correct + $some_variable = new Something(); // Incorrect + } +} +``` + + diff --git a/docs/description/rulesets-controversial.xml-Superglobals.md b/docs/description/rulesets-controversial.xml-Superglobals.md index f02ea4a..d5a3a67 100644 --- a/docs/description/rulesets-controversial.xml-Superglobals.md +++ b/docs/description/rulesets-controversial.xml-Superglobals.md @@ -1,11 +1,12 @@ +Directly accessing PHP superglobals scatters dependencies and poses security risks. Instead, encapsulate their access within a request class provided by your framework to enhance maintainability and security. -[Superglobal variables](http://www.php.net/manual/en/language.variables.superglobals.php) in PHP should not be accessed directly. -Instead of writing: +Example: +`` +// Direct access - not recommended +$name = $_POST['foo']; - $name = $_POST['foo']; +// Encapsulated access - recommended +$name = $request->get('foo'); +`` -You should encapsulate the call in an single class. -Most PHP frameworks already wrap Superglobals into a request object so you can use that. - -[Source](http://phpmd.org/rules/controversial.html#superglobals) - \ No newline at end of file + diff --git a/docs/description/rulesets-design.xml-EvalExpression.md b/docs/description/rulesets-design.xml-EvalExpression.md index 4067b2c..6e7dd9d 100644 --- a/docs/description/rulesets-design.xml-EvalExpression.md +++ b/docs/description/rulesets-design.xml-EvalExpression.md @@ -1,17 +1,11 @@ +`Eval` expressions are risky, hard to test, and reduce code quality. Avoid using `eval` by substituting with regular code constructs. For example: -An eval-expression is untestable, a security risk and bad practice. -Therefore it should be avoided. -Consider to replace the eval-expression with regular code. +```php +// Avoid +eval('$param = 23;'); -Example to avoid: +// Safer alternative +$param = 23; +``` - class Foo { - public function bar($param) { - if ($param === 42) { - eval('$param = 23;'); - } - } - } - -[Source](http://phpmd.org/rules/design.html#evalexpression) - \ No newline at end of file + diff --git a/docs/description/rulesets-design.xml-ExitExpression.md b/docs/description/rulesets-design.xml-ExitExpression.md index c7aed15..8d06cad 100644 --- a/docs/description/rulesets-design.xml-ExitExpression.md +++ b/docs/description/rulesets-design.xml-ExitExpression.md @@ -1,17 +1,14 @@ - -An exit-expression within regular code is untestable and therefore it should be avoided. -Consider to move the exit-expression into some kind of startup script where an -error/exception code is returned to the calling environment. - -Example to avoid: - - class Foo { - public function bar($param) { - if ($param === 42) { - exit(23); - } +Exit statements make code untestable and harder to maintain. Instead, handle termination logic in higher-level scripts, returning appropriate error codes to the caller. + +Incorrect: +``` +class Foo { + public function bar($param) { + if ($param === 42) { + exit(23); } } +} +``` -[Source](http://phpmd.org/rules/design.html#exitexpression) - \ No newline at end of file + diff --git a/docs/description/rulesets-design.xml-GotoStatement.md b/docs/description/rulesets-design.xml-GotoStatement.md index 85e55fe..bed9bb0 100644 --- a/docs/description/rulesets-design.xml-GotoStatement.md +++ b/docs/description/rulesets-design.xml-GotoStatement.md @@ -1,28 +1,43 @@ +`Goto` statements complicate code readability and control flow. Replace them with structured control mechanisms for better clarity and maintainability. -Goto makes code harder to read and it is nearly impossible to understand the control flow of an application -that uses this language construct. Therefore it should be avoided. -Consider to replace Goto with regular control structures and separate methods/function, which are easier to read. - -Example to avoid: +Issue example: +```php +class Foo { + public function bar($param) { + A: + if ($param === 42) { + goto X; + } + Y: + if (time() % 42 === 23) { + goto Z; + } + X: + if (time() % 23 === 42) { + goto Y; + } + Z: + return 42; + } +} +``` - class Foo { - public function bar($param) { - A: - if ($param === 42) { - goto X; - } - Y: - if (time() % 42 === 23) { - goto Z; - } - X: - if (time() % 23 === 42) { - goto Y; - } - Z: +Solution: +```php +class Foo { + public function bar($param) { + if ($param === 42) { + return 42; + } + if (time() % 42 === 23) { + return 42; + } + if (time() % 23 === 42) { return 42; } + return 42; } +} +``` -[Source](http://phpmd.org/rules/design.html#gotostatement) - \ No newline at end of file + diff --git a/docs/patterns.json b/docs/patterns.json index 550706b..1a39389 100644 --- a/docs/patterns.json +++ b/docs/patterns.json @@ -5,16 +5,17 @@ { "patternId": "rulesets-cleancode.xml-ElseExpression", "category": "CodeStyle", - "title": "Avoid else expressions", - "description": "Use return statements instead of else expression", + "title": "Eliminate Else Blocks with Early Returns", + "description": "Improves code clarity by using early returns.", "level": "Info", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:34:19.626Z" }, { "patternId": "rulesets-cleancode.xml-StaticAccess", "category": "CodeStyle", - "title": "Avoid static access", - "description": "Static access leads to hard to test code", + "title": "Avoid Static Method Access", + "description": "Reduces dependencies and improves testability.", "level": "Info", "parameters": [ { @@ -22,7 +23,8 @@ "default": "" } ], - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:34:41.151Z" }, { "patternId": "rulesets-cleancode.xml-BooleanArgumentFlag", @@ -75,8 +77,8 @@ { "patternId": "rulesets-codesize.xml-CyclomaticComplexity", "category": "CodeStyle", - "title": "Cyclomatic complexity", - "description": "This pattern reports methods with high cyclomatic complexity", + "title": "Understanding Cyclomatic Complexity", + "description": "Measure complexity by counting decision points in your code.", "parameters": [ { "name": "reportLevel", @@ -92,13 +94,14 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:35:04.586Z" }, { "patternId": "rulesets-codesize.xml-NPathComplexity", "category": "CodeStyle", - "title": "NPath complexity", - "description": "This pattern reports methods with a large number of possible paths", + "title": "Understanding and Managing NPath Complexity", + "description": "Measures possible code paths in methods.", "parameters": [ { "name": "minimum", @@ -106,13 +109,14 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:35:24.530Z" }, { "patternId": "rulesets-codesize.xml-ExcessiveMethodLength", "category": "CodeStyle", - "title": "Excessive method length", - "description": "This pattern reports excessively long methods.", + "title": "Avoid Long Methods for Better Code Quality", + "description": "Flag excessively long methods for refactoring.", "parameters": [ { "name": "minimum", @@ -120,13 +124,14 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:35:59.055Z" }, { "patternId": "rulesets-codesize.xml-ExcessiveClassLength", "category": "CodeStyle", - "title": "Excessive class length", - "description": "This pattern reports excessively long classes.", + "title": "Optimize Class Size for Better Maintainability", + "description": "Encourages breaking down lengthy class files.", "parameters": [ { "name": "minimum", @@ -134,13 +139,14 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:36:37.088Z" }, { "patternId": "rulesets-codesize.xml-ExcessiveParameterList", "category": "CodeStyle", - "title": "Excessive parameters", - "description": "This pattern reports methods with a high number of parameters.", + "title": "Refactor Long Parameter Lists", + "description": "Refactor long parameter lists for better maintainability.", "parameters": [ { "name": "minimum", @@ -148,13 +154,14 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:37:01.827Z" }, { "patternId": "rulesets-codesize.xml-ExcessivePublicCount", "category": "CodeStyle", - "title": "Excessive public attributes", - "description": "This pattern reports classes with a high number of public methods and attributes.", + "title": "Refactor Classes with Excessive Public Members", + "description": "Too many public methods and attributes in a class.", "parameters": [ { "name": "minimum", @@ -162,13 +169,14 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:37:22.495Z" }, { "patternId": "rulesets-codesize.xml-TooManyFields", "category": "CodeStyle", - "title": "Excessive fields", - "description": "This pattern reports classes with a high number of fields.", + "title": "Minimize Class Field Count", + "description": "Classes with too many fields can be hard to maintain.", "parameters": [ { "name": "maxfields", @@ -176,13 +184,14 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:37:49.183Z" }, { "patternId": "rulesets-codesize.xml-TooManyMethods", "category": "CodeStyle", - "title": "Excessive methods", - "description": "This pattern reports classes with a high number of methods.", + "title": "Refactor Classes with Excessive Methods", + "description": "Classes with too many methods are hard to maintain.", "parameters": [ { "name": "maxmethods", @@ -190,7 +199,8 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:38:09.790Z" }, { "patternId": "rulesets-codesize.xml-TooManyPublicMethods", @@ -213,8 +223,8 @@ { "patternId": "rulesets-codesize.xml-ExcessiveClassComplexity", "category": "CodeStyle", - "title": "Weighted method count", - "description": "This pattern reports classes with a high weighted method count.", + "title": "Manage Class Complexity for Better Code Maintainability", + "description": "Monitor and manage class complexity effectively.", "parameters": [ { "name": "maximum", @@ -222,80 +232,90 @@ } ], "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:38:32.968Z" }, { "patternId": "rulesets-controversial.xml-Superglobals", "category": "CodeStyle", - "title": "Encapsulate Superglobals", - "description": "Prohibit direct access to superglobal variables", + "title": "Encapsulate PHP Superglobal Variables", + "description": "Avoid direct access to PHP superglobal variables.", "level": "Info", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:38:48.061Z" }, { "patternId": "rulesets-controversial.xml-CamelCaseClassName", "category": "CodeStyle", - "title": "Enforce CamelCase in classes", - "description": "Requires all class names to use the CamelCase style", + "title": "Use CamelCase for PHP Class Names", + "description": "Ensures PHP classes follow CamelCase naming convention.", "level": "Info", - "enabled": false + "enabled": false, + "patPatBotReviewed": "2024-05-24T11:39:02.495Z" }, { "patternId": "rulesets-controversial.xml-CamelCasePropertyName", "category": "CodeStyle", - "title": "Enforce CamelCase in properties", - "description": "Requires all property names to use the CamelCase style", + "title": "Use Camel Case for Class Properties", + "description": "Standardize class properties using camel case.", "level": "Info", - "enabled": false + "enabled": false, + "patPatBotReviewed": "2024-05-24T11:39:16.793Z" }, { "patternId": "rulesets-controversial.xml-CamelCaseMethodName", "category": "CodeStyle", - "title": "Enforce CamelCase in methods", - "description": "Requires all method names to use the CamelCase style", + "title": "Enforce Camel Case for Method Names", + "description": "Ensure methods use camel case naming convention.", "level": "Info", - "enabled": false + "enabled": false, + "patPatBotReviewed": "2024-05-24T11:39:42.439Z" }, { "patternId": "rulesets-controversial.xml-CamelCaseParameterName", "category": "CodeStyle", - "title": "Enforce CamelCase in parameters", - "description": "Requires all parameter names to use the CamelCase style", + "title": "Use Camel Case for Parameter Names", + "description": "Adopt camel case for clearer parameter naming.", "level": "Info", - "enabled": false + "enabled": false, + "patPatBotReviewed": "2024-05-24T11:39:58.213Z" }, { "patternId": "rulesets-controversial.xml-CamelCaseVariableName", "category": "CodeStyle", - "title": "Enforce CamelCase in variables", - "description": "Requires all variable names to use the CamelCase style", + "title": "Enforce Camel Case for Variable Names", + "description": "Use camel case for naming variables.", "level": "Warning", - "enabled": false + "enabled": false, + "patPatBotReviewed": "2024-05-24T11:40:19.967Z" }, { "patternId": "rulesets-design.xml-ExitExpression", "category": "ErrorProne", - "title": "Prohibit exit-expression", - "description": "Prohibit the use of exit-expressions within regular code, it is not testable", + "title": "Avoid Using Exit Statements in Code", + "description": "Avoid using exit expressions in regular code.", "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:40:38.352Z" }, { "patternId": "rulesets-design.xml-EvalExpression", "category": "Security", - "title": "Prohibit eval expression", - "description": "Prohibit the use of eval, it is untestable, a security risk and bad practice", + "title": "Avoid Using `eval` Expressions", + "description": "Replace `eval` expressions for security and maintainability.", "level": "Warning", "subcategory": "CommandInjection", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:40:54.376Z" }, { "patternId": "rulesets-design.xml-GotoStatement", "category": "ErrorProne", - "title": "Prohibit goto", - "description": "Prohibit the use of goto, it makes the code harder to read nearly impossible to understand", + "title": "Avoid Using Goto Statements", + "description": "Promote readability by avoiding `goto` statements.", "level": "Warning", - "enabled": true + "enabled": true, + "patPatBotReviewed": "2024-05-24T11:41:26.020Z" }, { "patternId": "rulesets-design.xml-NumberOfChildren",