Skip to content

Commit b8c5dcc

Browse files
nicklemgithub-actions[bot]
authored andcommitted
gpt: Automated pattern documentation updates
1 parent a3e066e commit b8c5dcc

File tree

5 files changed

+61
-64
lines changed

5 files changed

+61
-64
lines changed

docs/description/description.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[
22
{
33
"patternId": "rulesets-cleancode.xml-ElseExpression",
4-
"title": "Avoid else expressions",
5-
"description": "Use return statements instead of else expression",
4+
"title": "Avoid Unnecessary Else Blocks Using Early Returns",
5+
"description": "Replace else blocks with early return statements.",
66
"timeToFix": 15
77
},
88
{
99
"patternId": "rulesets-cleancode.xml-StaticAccess",
10-
"title": "Avoid static access",
11-
"description": "Static access leads to hard to test code",
10+
"title": "Avoid Static Access to Class Members",
11+
"description": "Use constructor injection for better testability and maintainability.",
1212
"timeToFix": 15,
1313
"parameters": [
1414
{
@@ -19,8 +19,8 @@
1919
},
2020
{
2121
"patternId": "rulesets-codesize.xml-CyclomaticComplexity",
22-
"title": "Cyclomatic complexity",
23-
"description": "This pattern reports methods with high cyclomatic complexity",
22+
"title": "Measure and Control Cyclomatic Complexity",
23+
"description": "Assess and reduce method decision points.",
2424
"parameters": [
2525
{
2626
"name": "reportLevel",
Lines changed: 16 additions & 30 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
5-
{
6-
public function bar($flag)
7-
{
8-
if ($flag) {
9-
// one branch
10-
} else {
11-
// another branch
12-
}
13-
}
14-
}
15-
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-
1+
Improves readability by removing else blocks when early returns suffice. Transform code like:
2+
```
3+
if ($flag) {
4+
// one branch
5+
} else {
6+
// another branch
7+
}
8+
```
9+
to:
10+
```
11+
if ($flag) {
12+
// one branch
13+
return;
14+
}
15+
// another branch
16+
```
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
1+
Using static access increases dependencies and makes code hard to test. Instead, inject dependencies through the constructor. Example of the issue:
2+
```
3+
class Example {
4+
public function doSomething() {
5+
$dependency = Foo::getInstance(); // static access
6+
// ...
7+
}
8+
}
9+
```
10+
Solution:
11+
```
12+
class Example {
13+
private $dependency;
14+
15+
public function __construct(Foo $dependency) {
16+
$this->dependency = $dependency;
17+
}
118
2-
Static access increases dependencies and leads to hard to test code. You should instead
3-
inject dependencies through the constructor
4-
5-
[Source](http://phpmd.org/rules/cleancode.html#staticaccess)
6-
19+
public function doSomething() {
20+
// Use $this->dependency
21+
}
22+
}
23+
```
Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
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 evaluates the number of decision points in a method. Keep complexity between 1-4 for low, 5-7 for moderate, 8-10 for high, and 11+ for very high complexity. Aim to refactor methods exceeding a complexity level of 10.
2+
3+
Example:
4+
```
5+
function foo() {
6+
$t = date("H");
7+
if ($t < "20") {
8+
echo "Have a good day!";
139
}
14-
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-
10+
}
11+
// Complexity: 2
12+
```

docs/patterns.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
{
66
"patternId": "rulesets-cleancode.xml-ElseExpression",
77
"category": "CodeStyle",
8-
"title": "Avoid else expressions",
9-
"description": "Use return statements instead of else expression",
8+
"title": "Avoid Unnecessary Else Blocks Using Early Returns",
9+
"description": "Replace else blocks with early return statements.",
1010
"level": "Info",
1111
"enabled": true
1212
},
1313
{
1414
"patternId": "rulesets-cleancode.xml-StaticAccess",
1515
"category": "CodeStyle",
16-
"title": "Avoid static access",
17-
"description": "Static access leads to hard to test code",
16+
"title": "Avoid Static Access to Class Members",
17+
"description": "Use constructor injection for better testability and maintainability.",
1818
"level": "Info",
1919
"parameters": [
2020
{
@@ -75,8 +75,8 @@
7575
{
7676
"patternId": "rulesets-codesize.xml-CyclomaticComplexity",
7777
"category": "CodeStyle",
78-
"title": "Cyclomatic complexity",
79-
"description": "This pattern reports methods with high cyclomatic complexity",
78+
"title": "Measure and Control Cyclomatic Complexity",
79+
"description": "Assess and reduce method decision points.",
8080
"parameters": [
8181
{
8282
"name": "reportLevel",

0 commit comments

Comments
 (0)