Skip to content

Conversation

terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jun 15, 2025

Q A
Is bugfix? ✔️
New feature?
Breaks BC?

Summary by CodeRabbit

  • Bug Fixes

    • Updated changelog to document relocation of user property reflection extension and related tests.
  • Documentation

    • Improved and clarified PHPDoc comments for the user property reflection extension, including consistent references and more precise descriptions.
  • Tests

    • Added comprehensive tests to verify type inference for Yii User component properties and methods.
    • Enhanced test coverage by introducing new test classes and updating test stubs for the User component.

Copy link

coderabbitai bot commented Jun 15, 2025

Warning

Rate limit exceeded

@terabytesoftw has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between b1d33c7 and 96d38b2.

📒 Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • composer-require-checker.json (1 hunks)
  • src/property/UserPropertiesClassReflectionExtension.php (6 hunks)
  • tests/fixture/data/property/UserPropertiesClassReflectionType.php (1 hunks)

"""

Walkthrough

The changes reorganize the UserPropertiesClassReflectionExtension by moving it to a new namespace and directory, updating its documentation, and adjusting its service registration in the configuration file. Comprehensive tests for user property reflection are added, and the test stub for the User class is updated to fully implement the IdentityInterface.

Changes

File(s) Change Summary
CHANGELOG.md Added entry documenting the move of UserPropertiesClassReflectionExtension and new tests.
extension.neon Reordered the service registration for UserPropertiesClassReflectionExtension under the new namespace.
src/property/UserPropertiesClassReflectionExtension.php Moved class to property namespace, updated imports and PHPDoc comments for clarity; no logic changes.
tests/fixture/data/property/UserPropertiesClassReflectionType.php Added a new test class with multiple methods asserting PHPStan's type inference for Yii User component.
tests/property/UserPropertiesClassReflectionExtensionTest.php Added test class to run type inference assertions using PHPStan's testing framework.
tests/stub/User.php Updated User stub: removed properties, made class final, implemented IdentityInterface methods.

Sequence Diagram(s)

sequenceDiagram
    participant TestCase as UserPropertiesClassReflectionExtensionTest
    participant PHPStan as PHPStan Type Inference Engine
    participant Fixture as UserPropertiesClassReflectionType
    participant User as User (stub)

    TestCase->>PHPStan: Run type inference assertions from Fixture
    PHPStan->>User: Analyze properties/methods (e.g., identity, id, getAuthKey)
    User-->>PHPStan: Return types per IdentityInterface implementation
    PHPStan-->>TestCase: Report inferred types for assertions
Loading

Possibly related PRs

  • yii2-extensions/phpstan#34: Directly modifies UserPropertiesClassReflectionExtension to enhance identity class resolution and type inference.
  • yii2-extensions/phpstan#41: Refactors PHPDoc comments in UserPropertiesClassReflectionExtension for clarity and consistency.
  • yii2-extensions/phpstan#42: Moves and tests ApplicationPropertiesClassReflectionExtension, similar in structure but for a different Yii component.

Poem

A bunny hopped through PHP's land,
Moving code with gentle hand.
User properties now in place,
With tests to keep them in the race!
Reflection shines, assertions true—
PHPStan sees what rabbits do.
🐇✨
"""

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@terabytesoftw terabytesoftw added the bug Something isn't working label Jun 15, 2025
Copy link

codecov bot commented Jun 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (d3acfa2) to head (96d38b2).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #44   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity        62        62           
===========================================
  Files              1         1           
  Lines            107       107           
===========================================
  Hits             107       107           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@terabytesoftw terabytesoftw requested a review from Copilot June 15, 2025 14:17
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🔭 Outside diff range comments (2)
src/property/UserPropertiesClassReflectionExtension.php (2)

142-145: ⚠️ Potential issue

isSubclassOfClass() is not part of PHPStan’s API — will trigger a fatal error.

ClassReflection exposes isSubclassOf(string $className): bool, not isSubclassOfClass(). Passing a ClassReflection instance is also wrong.

-            $classReflection->isSubclassOfClass($this->reflectionProvider->getClass(User::class)) === false
+            $classReflection->isSubclassOf(User::class) === false

