Skip to content

[Chore]: Add PHPStan rule to enforce ClientIp resolver usage - #147

Merged
danharrin merged 2 commits into
mainfrom
copilot/create-phpstan-rule-for-clientip
Aug 24, 2026
Merged

[Chore]: Add PHPStan rule to enforce ClientIp resolver usage#147
danharrin merged 2 commits into
mainfrom
copilot/create-phpstan-rule-for-clientip

Conversation

Copilot AI commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Ticket(s) or GitHub Issue

  • N/A

Technical Description

Direct Request IP accessors can return incorrect client addresses in Cloudflare + ALB deployments. This change adds a package PHPStan rule so consuming apps are guided to use ClientIp::resolve() consistently.

  • Rule implementation

    • Added UseClientIpResolverRule under src/Rules/UseClientIpResolver/.
    • Reports Common.useClientIpResolver for Illuminate\Http\Request calls to:
      • ip()
      • ips()
      • getClientIp()
      • getClientIps()
    • Excludes ClientIp class internals to avoid flagging its fallback path.
  • Package registration

    • Registered the rule in phpstan-extension.neon so consumers including this extension receive the check.
  • Rule coverage

    • Added dedicated PHPStan config, fixtures, and test file under tests/PHPStan/ for:
      • violating usages (ip(), getClientIp())
      • compliant usage (ClientIp::resolve($request))
      • inline ignore behavior (@phpstan-ignore Common.useClientIpResolver)
use CanyonGBS\Common\Support\ClientIp;
use Illuminate\Http\Request;

function resolveIp(Request $request): ?string
{
    return ClientIp::resolve($request);
}

Please apply the Change Type | New Feature label.

Any deployment steps required?

No

Are any Feature Flags and/or Data Migrations that can eventually be removed Added?

No


Before contributing and submitting this PR, make sure you have Read, agree, and are compliant with the contributing guidelines.

Co-authored-by: Orrison <6799341+Orrison@users.noreply.github.com>
@Orrison Orrison changed the title Add PHPStan rule to enforce ClientIp resolver usage [Chore]: Add PHPStan rule to enforce ClientIp resolver usage Aug 23, 2026

@Orrison Orrison left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot respond to all this PR feedback

Comment thread src/Rules/UseClientIpResolver/UseClientIpResolverRule.php Outdated
Comment thread src/Rules/UseClientIpResolver/UseClientIpResolverRule.php
Co-authored-by: Orrison <6799341+Orrison@users.noreply.github.com>
Copilot AI requested a review from Orrison August 23, 2026 16:47
@Orrison
Orrison marked this pull request as ready for review August 23, 2026 16:59
@Orrison
Orrison requested a review from a team as a code owner August 23, 2026 16:59
@Orrison
Orrison requested a review from danharrin August 23, 2026 16:59
@danharrin
danharrin merged commit 323c6f9 into main Aug 24, 2026
8 checks passed
@danharrin
danharrin deleted the copilot/create-phpstan-rule-for-clientip branch August 24, 2026 08:46
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.

3 participants