-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gpt: Automated pattern documentation updates
- Loading branch information
1 parent
487dd07
commit b330b27
Showing
22 changed files
with
15,318 additions
and
12,198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
Classes: Return Type Hint | ||
Verify all methods in CakePHP classes include return type hints to improve type safety and code quality. For instance, update methods like this: | ||
``` | ||
// Issue: Missing return type hint | ||
public function getUserName() { | ||
return $this->name; | ||
} | ||
// Solution: Added return type hint | ||
public function getUserName(): string { | ||
return $this->name; | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:35:15.695Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
Commenting: Doc Block Alignment | ||
Standardize the alignment of PHPDoc blocks in your code to enhance readability and maintainability. Ensure annotations align vertically and descriptions are properly indented. | ||
Example: | ||
```php | ||
/** | ||
* Calculate sum of two numbers. | ||
* | ||
* @param int $a First number. | ||
* @param int $b Second number. | ||
* @return int Sum of numbers. | ||
*/ | ||
function sum($a, $b) { | ||
return $a + $b; | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:35:34.132Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
Commenting: Function Comment | ||
This pattern ensures all functions in your CakePHP project have appropriate comments. Include descriptions, parameters, and return information to improve code readability and maintenance. | ||
|
||
Example: | ||
```php | ||
/** | ||
* Calculates the sum of two numbers. | ||
* | ||
* @param int $a First number | ||
* @param int $b Second number | ||
* @return int Sum of $a and $b | ||
*/ | ||
function calculateSum($a, $b) { | ||
return $a + $b; | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:35:54.152Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
Commenting: Inherit Doc | ||
Use the `@inheritDoc` tag to automatically include the parent method's documentation, ensuring clear and consistent documentation across your codebase. This reduces redundancy and simplifies maintenance. | ||
```php | ||
class BaseController { | ||
/** | ||
* Base action method. | ||
*/ | ||
public function action() { | ||
// Implementation | ||
} | ||
} | ||
|
||
class SubController extends BaseController { | ||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function action() { | ||
// Overridden implementation | ||
} | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:36:12.000Z --> |
23 changes: 22 additions & 1 deletion
23
docs/description/CakePHP_ControlStructures_ControlStructures.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,22 @@ | ||
Control Structures: Control Structures | ||
This pattern identifies improper or inefficient control structures in CakePHP code. Recommendations include adhering to coding standards, reducing redundancy, and applying security best practices. | ||
|
||
**Example Issue:** | ||
``` | ||
if (condition) { | ||
// code | ||
} elseif (otherCondition) { | ||
// code | ||
} else { | ||
// code | ||
} | ||
``` | ||
**Optimized Solution:** | ||
``` | ||
if (condition) { | ||
// code | ||
} else if (otherCondition) { | ||
// code | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:36:32.785Z --> |
22 changes: 21 additions & 1 deletion
22
docs/description/CakePHP_ControlStructures_ElseIfDeclaration.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
Control Structures: Else If Declaration | ||
Standardize the use of else if statements for readability and maintainability. Use `elseif` instead of `else if`. | ||
|
||
**Example - Incorrect:** | ||
```php | ||
if ($condition1) { | ||
// code | ||
} else if ($condition2) { | ||
// code | ||
} | ||
``` | ||
|
||
**Example - Correct:** | ||
```php | ||
if ($condition1) { | ||
// code | ||
} elseif ($condition2) { | ||
// code | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:36:50.734Z --> |
18 changes: 17 additions & 1 deletion
18
docs/description/CakePHP_ControlStructures_WhileStructures.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
Control Structures: While Structures | ||
Enforces coding standards and best practices for `while` loops in CakePHP. Avoid inefficient or problematic patterns. Ensure meaningful conditions and avoid infinite loops. | ||
|
||
```php | ||
// Inefficient and risky `while` loop | ||
while (true) { | ||
// Do something | ||
} | ||
|
||
// Improved version | ||
$isConditionMet = false; | ||
while (!$isConditionMet) { | ||
// Do something | ||
$isConditionMet = checkCondition(); | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:37:07.639Z --> |
21 changes: 20 additions & 1 deletion
21
docs/description/CakePHP_Formatting_BlankLineBeforeReturn.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,20 @@ | ||
Formatting: Blank Line Before Return | ||
This pattern ensures better code readability by adding a blank line before each return statement, making the exit points of functions clearer. | ||
|
||
**Example:** | ||
|
||
```php | ||
// Problematic code: | ||
function example() { | ||
$value = computeValue(); | ||
return $value; | ||
} | ||
|
||
// Corrected code: | ||
function example() { | ||
$value = computeValue(); | ||
|
||
return $value; | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:37:31.468Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
Functions: Closure Declaration | ||
Validates the proper declaration and formatting of anonymous functions in CakePHP. Helps maintain code consistency and readability. | ||
|
||
Example: | ||
```php | ||
// Issue: Improperly formatted closure | ||
$data = array_map(function($item){ return $item->value; }, $items); | ||
|
||
// Solution: Properly formatted closure | ||
$data = array_map(function ($item) { | ||
return $item->value; | ||
}, $items); | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:37:59.078Z --> |
17 changes: 16 additions & 1 deletion
17
docs/description/CakePHP_NamingConventions_ValidFunctionName.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
Naming Conventions: Valid Function Name | ||
Functions should follow lower camelCase, be descriptive without abbreviations, and use consistent prefixes for specific contexts. For instance, `getUserData` is preferred over `gUD`. | ||
|
||
Example: | ||
```php | ||
// Not Recommended | ||
public function gUD() { | ||
// Code to get user data | ||
} | ||
|
||
// Recommended | ||
public function getUserData() { | ||
// Code to get user data | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:38:13.709Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
Naming Conventions: Valid Trait Name | ||
Trait names should be in CamelCase and suffixed with 'Trait' for clarity. This ensures consistency and readability in codebases. Example: | ||
``` | ||
Incorrect: logging | ||
Correct: LoggingTrait | ||
```. | ||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:38:29.984Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
PHP: Disallow Short Open Tag | ||
Use long PHP open tags `<?php ?>` instead of shorthand `<? ?>` to improve code compatibility and readability. This practice ensures your code runs smoothly across different environments. | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:38:47.550Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
PHP: Single Quote | ||
To enhance performance and readability, use single quotes for strings that don't need variable interpolation. This avoids unnecessary parsing and adheres to coding standards. | ||
|
||
Example: | ||
```php | ||
// Inefficient | ||
echo "$message"; | ||
|
||
// Efficient | ||
echo '$message'; | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:39:02.692Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,17 @@ | ||
White Space: Empty Lines | ||
Ensures no consecutive empty lines and appropriate spacing for readability and maintenance. Remove extra empty lines to align with guidelines for a cleaner codebase. | ||
Example: | ||
```php | ||
// Incorrect | ||
function test() { | ||
|
||
|
||
echo 'hello'; | ||
} | ||
|
||
// Correct | ||
function test() { | ||
echo 'hello'; | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:39:22.072Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
White Space: Function Call Spacing | ||
Maintain consistent spacing in function calls by avoiding extra spaces after opening or before closing parentheses, and ensuring appropriate spaces around arguments. | ||
|
||
Example: | ||
``` | ||
Correct: $result = someFunction($arg1, $arg2); | ||
Incorrect: $result = someFunction( $arg1 ,$arg2 ); | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:39:45.125Z --> |
9 changes: 8 additions & 1 deletion
9
docs/description/CakePHP_WhiteSpace_FunctionClosingBraceSpace.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,8 @@ | ||
White Space: Function Closing Brace Space | ||
Maintains consistent whitespace usage before the closing brace of functions. Avoid trailing whitespace and ensure the closing brace is on a new line. Example: | ||
``` | ||
function exampleFunction() { | ||
// Code | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:40:09.792Z --> |
16 changes: 15 additions & 1 deletion
16
docs/description/CakePHP_WhiteSpace_FunctionOpeningBraceSpace.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,15 @@ | ||
White Space: Function Opening Brace Space | ||
Ensure there is a space between the closing parenthesis of a function definition and its opening brace. This improves readability and maintains coding standards. | ||
|
||
```php | ||
// Correct | ||
function example() { | ||
// function body | ||
} | ||
|
||
// Incorrect | ||
function example(){ | ||
// function body | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:40:26.925Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,21 @@ | ||
White Space: Function Spacing | ||
This pattern ensures consistent whitespace around function definitions to improve readability. Ensure two blank lines before function definitions and one blank line after. | ||
|
||
Example: | ||
```php | ||
// Correct | ||
class Sample { | ||
|
||
|
||
public function exampleFunction() { | ||
// function body | ||
} | ||
} | ||
// Incorrect | ||
class Sample { | ||
public function exampleFunction() { | ||
// function body | ||
} | ||
} | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:40:45.568Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
White Space: Tab And Space | ||
This pattern identifies lines where both tabs and spaces are used for indentation, prompting to replace them for consistency. For example: | ||
``` | ||
if (true) { | ||
⇥ echo 'Hello'; // mixed tab and spaces | ||
} | ||
``` | ||
Replace tabs or spaces to be consistent throughout the file. | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:41:02.963Z --> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,10 @@ | ||
Arrays: Array | ||
Ensures consistent and proper usage of arrays in Drupal, conforming to standards and avoiding common pitfalls. Check for deprecated structures and update as necessary. Example issue and solution: | ||
```php | ||
// Issue: Incorrect array structure | ||
$settings = array('name', 'value' => 'example'); | ||
|
||
// Solution: Correct structure | ||
$settings = array('name' => 'example', 'value' => 'example'); | ||
``` | ||
|
||
<!-- Codacy PatPatBot reviewed: 2024-05-24T11:41:18.582Z --> |
Oops, something went wrong.