Without this fix the extension crashes during analysis.


104-110: 🛠️ Refactor suggestion

isGuest should be BooleanType, not the constant true.

$user->isGuest can be either true or false. Using ConstantBooleanType(true) falsely narrows the type and hides bugs where the value is false.

-                    new ConstantBooleanType(true),
+                    new \PHPStan\Type	BooleanType(),

Also, in hasProperty() the existence of isGuest (and id) is tied to identityClass which is unnecessary; those properties always exist.

🧹 Nitpick comments (2)
CHANGELOG.md (1)

14-14: Capitalization inconsistent with existing entries.

All prior bullets start with Bug, Enh, etc. Line 14 uses lowercase bug, breaking the pattern and changelog automation that might rely on the prefix.

- - bug #44: Move `UserPropertiesClassReflectionExtension` to `property` directory and add testing (@terabytesoftw)
+ - Bug #44: Move `UserPropertiesClassReflectionExtension` to `property` directory and add testing (@terabytesoftw)
tests/fixture/data/property/UserPropertiesClassReflectionType.php (1)

46-54: Static call via a potentially-null object risks fatal error.

Yii::$app->user->identity may be null; invoking ::findIdentity*() on it will crash at runtime, even though the snippet is used only for static analysis.
Consider asserting on the class directly or guarding with null-safe operator to reflect real-world usage:

assertType('yii\web\IdentityInterface|null', Yii::$app->user->identity?::findIdentityByAccessToken('123abc'));
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d3acfa2 and 7084d3f.

📒 Files selected for processing (6)
  • CHANGELOG.md (1 hunks)
  • extension.neon (1 hunks)
  • src/property/UserPropertiesClassReflectionExtension.php (5 hunks)
  • tests/fixture/data/property/UserPropertiesClassReflectionType.php (1 hunks)
  • tests/property/UserPropertiesClassReflectionExtensionTest.php (1 hunks)
  • tests/stub/User.php (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/property/UserPropertiesClassReflectionExtension.php (2)
src/reflection/ComponentPropertyReflection.php (1)
  • ComponentPropertyReflection (37-271)
src/ServiceMap.php (1)
  • ServiceMap (60-537)
tests/fixture/data/property/UserPropertiesClassReflectionType.php (1)
tests/stub/User.php (5)
  • validateAuthKey (48-51)
  • findIdentityByAccessToken (33-36)
  • findIdentity (28-31)
  • getAuthKey (43-46)
  • getId (38-41)
🔇 Additional comments (1)
extension.neon (1)

29-31: Confirm removal of the old reflection\UserPropertiesClassReflectionExtension service.

The service has been re-registered under property\…. Please double-check that the old reflection\UserPropertiesClassReflectionExtension class file and its service entry were deleted to avoid PHPStan loading the same logic twice.

Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the UserPropertiesClassReflectionExtension by relocating it to a dedicated property directory, updating its namespace and configuration, and adds comprehensive tests and a stub user class for PHPStan type inference.

  • Moved UserPropertiesClassReflectionExtension from reflection to property directory and updated namespaces.
  • Updated extension.neon to register the relocated extension and removed the old registration.
  • Added a test stub (tests/stub/User.php), PHPStan property tests, fixtures, and updated the changelog.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/stub/User.php Implemented IdentityInterface methods in the user stub.
tests/property/UserPropertiesClassReflectionExtensionTest.php Added a test class for property reflection extension.
tests/fixture/data/property/UserPropertiesClassReflectionType.php Created fixture tests to assert inferred property and method types.
src/property/UserPropertiesClassReflectionExtension.php Updated namespace and documentation for the property extension.
extension.neon Registered the moved property extension and removed the old one.
CHANGELOG.md Documented the move of the extension and added the testing notes.
Comments suppressed due to low confidence (1)

CHANGELOG.md:14

  • The changelog entry uses a lowercase 'bug' and lacks a version header; please capitalize 'Bug #44' to match the existing pattern and add a new version section (e.g., '## 0.2.4') above this entry.
- bug #44: Move `UserPropertiesClassReflectionExtension` to `property` directory and add testing (@terabytesoftw)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant