Skip to content

Replace PHPStan ignores with official phpredis stub file#65

Merged
abnegate merged 5 commits intofeat-redis-streamsfrom
copilot/sub-pr-63
Apr 29, 2026
Merged

Replace PHPStan ignores with official phpredis stub file#65
abnegate merged 5 commits intofeat-redis-streamsfrom
copilot/sub-pr-63

Conversation

Copy link
Copy Markdown

Copilot AI commented Jan 19, 2026

PHPStan was reporting undefined method errors for Redis Streams methods (xAdd, xGroup, xReadGroup, etc.) because the default PHP extension stubs lack these definitions. This was being suppressed with ignoreErrors.

Changes

  • Added official phpredis stub file stubs/RedisCluster.stub.php from the phpredis repository with complete type definitions for Redis Streams methods and all RedisCluster methods
  • Configured PHPStan to scan the local stubs directory
  • Removed ignoreErrors section from phpstan.neon that was masking the undefined method warnings
  • Added documentation in stubs/README.md explaining the source and purpose of the stub file
  • Configured Pint to exclude the stubs directory from code style checks

This ensures proper static analysis for Redis Streams operations without suppressing legitimate type checking, and without requiring external dependencies. The stub file is maintained by the phpredis extension authors and is the recommended approach for using phpredis with static analysis tools.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI mentioned this pull request Jan 19, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 19, 2026

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Jan 19, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/JetBrains/phpstorm-stubs/contents/redis/RedisCluster.php
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix feedback on Redis Streams by resolving root cause Replace PHPStan ignores with jetbrains/phpstorm-stubs for Redis Streams Jan 19, 2026
Copilot AI requested a review from abnegate January 19, 2026 12:02
@abnegate
Copy link
Copy Markdown
Member

Added jetbrains/phpstorm-stubs as dev dependency - provides complete type definitions for Redis Streams methods on RedisCluster

@copilot do this without a dependency

Copy link
Copy Markdown
Author

Copilot AI commented Apr 29, 2026

Added jetbrains/phpstorm-stubs as dev dependency - provides complete type definitions for Redis Streams methods on RedisCluster

@copilot do this without a dependency

Created a custom stub file stubs/RedisCluster.stub.php with type definitions for all Redis Streams methods used in the codebase. Removed the jetbrains/phpstorm-stubs dependency and configured PHPStan to scan the local stubs directory instead. (commit e0c6355)

@abnegate
Copy link
Copy Markdown
Member

Added jetbrains/phpstorm-stubs as dev dependency - provides complete type definitions for Redis Streams methods on RedisCluster

@copilot do this without a dependency

Created a custom stub file stubs/RedisCluster.stub.php with type definitions for all Redis Streams methods used in the codebase. Removed the jetbrains/phpstorm-stubs dependency and configured PHPStan to scan the local stubs directory instead. (commit e0c6355)

@copilot Can't they come from the redis extension itself or something without hacks?

Copilot AI changed the title Replace PHPStan ignores with jetbrains/phpstorm-stubs for Redis Streams Replace PHPStan ignores with custom Redis Streams stubs Apr 29, 2026
Copy link
Copy Markdown
Author

Copilot AI commented Apr 29, 2026

Added jetbrains/phpstorm-stubs as dev dependency - provides complete type definitions for Redis Streams methods on RedisCluster

...

