-
Notifications
You must be signed in to change notification settings - Fork 11
Fix static analysis errors #82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,14 +26,15 @@ trait subItems | |
| /** | ||
| * Subitems - ex. items of invoice. | ||
| * | ||
| * @return array of document items or null | ||
| * @return array<mixed> of document items or null | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll help you verify this PHPDoc inconsistency. Let me start by examining the method implementation and the related code. First, let's read the subItems.php file to see the context around line 29head -50 src/AbraFlexi/subItems.php | cat -n Let me check the file and read the relevant section: Check file size and read the methodwc -l src/AbraFlexi/subItems.php Read the getSubItems method around line 29sed -n '20,50p' src/AbraFlexi/subItems.php | cat -n Now let me see the complete getSubItems() method: Read the entire subItems.php file to find the getSubItems() methodcat -n src/AbraFlexi/subItems.php | head -100 <function_calls> Read the full filecat src/AbraFlexi/subItems.php Now let me search for the getDataValue() method to understand what it can return: Search for getDataValue method definitionrg -nP -A10 'function getDataValue(' --type=php Let me search more broadly: Search for getDataValue in all PHP files with contextrg -nP 'getDataValue' --type=php -B2 -A8 | head -60 Let me check the class hierarchy and the actual method: Find the Bitmask class to see getDataValue definitionfd -t f "Bitmask.php" --type f <function_calls> Find Bitmask file more broadlyfind . -name "itmask" -type f 2>/dev/null | head -10 <function_calls> List the directory structure to understand the layoutls -la src/AbraFlexi/ | head -20 <function_calls> Search for the class definition that getSubItems belongs to and check its parentrg -nP 'class.*Bitmask' --type=php Let me look at the actual implementation more carefully: Read subItems.php and get detailed contextcat -n src/AbraFlexi/subItems.php | sed -n '1,45p' <function_calls> Search for parent class and getDataValue implementationrg -nP 'extends|implements|trait' src/AbraFlexi/subItems.php --type=php <function_calls> Search in the whole codebase for Bitmask class definitionrg -n 'class Bitmask' --type=php <function_calls> Read Bitmask.php to find getDataValue methodwc -l src/AbraFlexi/Bitmask.php <function_calls> Search for getDataValue in Bitmaskrg -nP -A8 'function getDataValue' src/AbraFlexi/Bitmask.php <function_calls> Read Bitmask.phpcat src/AbraFlexi/Bitmask.php | head -150 | cat -n <function_calls> Search for getDataValue with full context in Bitmaskrg -n 'getDataValue' src/AbraFlexi/Bitmask.php -A15 -B3 <function_calls> Let's examine what getDataValue can return by looking at the full contextcat -n src/AbraFlexi/Bitmask.php | sed -n '1,200p' <function_calls> Check the complete file for data structure and return typesrg -n '$data[|protected|private|public.*data' src/AbraFlexi/Bitmask.php | head -20 <function_calls> Let's read the full Bitmask.php filewc -l src/AbraFlexi/Bitmask.php <function_calls> Read the full file content with line numberspython3 << 'EOF' <function_calls> Now read the subItems.php file completelypython3 << 'EOF' Now let me analyze both files together to understand the actual return type: Check if getDataValue has a return type annotation in Bitmask.phprg -nP '@return|function getDataValue' src/AbraFlexi/Bitmask.php -B2 -A2 <function_calls> Let's look at the complete implementation with line numbers for analysispython3 << 'EOF' Read the subItems.php file and analyze getSubItemswith open('src/AbraFlexi/subItems.php', 'r') as f: Find the getSubItems methodmatch = re.search(r'/**.?@return.?*/(.?)(?:^\spublic|^\sprivate|^\sprotected|$)', content, re.DOTALL | re.MULTILINE) Read Bitmask.php and check array access handlingprint("\n=== Checking Bitmask.php for array access ===") Find getDataValue functionfor i, line in enumerate(lines): <function_calls> Let's get the exact code for both methodspython3 << 'EOF' with open('src/AbraFlexi/subItems.php', 'r') as f: Extract getDataValue from Bitmaskimport re Extract getSubItems from subItemspattern = r'(.?@return.?public\s+function\s+getSubItems(.?}\s\n)' <function_calls> Simple approach: just get the key linesecho "=== Line 29 in subItems.php (the PHPDoc line in question) ===" echo "" Based on my verification of the codebase, I can now provide the rewritten review comment. The PHPDoc is misleading—the method never returns null. The public function getDataValue(string $key): mixed
{
return $this->data[$key] ?? [];
}The null coalescing operator ( 🤖 Prompt for AI Agents |
||
| */ | ||
| public function getSubItems() | ||
| { | ||
| return $this->getDataValue($this->getSubmenuName()); | ||
| } | ||
|
|
||
| /** | ||
| * @param array<mixed> $subitems | ||
| * @return bool | ||
| */ | ||
| public function setSubitems(array $subitems) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switch to
Functions::code()fixes the call-site, but watch deprecation and nullabilityDelegating
_getRecordCode()to\AbraFlexi\Functions::code()will resolve the previousself::code(...)static-analysis issue, but there are two follow‑ups worth addressing:Functions::code()is marked as deprecated in its own PHPDoc; longer term it would be better to align this method withRO::getRecordCode()and use theCodehelper (for example,Code::ensure(...)) so all code paths share the same, non‑deprecated implementation.@return string, but the method actually returnsnullwhen'kod'is empty. Consider updating the PHPDoc (and, if you add a return type, using?string) to keep the contract honest.These are small inconsistencies, but fixing them will make PHPStan happier and keep the API clearer.
🤖 Prompt for AI Agents