Skip to content

Commit 7c58176

Browse files
nicklemgithub-actions[bot]
authored andcommitted
gpt: Automated pattern documentation updates
1 parent 8a794de commit 7c58176

12 files changed

+244
-149
lines changed

docs/description/description.json

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
[
22
{
33
"patternId": "rulesets-cleancode.xml-ElseExpression",
4-
"title": "Avoid else expressions",
5-
"description": "Use return statements instead of else expression",
6-
"timeToFix": 15
4+
"title": "Refactor Else Statements with Early Returns",
5+
"description": "Promotes early returns over else statements.",
6+
"timeToFix": 15,
7+
"patPatBotReviewed": "2024-05-23T14:35:52.861Z"
78
},
89
{
910
"patternId": "rulesets-cleancode.xml-StaticAccess",
10-
"title": "Avoid static access",
11-
"description": "Static access leads to hard to test code",
11+
"title": "Avoid Static Access to Reduce Dependencies",
12+
"description": "Static access heightens dependencies and complicates testing.",
1213
"timeToFix": 15,
1314
"parameters": [
1415
{
1516
"name": "exceptions",
1617
"description": "Comma-separated class name list of exceptions"
1718
}
18-
]
19+
],
20+
"patPatBotReviewed": "2024-05-23T14:35:59.524Z"
1921
},
2022
{
2123
"patternId": "rulesets-codesize.xml-CyclomaticComplexity",
22-
"title": "Cyclomatic complexity",
23-
"description": "This pattern reports methods with high cyclomatic complexity",
24+
"title": "Measuring Cyclomatic Complexity in Methods",
25+
"description": "Evaluates decision points to determine code complexity.",
2426
"parameters": [
2527
{
2628
"name": "reportLevel",
@@ -35,91 +37,99 @@
3537
"description": "Indicate if method average violation should be included"
3638
}
3739
],
38-
"timeToFix": 30
40+
"timeToFix": 30,
41+
"patPatBotReviewed": "2024-05-23T14:36:04.929Z"
3942
},
4043
{
4144
"patternId": "rulesets-codesize.xml-NPathComplexity",
42-
"title": "NPath complexity",
43-
"description": "This pattern reports methods with a large number of possible paths",
45+
"title": "NPath Complexity Detection",
46+
"description": "Measures possible execution paths in methods.",
4447
"parameters": [
4548
{
4649
"name": "minimum",
4750
"description": "Reporting threshold"
4851
}
4952
],
50-
"timeToFix": 30
53+
"timeToFix": 30,
54+
"patPatBotReviewed": "2024-05-23T14:36:13.622Z"
5155
},
5256
{
5357
"patternId": "rulesets-codesize.xml-ExcessiveMethodLength",
54-
"title": "Excessive method length",
55-
"description": "This pattern reports excessively long methods.",
58+
"title": "Method Length Warning",
59+
"description": "Long methods may indicate excessive functionality.",
5660
"parameters": [
5761
{
5862
"name": "minimum",
5963
"description": "Reporting threshold for the number of lines in a method"
6064
}
6165
],
62-
"timeToFix": 15
66+
"timeToFix": 15,
67+
"patPatBotReviewed": "2024-05-23T14:36:18.001Z"
6368
},
6469
{
6570
"patternId": "rulesets-codesize.xml-ExcessiveClassLength",
66-
"title": "Excessive class length",
67-
"description": "This pattern reports excessively long classes.",
71+
"title": "Reducing Excessive Class Length",
72+
"description": "Class files are too lengthy.",
6873
"parameters": [
6974
{
7075
"name": "minimum",
7176
"description": "Reporting threshold for the number of lines in a class"
7277
}
7378
],
74-
"timeToFix": 15
79+
"timeToFix": 15,
80+
"patPatBotReviewed": "2024-05-23T14:36:22.011Z"
7581
},
7682
{
7783
"patternId": "rulesets-codesize.xml-ExcessiveParameterList",
78-
"title": "Excessive parameters",
79-
"description": "This pattern reports methods with a high number of parameters.",
84+
"title": "Avoid Long Parameter Lists",
85+
"description": "Simplify functions by reducing long parameter lists.",
8086
"parameters": [
8187
{
8288
"name": "minimum",
8389
"description": "Reporting threshold for the number of arguments in a method"
8490
}
8591
],
86-
"timeToFix": 15
92+
"timeToFix": 15,
93+
"patPatBotReviewed": "2024-05-23T14:36:26.426Z"
8794
},
8895
{
8996
"patternId": "rulesets-codesize.xml-ExcessivePublicCount",
90-
"title": "Excessive public attributes",
91-
"description": "This pattern reports classes with a high number of public methods and attributes.",
97+
"title": "Too Many Public Members",
98+
"description": "A flag for classes with excessive public members.",
9299
"parameters": [
93100
{
94101
"name": "minimum",
95102
"description": "Reporting threshold for the number of public methods and attributes in a class"
96103
}
97104
],
98-
"timeToFix": 15
105+
"timeToFix": 15,
106+
"patPatBotReviewed": "2024-05-23T14:36:31.617Z"
99107
},
100108
{
101109
"patternId": "rulesets-codesize.xml-TooManyFields",
102-
"title": "Excessive fields",
103-
"description": "This pattern reports classes with a high number of fields.",
110+
"title": "Refactor Classes with Excessive Fields",
111+
"description": "Improve maintainability by redesigning classes with too many fields.",
104112
"parameters": [
105113
{
106114
"name": "maxfields",
107115
"description": "Reporting threshold for the number of fields in a class"
108116
}
109117
],
110-
"timeToFix": 15
118+
"timeToFix": 15,
119+
"patPatBotReviewed": "2024-05-23T14:36:37.334Z"
111120
},
112121
{
113122
"patternId": "rulesets-codesize.xml-TooManyMethods",
114-
"title": "Excessive methods",
115-
"description": "This pattern reports classes with a high number of methods.",
123+
"title": "Refactor Classes with Excessive Methods",
124+
"description": "Classes with too many methods require refactoring",
116125
"parameters": [
117126
{
118127
"name": "maxmethods",
119128
"description": "Reporting threshold for the number of methods in a class"
120129
}
121130
],
122-
"timeToFix": 15
131+
"timeToFix": 15,
132+
"patPatBotReviewed": "2024-05-23T14:36:44.282Z"
123133
},
124134
{
125135
"patternId": "rulesets-codesize.xml-ExcessiveClassComplexity",
Lines changed: 12 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,16 @@
1-
2-
Instead of using an else block, you can use an early return statement:
3-
4-
class Foo
1+
Improves readability by using early returns instead of else blocks to handle conditions more explicitly. Refactor code accordingly for better maintenance.
2+
```php
3+
class Foo
4+
{
5+
public function bar($flag)
56
{
6-
public function bar($flag)
7-
{
8-
if ($flag) {
9-
// one branch
10-
} else {
11-
// another branch
12-
}
7+
if ($flag) {
8+
// one branch
9+
return;
1310
}
11+
// another branch
1412
}
13+
}
14+
```
1515

16-
Rewrite without the else:
17-
18-
class Foo
19-
{
20-
public function bar($flag)
21-
{
22-
if ($flag) {
23-
// one branch
24-
return;
25-
}
26-
27-
// another branch
28-
}
29-
}
30-
16+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:35:52.861Z -->
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1+
Static access increases dependencies and results in code that is hard to test. Instead, inject dependencies through the constructor. For example, avoid using `self::method()` and use constructor injection:
2+
```
3+
class Example {
4+
private $dependency;
5+
public function __construct(Dependency $dependency) {
6+
$this->dependency = $dependency;
7+
}
18
2-
Static access increases dependencies and leads to hard to test code. You should instead
3-
inject dependencies through the constructor
9+
public function exampleMethod() {
10+
$this->dependency->method();
11+
}
12+
}
13+
```
414

5-
[Source](http://phpmd.org/rules/cleancode.html#staticaccess)
6-
15+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:35:59.524Z -->
Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
2-
Cyclomatic complexity is determined by the number of decision points in a method plus one for the method entry.
3-
The following keywords create new decision points: 'if', 'while', 'for', and 'case labels'. For example, this
4-
code has a cyclomatic complexity level of 2:
5-
6-
function foo()
7-
{
8-
$t=date("H");
9-
if ($t<"20")
10-
{
11-
echo "Have a good day!";
12-
}
1+
Cyclomatic complexity quantifies method complexity based on decision points like 'if' and 'for' statements. Scores range: 1-4 (low), 5-7 (medium), 8-10 (high), 11+ (very high). Simplify highly complex methods to improve maintainability and readability.
2+
3+
Example:
4+
```
5+
function foo() {
6+
$t = date("H");
7+
if ($t < "20") {
8+
echo "Have a good day!";
139
}
10+
}
11+
// Cyclomatic Complexity = 2
12+
```
1413

15-
1-4 indicates low complexity, 5-7 medium complexity, 8-10 high complexity and 11+ indicates very high complexity.
16-
17-
[Source](http://phpmd.org/rules/codesize.html#cyclomaticcomplexity)
18-
14+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:36:04.929Z -->
Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1+
Long Class files suggest that the class might handle too many responsibilities. Consider breaking it down into smaller classes to enhance manageability and readability.
12

2-
Long Class files are an indicator that the class may be trying to do too much.
3-
Try to break it down, and reduce the size to something manageable.
3+
Example:
4+
```php
5+
// Too Long
6+
class AdvertTest {
7+
// 1026 lines of code
8+
}
49

5-
[Source](http://phpmd.org/rules/codesize.html#excessiveclasslength)
6-
10+
// Improved
11+
class AdvertTest {
12+
// Splitting logic into multiple, focused classes
13+
}
14+
```
15+
16+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:36:22.011Z -->
Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
1+
Long methods can signal that a method is tasked with too much. To improve readability and maintainability, divide it into smaller, focused methods. For example:
12

2-
Long methods are an indicator that the method is doing too much.
3-
Try to break it down, and reduce the size to something manageable.
3+
```php
4+
// Problematic code
5+
function calculate() {
6+
// ... many lines of code
7+
}
48

5-
[Source](http://phpmd.org/rules/codesize.html#excessivemethodlength)
6-
9+
// Improved code
10+
function calculate() {
11+
calculatePartA();
12+
calculatePartB();
13+
}
14+
15+
function calculatePartA() {
16+
// logic for part A
17+
}
18+
19+
function calculatePartB() {
20+
// logic for part B
21+
}
22+
```
23+
24+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:36:18.001Z -->
Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
1+
Long parameter lists indicate that creating a new object to encapsulate the parameters may be beneficial. This enhances code readability and manageability. For example, replace:
2+
```php
3+
function createUser($firstName, $lastName, $email, $age) {}
4+
```
5+
with:
6+
```php
7+
class UserInfo {
8+
public $firstName;
9+
public $lastName;
10+
public $email;
11+
public $age;
12+
// Constructor and other methods...
13+
}
114

2-
Long parameter lists can indicate that a new object should be created to wrap the numerous parameters.
15+
function createUser(UserInfo $userInfo) {}
16+
```
317

4-
[Source](http://phpmd.org/rules/codesize.html#excessiveparameterlist)
5-
18+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:36:26.426Z -->
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1+
A class with many public methods and attributes often needs splitting to simplify testing and maintenance. Consider breaking it into smaller classes with focused responsibilities.
2+
```php
3+
class TooManyPublicMembers {
4+
public $attr1;
5+
public $attr2;
6+
// many more public attributes
17

2-
A large number of public methods and attributes declared in a class can indicate
3-
the class may need to be broken up. Properly testing a class with a large number of
4-
publicly exposed members is difficult and time consuming.
8+
public function method1() {}
9+
public function method2() {}
10+
// many more public methods
11+
}
512

6-
[Source](http://phpmd.org/rules/codesize.html#excessivepubliccount)
7-
13+
// Refactor to:
14+
class GroupedResponsibility {
15+
// fewer public members
16+
}
17+
```
18+
19+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:36:31.617Z -->

0 commit comments

Comments
 (0)