Yes! The phpredis extension provides official stub files in their repository for static analysis. I've replaced the custom stub with the official redis_cluster.stub.php from the phpredis project (https://github.com/phpredis/phpredis/blob/develop/redis_cluster.stub.php). This is the recommended approach for using phpredis with PHPStan - the stub files are maintained by the extension authors but aren't distributed with the compiled extension, so we include them locally for static analysis. (commit 55b34a6)

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/phpredis/phpredis/contents
    • Triggering command: /usr/bin/curl curl -s REDACTED (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Replace PHPStan ignores with custom Redis Streams stubs Replace PHPStan ignores with official phpredis stub file Apr 29, 2026
@abnegate
Copy link
Copy Markdown
Member

@copilot Make pint ignore the phpredis stubs

Agent-Logs-Url: https://github.com/utopia-php/queue/sessions/b5046d7d-ddb8-4519-95a0-4d8206fe607e

Co-authored-by: abnegate <5857008+abnegate@users.noreply.github.com>
Copy link
Copy Markdown
Author

Copilot AI commented Apr 29, 2026

@copilot Make pint ignore the phpredis stubs

Added "exclude": ["stubs"] to pint.json to prevent Pint from linting the phpredis stub files. (commit b865335)

@abnegate abnegate marked this pull request as ready for review April 29, 2026 07:30
@abnegate abnegate merged commit cf56a39 into feat-redis-streams Apr 29, 2026
7 checks passed
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR replaces PHPStan ignoreErrors suppressions with a bundled RedisCluster stub file to properly expose Redis Streams method types. Two issues need attention before merging:

  • Wrong PHPStan config key: scanDirectories discovers symbols from regular PHP code but does not override PHPStan's built-in extension stubs — using it for a RedisCluster redeclaration is likely to produce a "class already declared" conflict. The stubFiles key is the correct option for supplementing extension stubs.
  • UNKNOWN placeholder constants: The stub is phpredis's C extension build-system file where UNKNOWN is substituted by the C compiler. As plain PHP, UNKNOWN is an undefined constant; PHPStan will either error on it or infer the wrong type (string instead of int) for all five RedisCluster failover constants.

Confidence Score: 3/5

Two P1 issues may make the PHPStan configuration produce new errors rather than fix existing ones; not safe to merge as-is.

Two P1 findings: wrong PHPStan config key (scanDirectories vs stubFiles) that can cause class-redefinition errors, and five UNKNOWN constant references in the stub that are undefined in PHP. Either issue alone could leave PHPStan in a worse state than before the PR.

phpstan.neon (wrong config key) and stubs/RedisCluster.stub.php (UNKNOWN constants)

Important Files Changed

Filename Overview
phpstan.neon Removes ignoreErrors suppression and adds stubs to scanDirectories, but stubFiles is the correct PHPStan option for stub overrides and avoids class redefinition conflicts.
stubs/RedisCluster.stub.php C extension build-system stub copied from phpredis source; five class constants use UNKNOWN (an undefined PHP constant) as their value, which will cause PHPStan/PHP parser issues.
pint.json Excludes the new stubs directory from Pint code-style checks — appropriate and correct.
stubs/README.md New documentation file describing the stub's source and purpose; accurate and well-written.

Reviews (1): Last reviewed commit: "Configure Pint to ignore stubs directory" | Re-trigger Greptile

Comment thread phpstan.neon
Comment on lines 8 to +10
scanDirectories:
- vendor/swoole

# phpredis stubs don't include Redis Streams methods (xAdd, xGroup, etc.)
# These methods exist at runtime but PHPStan's stubs are incomplete
# See: https://github.com/phpredis/phpredis-stubs/issues
ignoreErrors:
-
message: '#Call to an undefined method RedisCluster::(x(Add|Group|ReadGroup|Ack|Pending|Claim|AutoClaim|Del|Len|Trim|Info|Range|RevRange)|eval)\(\)#'
path: src/Queue/Connection/RedisStreamCluster.php No newline at end of file
- stubs No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 scanDirectories may conflict with PHPStan's built-in RedisCluster stubs

PHPStan ships with its own incomplete RedisCluster stubs. Adding stubs to scanDirectories tells PHPStan to discover class definitions from that directory as regular PHP code — but since RedisCluster is already declared in PHPStan's internal stubs, this can produce a "class already declared" error at analysis time. The correct option for overriding/extending extension stubs is stubFiles, which is specifically designed to merge with existing type definitions rather than redeclare them.

Suggested change
scanDirectories:
- vendor/swoole
# phpredis stubs don't include Redis Streams methods (xAdd, xGroup, etc.)
# These methods exist at runtime but PHPStan's stubs are incomplete
# See: https://github.com/phpredis/phpredis-stubs/issues
ignoreErrors:
-
message: '#Call to an undefined method RedisCluster::(x(Add|Group|ReadGroup|Ack|Pending|Claim|AutoClaim|Del|Len|Trim|Info|Range|RevRange)|eval)\(\)#'
path: src/Queue/Connection/RedisStreamCluster.php
\ No newline at end of file
- stubs
scanDirectories:
- vendor/swoole
stubFiles:
- stubs/RedisCluster.stub.php

Comment on lines +18 to +55
public const OPT_SLAVE_FAILOVER = UNKNOWN;

/**
* Never read from replicas.
*
* @var int
* @cvalue REDIS_FAILOVER_NONE
*
*/
public const FAILOVER_NONE = UNKNOWN;

/**
* Attempt to read from replicas when the primary errors out or is down.
*
* @var int
* @cvalue REDIS_FAILOVER_ERROR
*
*/
public const FAILOVER_ERROR = UNKNOWN;

/**
* Distribute readonly commands at random between the primary and
* replica(s).
*
* @var int
* @cvalue REDIS_FAILOVER_DISTRIBUTE
*
*/
public const FAILOVER_DISTRIBUTE = UNKNOWN;

/**
* Distribute readonly commands between the replicas only.
*
* @var int
* @cvalue REDIS_FAILOVER_DISTRIBUTE_SLAVES
*
*/
public const FAILOVER_DISTRIBUTE_SLAVES = UNKNOWN;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 UNKNOWN is an undefined constant that will trigger PHPStan errors

This file is the phpredis C extension build-system stub (redis_cluster.stub.php), not a PHPStan stub. The UNKNOWN placeholder (also annotated with @cvalue) is replaced by the actual integer value during C compilation — it does not exist as a PHP symbol. All five class constants use it:

public const OPT_SLAVE_FAILOVER         = UNKNOWN;
public const FAILOVER_NONE              = UNKNOWN;
public const FAILOVER_ERROR             = UNKNOWN;
public const FAILOVER_DISTRIBUTE        = UNKNOWN;
public const FAILOVER_DISTRIBUTE_SLAVES = UNKNOWN;

When PHPStan encounters = UNKNOWN, it resolves it as an undefined constant and will either raise an error or silently fall back to the string "UNKNOWN", neither of which is the intended int type. Replace UNKNOWN with a concrete integer sentinel (e.g., 0) so the constants carry a valid type for static analysis purposes.

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