Skip to content

Commit 71b9b5b

Browse files
nicklemgithub-actions[bot]
authored andcommitted
gpt: Automated pattern documentation updates
1 parent a383769 commit 71b9b5b

12 files changed

+244
-155
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": "Prefer Early Return Over Else Blocks",
5+
"description": "Encourage early returns instead of else blocks for clarity.",
6+
"timeToFix": 15,
7+
"patPatBotReviewed": "2024-05-23T14:53:40.117Z"
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",
12+
"description": "Static access increases dependencies and reduces testability.",
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:53:46.190Z"
1921
},
2022
{
2123
"patternId": "rulesets-codesize.xml-CyclomaticComplexity",
22-
"title": "Cyclomatic complexity",
23-
"description": "This pattern reports methods with high cyclomatic complexity",
24+
"title": "Cyclomatic Complexity Evaluation",
25+
"description": "Assess complexity based on decision points.",
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:53:57.443Z"
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 in Code Methods",
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:54:03.492Z"
5155
},
5256
{
5357
"patternId": "rulesets-codesize.xml-ExcessiveMethodLength",
54-
"title": "Excessive method length",
55-
"description": "This pattern reports excessively long methods.",
58+
"title": "Break Down Long Methods",
59+
"description": "Long methods indicate potential over-complexity; simplify them.",
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:54:07.770Z"
6368
},
6469
{
6570
"patternId": "rulesets-codesize.xml-ExcessiveClassLength",
66-
"title": "Excessive class length",
67-
"description": "This pattern reports excessively long classes.",
71+
"title": "Class Exceeds Recommended Length",
72+
"description": "Indicates a class is too lengthy and complex.",
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:54:12.269Z"
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": "Refactor Long Parameter Lists",
85+
"description": "New object to wrap numerous parameters.",
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:54:18.537Z"
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": "Excessive Public Members in Class",
98+
"description": "Break up classes with too many 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:54:24.033Z"
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": "Maintainability Concerns with Excessive Class Fields",
111+
"description": "Redesign 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:54:30.033Z"
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": "Reduce complexity by refactoring classes with too many methods.",
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:54:35.909Z"
123133
},
124134
{
125135
"patternId": "rulesets-codesize.xml-ExcessiveClassComplexity",
Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,14 @@
1-
2-
Instead of using an else block, you can use an early return statement:
3-
4-
class Foo
5-
{
6-
public function bar($flag)
7-
{
8-
if ($flag) {
9-
// one branch
10-
} else {
11-
// another branch
12-
}
1+
Using early returns in place of else blocks enhances code readability by reducing nesting. This approach facilitates easier comprehension and maintenance of the code.
2+
```php
3+
class Foo {
4+
public function bar($flag) {
5+
if ($flag) {
6+
// one branch
7+
return;
138
}
9+
// another branch
1410
}
11+
}
12+
```
1513

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-
14+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:53:40.117Z -->
Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,25 @@
1+
Static access increases code dependencies and hinders testability. Instead, inject dependencies through the constructor to promote flexibility. For example:
12

2-
Static access increases dependencies and leads to hard to test code. You should instead
3-
inject dependencies through the constructor
3+
```php
4+
// Issue
5+
class Example {
6+
public function doSomething() {
7+
Logger::log('message');
8+
}
9+
}
410

5-
[Source](http://phpmd.org/rules/cleancode.html#staticaccess)
6-
11+
// Solution
12+
class Example {
13+
private $logger;
14+
15+
public function __construct(Logger $logger) {
16+
$this->logger = $logger;
17+
}
18+
19+
public function doSomething() {
20+
$this->logger->log('message');
21+
}
22+
}
23+
```
24+
25+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:53:46.190Z -->
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1+
Cyclomatic complexity measures the decision points in a method plus one for the method entry. Low complexity (1-4) is preferred, while very high (11+) necessitates refactoring. Address complex methods using helper methods and refactoring. Example:
12

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-
}
3+
```php
4+
function foo() {
5+
$t = date("H");
6+
if ($t < "20") {
7+
echo "Have a good day!";
138
}
9+
}
10+
```
1411

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-
12+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:53:57.443Z -->
Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
A lengthy class file suggests it may be taking on too much responsibility. Refactor the class by breaking it down into smaller, more manageable units.
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+
// Problematic Class
6+
class LargeClass {
7+
// many methods and properties
8+
}
49

5-
[Source](http://phpmd.org/rules/codesize.html#excessiveclasslength)
6-
10+
// Refactored Code
11+
class SmallerClass1 {
12+
// fewer methods and properties
13+
}
14+
class SmallerClass2 {
15+
// fewer methods and properties
16+
}
17+
```
18+
19+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:54:12.269Z -->
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1+
Long methods often suggest that too much logic is encapsulated in one place. To improve code readability and maintainability, break down long methods into smaller helper methods. This reduces complexity and makes the code cleaner and easier to manage.
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.
4-
5-
[Source](http://phpmd.org/rules/codesize.html#excessivemethodlength)
6-
3+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:54:07.770Z -->
Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
1+
Long parameter lists can be a sign that your method requires too many inputs, making it hard to maintain and understand. Consider creating a new object that encapsulates these numerous parameters. For example:
2+
```
3+
// Problematic Code
4+
function bookTicket($flightNumber, $departureDate, $returnDate, $passengerName, $seatPreference) {
5+
...
6+
}
17
2-
Long parameter lists can indicate that a new object should be created to wrap the numerous parameters.
8+
// Refactored Code
9+
class TicketDetails {
10+
public $flightNumber;
11+
public $departureDate;
12+
public $returnDate;
13+
public $passengerName;
14+
public $seatPreference;
15+
16+
// constructor and other methods
17+
}
318
4-
[Source](http://phpmd.org/rules/codesize.html#excessiveparameterlist)
5-
19+
function bookTicket(TicketDetails $ticketDetails) {
20+
...
21+
}
22+
```
23+
24+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:54:18.537Z -->
Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1+
A large number of public methods and attributes in a class can indicate it needs to be broken up. This complexity makes thorough testing difficult and time-consuming. Consider refactoring the class to reduce the number of public members.
2+
Example:
3+
```php
4+
// Avoid
5+
class ComplexClass {
6+
public function method1() {}
7+
public function method2() {}
8+
// ... many more methods and attributes
9+
}
110

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.
11+
// Refactor to
12+
class SimplifiedClass {
13+
public function method1() {}
14+
}
515

6-
[Source](http://phpmd.org/rules/codesize.html#excessivepubliccount)
7-
16+
class AnotherClass {
17+
public function method2() {}
18+
}
19+
```
20+
21+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:54:24.033Z -->
Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
1-
2-
NPath complexity measures all the possible code paths in your methods. For example, the following method has NPath complexity of 8:
3-
4-
5-
function foo($value) {
6-
$result = '';
7-
8-
if($value % 3 == 0) {
9-
$result .= 'divisible by 3';
10-
}
11-
12-
if($value % 5 == 0) {
13-
$result .= 'divisible by 5';
14-
}
15-
16-
if(!$result) {
17-
$result = $value;
18-
}
19-
20-
return $result;
1+
NPath complexity is the count of execution paths in a method. Methods exceeding an NPath complexity of 200 should be refactored to improve maintainability. For example, nested conditions create multiple paths.
2+
3+
```php
4+
function example($value) {
5+
if ($value > 0 && $value < 10) {
6+
return 'single digit';
7+
} elseif ($value >= 10 && $value < 100) {
8+
return 'double digits';
9+
} else {
10+
return 'other';
2111
}
12+
}
13+
```
2214

23-
As a rule of thumb, methods with NPath complexity higher than 200 should be refactored.
24-
25-
[Source](http://phpmd.org/rules/codesize.html#npathcomplexity)
26-
15+
<!-- Codacy PatPatBot reviewed: 2024-05-23T14:54:03.492Z -->

0 commit comments

Comments
 (0)