Skip to content

Fix static analysis: widen return types to static, add explicit Container/K8sSecret methods#20

Merged
loks0n merged 11 commits intomainfrom
feat-type-safety-v2
Apr 1, 2026
Merged

Fix static analysis: widen return types to static, add explicit Container/K8sSecret methods#20
loks0n merged 11 commits intomainfrom
feat-type-safety-v2

Conversation

@loks0n
Copy link
Copy Markdown
Member

@loks0n loks0n commented Apr 1, 2026

Summary

Follow-up to partial type-safety fixes already landed (refresh, refreshOriginal, apply, jsonPatch, jsonMergePatch).

  • Part A: RunsClusterOperations — changed get(), create(), createOrUpdate(), syncWithCluster(), updateStatus(), jsonPatchStatus(), jsonMergePatchStatus() return types to static. Without this, code like $cluster->secret()->get()->getData() causes static analyzers to report undefined methods since the return type is widened to the base class.
  • Part B: Replaced __call magic reliance with explicit typed methods on Container (setName/getName, setImagePullPolicy/getImagePullPolicy, setCommand/getCommand, setArgs/getArgs, setWorkingDir/getWorkingDir) and K8sSecret (setType/getType). The __call fallback remains for ad-hoc/CRD attributes.
  • CI: Added concurrency group to cancel outdated PR runs on new pushes.

Test plan

  • vendor/bin/phpunit --filter Test$ passes (unit tests)
  • vendor/bin/psalm passes with no new issues
  • Integration suite passes against a live cluster (CI=true vendor/bin/phpunit)

🤖 Generated with Claude Code

loks0n and others added 3 commits April 1, 2026 16:06
…ntainer/K8sSecret methods

- Change get(), create(), createOrUpdate(), syncWithCluster() return types
  from K8sResource to static so concrete subclass methods are visible to
  PHPStan/Psalm after cluster operations
- Change updateStatus(), jsonPatchStatus(), jsonMergePatchStatus() from
  self to static to maintain the covariant chain in subclasses
- Add explicit setName/getName, setImagePullPolicy/getImagePullPolicy,
  setCommand/getCommand, setArgs/getArgs, setWorkingDir/getWorkingDir
  methods on Container instead of relying on __call magic
- Add explicit setType/getType methods on K8sSecret instead of relying
  on __call magic

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Cancels in-progress runs when a new push arrives on the same branch,
but leaves main runs to complete so coverage reports aren't dropped.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 1, 2026

Greptile Summary

This PR improves static analysis correctness across the library by widening return types to static in RunsClusterOperations and K8sScale, and replaces __call magic on Container and K8sSecret with explicit typed methods. The core PHP changes are well-executed and achieve the stated goal.

The main concern is in composer.json: the production dependency constraints for illuminate/macroable, illuminate/support, and symfony/process are silently narrowed, dropping declared support for Laravel 13 and Symfony 8 from the library's install requirements — not just from CI. Library consumers already running Laravel 13 will be blocked from upgrading to this version. This is an undocumented breaking change that the PR description does not address.

Other changes:

  • RunsClusterOperations: !instanceofis_array guards in jsonPatchStatus/jsonMergePatchStatus are logically equivalent for the declared JsonPatch|array union type — correct and cleaner for static analyzers
  • CI: concurrency group added to cancel stale PR runs; K8s matrix reduced to one version while PHP 8.3/8.4/8.5 remain; laravel/pint pinned to stable ^1.29; minimum-stability: dev removed (no longer needed after pint stabilization)

Confidence Score: 4/5

Safe to merge after clarifying the intentional scope of the composer.json constraint narrowing and documenting it in the PR description or changelog.

All PHP source changes (return type widening, explicit Container/K8sSecret methods, is_array guards) are correct and clean. The one P1 finding is in composer.json: dropping Laravel 13 and Symfony 8 from production constraints is an undocumented breaking change for library consumers that the author should either document as intentional or revert.

composer.json — constraint narrowing silently drops Laravel 13 and Symfony 8 support for library consumers.

Important Files Changed

Filename Overview
.github/workflows/ci.yml Adds concurrency group to cancel stale PR runs; reduces K8s matrix to one version (1.33.10) while keeping PHP 8.3/8.4/8.5; simplifies cache key; removes Laravel/testbench matrix dimension.
composer.json Narrows production illuminate constraints from ^12.0
src/Instances/Container.php Adds explicit typed methods (setName/getName, setImagePullPolicy/getImagePullPolicy, setCommand/getCommand, setArgs/getArgs, setWorkingDir/getWorkingDir) replacing __call magic for static analysis; clean and correct.
src/Kinds/K8sScale.php Return type on create() widened from K8sResource to static for correct subtype inference; straightforward and correct.
src/Kinds/K8sSecret.php Adds explicit setType/getType methods for the Kubernetes secret type field; clean addition consistent with existing pattern.
src/Traits/RunsClusterOperations.php Widens return types to static on get(), create(), createOrUpdate(), syncWithCluster(), updateStatus(), jsonPatchStatus(), jsonMergePatchStatus(); also changes !instanceof to is_array guard in status patch methods, which is logically equivalent for the declared union types.

Reviews (4): Last reviewed commit: "Fix K8sScale::create() return type to st..." | Re-trigger Greptile

Comment thread src/Traits/RunsClusterOperations.php Outdated
Comment thread .github/workflows/ci.yml
loks0n and others added 7 commits April 1, 2026 16:16
- Restore proper union type hints on jsonPatchStatus/jsonMergePatchStatus
- Use imported class names instead of FQCN
- Fix @throws annotations to use short class names
- Remove minimum-stability: dev from composer.json

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- illuminate/macroable and illuminate/support: ^13.0
- symfony/process: ^8.0
- orchestra/testbench: ^11.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
illuminate/* and testbench are coupled to Laravel 12 on PHP 8.3:
- illuminate/macroable + illuminate/support: ^12.0
- symfony/process: ^7.4 (symfony 8 requires PHP 8.4)
- orchestra/testbench: ^10.9.0

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PHP 8.5 enforces covariant return type compatibility strictly.
K8sScale overrode create() with K8sResource instead of static,
causing a fatal error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@loks0n loks0n merged commit 8ae0072 into main Apr 1, 2026
4 checks passed
@ChiragAgg5k ChiragAgg5k deleted the feat-type-safety-v2 branch April 2, 2026 04:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants