[php-nextgen]: Fix ArrayAccess parameter types#23315
[php-nextgen]: Fix ArrayAccess parameter types#23315coffeemakr wants to merge 1 commit intoOpenAPITools:masterfrom
Conversation
There was a problem hiding this comment.
3 issues found across 71 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php">
<violation number="1" location="samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php:973">
P3: ArrayAccess key type docs are inconsistent: class-level `@implements ArrayAccess<string, mixed>` conflicts with updated method PHPDocs that accept `int|string` offsets. Update the class-level generic to match the new key type.</violation>
</file>
<file name="samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/NullableClass.php">
<violation number="1" location="samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/NullableClass.php:739">
P2: ArrayAccess key type docs are inconsistent: class-level `@implements ArrayAccess<string, mixed>` conflicts with updated method docs allowing `int|string` offsets.</violation>
</file>
<file name="samples/client/echo_api/php-nextgen/src/Model/DefaultValue.php">
<violation number="1" location="samples/client/echo_api/php-nextgen/src/Model/DefaultValue.php:582">
P2: Class-level ArrayAccess template still declares string-only keys, but updated method docs now allow int|string (and offsetSet allows null append), creating a conflicting type contract that can confuse static analysis and API usage.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| * Returns true if offset exists. False otherwise. | ||
| * | ||
| * @param integer $offset Offset | ||
| * @param int|string $offset Offset |
There was a problem hiding this comment.
P2: ArrayAccess key type docs are inconsistent: class-level @implements ArrayAccess<string, mixed> conflicts with updated method docs allowing int|string offsets.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/NullableClass.php, line 739:
<comment>ArrayAccess key type docs are inconsistent: class-level `@implements ArrayAccess<string, mixed>` conflicts with updated method docs allowing `int|string` offsets.</comment>
<file context>
@@ -736,7 +736,7 @@ public function setObjectItemsNullable(?array $object_items_nullable): static
* Returns true if offset exists. False otherwise.
*
- * @param integer $offset Offset
+ * @param int|string $offset Offset
*
* @return boolean
</file context>
| * Returns true if offset exists. False otherwise. | ||
| * | ||
| * @param integer $offset Offset | ||
| * @param int|string $offset Offset |
There was a problem hiding this comment.
P2: Class-level ArrayAccess template still declares string-only keys, but updated method docs now allow int|string (and offsetSet allows null append), creating a conflicting type contract that can confuse static analysis and API usage.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/echo_api/php-nextgen/src/Model/DefaultValue.php, line 582:
<comment>Class-level ArrayAccess template still declares string-only keys, but updated method docs now allow int|string (and offsetSet allows null append), creating a conflicting type contract that can confuse static analysis and API usage.</comment>
<file context>
@@ -579,7 +579,7 @@ public function setStringNullable(?string $string_nullable): static
* Returns true if offset exists. False otherwise.
*
- * @param integer $offset Offset
+ * @param int|string $offset Offset
*
* @return boolean
</file context>
| @@ -970,7 +970,7 @@ public function setArrayRef(?array $array_ref): static | |||
| /** | |||
There was a problem hiding this comment.
P3: ArrayAccess key type docs are inconsistent: class-level @implements ArrayAccess<string, mixed> conflicts with updated method PHPDocs that accept int|string offsets. Update the class-level generic to match the new key type.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At samples/client/petstore/php-nextgen/OpenAPIClient-php/src/Model/FormatTest.php, line 973:
<comment>ArrayAccess key type docs are inconsistent: class-level `@implements ArrayAccess<string, mixed>` conflicts with updated method PHPDocs that accept `int|string` offsets. Update the class-level generic to match the new key type.</comment>
<file context>
@@ -970,7 +970,7 @@ public function setArrayRef(?array $array_ref): static
* Returns true if offset exists. False otherwise.
*
- * @param integer $offset Offset
+ * @param int|string $offset Offset
*
* @return boolean
</file context>
The model classes implement the
ArrayAccessinterface. The phpdoc specifies the key type to be a string. In the methods, the key type is defined asintin the PHPDoc. This PR changes it toint|string. I'm not 100% sure what the correct type would be, but including string is correct for sure.Also I think maybe the methods to access the fields could be moved to the
ModelInterface, with stronger typing than theArrayAccessinterface.PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Corrects
ArrayAccessoffset PHPDoc types inphp-nextgenmodels to accept both strings and integers, matching PHP behavior and reducing IDE/static analysis warnings. Updates the generator template and regenerates samples.modules/openapi-generator/src/main/resources/php-nextgen/model_generic.mustacheto useint|stringfor offset parameters (offsetExists,offsetGet,offsetUnset) andint|string|nullforoffsetSet.php-nextgenandphp-nextgen-streamingsample models to reflect the new PHPDoc types.Written for commit a5f6543. Summary will update on new commits.