Skip to content

feat: Enhance PHPStan integration with yii2 extensions. #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 2, 2025

Conversation

terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jun 2, 2025

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

Summary by CodeRabbit

  • Refactor

    • Standardized all namespaces and class references from PascalCase to lowercase across the codebase and configuration files.
    • Updated constructor property modifiers, removing the readonly keyword from several class constructors.
    • Improved coding standards by updating code style configurations, including import ordering and single-quote enforcement.
  • Chores

    • Revised dependency and script configurations for improved compatibility and clarity.
    • Updated test and fixture paths to reflect new naming conventions.
    • Extended PHP version testing to include PHP 8.4 in CI workflows.
    • Added project funding information via GitHub Funding configuration.
  • Documentation

    • Adjusted configuration files and comments to align with updated namespaces and paths.

Copy link

coderabbitai bot commented Jun 2, 2025

Walkthrough

This change standardizes all namespaces and configuration references from PascalCase to lowercase across the codebase, updates dependency and script definitions in composer.json, and refines coding standards and test configurations. Several constructors have the readonly modifier removed, and minor adjustments are made to logic and configuration paths.

Changes

Files / Groups Change Summary
composer.json Updated dependency versions, autoload namespaces to lowercase, script commands, and allowed plugins.
ecs.php Added new coding standard fixers, reordered import rules, enforced single quotes, switched to 'strict'.
extension.neon Updated all class references in services to lowercase namespaces.
phpstan.neon Changed yii2.config_path to use fixture directory.
src/ServiceMap.php Namespace changed to lowercase; reordered PHPStan docblock types.
src/reflection/ApplicationPropertiesClassReflectionExtension.php Namespace to lowercase, removed readonly from constructor, adjusted subclass check logic.
src/reflection/ComponentPropertyReflection.php Namespace to lowercase, removed readonly from constructor properties.
src/reflection/RequestMethodsClassReflectionExtension.php Namespace to lowercase.
src/reflection/RequestPropertiesClassReflectionExtension.php Namespace changed to lowercase.
src/reflection/ResponsePropertiesClassReflectionExtension.php Namespace changed to lowercase.
src/reflection/UserPropertiesClassReflectionExtension.php Namespace changed to lowercase.
src/type/ActiveQueryDynamicMethodReturnTypeExtension.php Namespace to lowercase, removed unused variable and exception docblock.
src/type/ActiveQueryObjectType.php Namespace changed to lowercase.
src/type/ActiveRecordDynamicMethodReturnTypeExtension.php Namespace to lowercase, added blank line before exception.
src/type/ActiveRecordDynamicStaticMethodReturnTypeExtension.php Namespace to lowercase, updated subclass checks, removed exception import/docblock.
src/type/ActiveRecordObjectType.php Namespace to lowercase, used nullsafe operator for offset type.
src/type/ContainerDynamicMethodReturnTypeExtension.php Namespace to lowercase, updated imports, removed exception import/docblock.
src/type/HeaderCollectionDynamicMethodReturnTypeExtension.php Namespace changed to lowercase.
stubs/BaseYii.stub Removed blank line after namespace declaration.
tests/ServiceMapTest.php Namespace/use to lowercase, updated fixture paths, added non-assertion expectation in a test.
tests/fixture/yii-config-valid.php Namespace import changed to lowercase.
tests/yii/MyActiveRecord.php, tests/yii/MyController.php Namespace declarations changed to lowercase.
.github/FUNDING.yml Added funding configuration for GitHub Sponsors.
.github/workflows/*.yml Updated workflows: removed ignored paths, changed Yii2 package version to 22.0.x-dev, added PHP 8.4.

Sequence Diagram(s)

sequenceDiagram
    participant Composer
    participant Autoloader
    participant AppCode
    participant Config

    Composer->>Autoloader: Register PSR-4 namespaces (now lowercase)
    Autoloader->>AppCode: Load classes using lowercase namespaces
    AppCode->>Config: Reference services/types using lowercase paths
    Config-->>AppCode: Provide configuration/services
Loading

Possibly related PRs

  • Upgrade to phpstan 2.0 #12: Updates composer.json and PHPStan-related configuration files, aligning with the current PR's focus on dependency and configuration refinement.

Poem

In fields of code where namespaces hop,
The PascalCase bunnies decided to stop.
Now all is lowercase, neat and tight,
Composer scripts run with delight.
With tests and configs all in sync,
This rabbit winks—a change in a blink!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 26f0096 and fc1e52a.

📒 Files selected for processing (8)
  • .github/FUNDING.yml (1 hunks)
  • .github/workflows/build.yml (1 hunks)
  • .github/workflows/compatibility.yml (1 hunks)
  • .github/workflows/dependency-check.yml (1 hunks)
  • .github/workflows/ecs.yml (1 hunks)
  • .github/workflows/static.yml (1 hunks)
  • composer.json (3 hunks)
  • src/reflection/RequestMethodsClassReflectionExtension.php (1 hunks)
✅ Files skipped from review due to trivial changes (4)
  • .github/FUNDING.yml
  • .github/workflows/static.yml
  • .github/workflows/compatibility.yml
  • .github/workflows/dependency-check.yml
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/reflection/RequestMethodsClassReflectionExtension.php
  • composer.json
🔇 Additional comments (3)
.github/workflows/ecs.yml (1)

27-27:

❓ Verification inconclusive

Verify the yiisoft/yii2 version constraint.

The composer require is now pinned to yiisoft/yii2:22.0.x-dev. Double-check that this version actually exists and matches the intended branch (e.g., 2.2.x-dev vs. 22.0.x-dev). An incorrect constraint could cause CI failures or install the wrong code.

Run this locally to list available versions:


🏁 Script executed:

composer show yiisoft/yii2 --all | grep versions

Length of output: 803


Confirm the intended Yii-2 branch alias for the Composer requirement

We ran composer show yiisoft/yii2 --all | grep versions and saw both aliases:

  • 22.0.x-dev
  • 2.2.x-dev

Ensure you really want to pin to 22.0.x-dev. If your goal is to track the 2.2 development branch, update the workflow step in .github/workflows/ecs.yml (line 27) to:

composer require yiisoft/yii2:2.2.x-dev --prefer-dist --no-progress --no-interaction --no-scripts --ansi
.github/workflows/build.yml (2)

29-29:

❓ Verification inconclusive

Ensure PHP 8.4 compatibility.

You’ve added PHP 8.4 to the test matrix. Verify that your code and all dependencies support PHP 8.4 to prevent unexpected CI failures. This may involve updating your composer.json platform config or bumping dependency constraints.

You can test on PHP 8.4 locally via Docker:


🏁 Script executed:

docker run --rm -v "$PWD":/app -w /app php:8.4-cli bash -c "composer install && vendor/bin/phpunit"

Length of output: 210


Docker isn’t available in this sandbox, so let’s verify your PHP version constraints in composer.json to ensure PHP 8.4 is allowed:


🏁 Script executed:

#!/bin/bash
set -e

if [[ ! -f composer.json ]]; then
  echo "composer.json not found!"
  exit 1
fi

echo "→ Extracting PHP requirement from composer.json"
python3 - << 'EOF'
import json, sys
data = json.load(open('composer.json'))
php_req = data.get('require', {}).get('php', 'not specified')
platform_php = data.get('config', {}).get('platform', {}).get('php', 'not specified')
print(f"php require: {php_req}")
print(f"config.platform.php: {platform_php}")
EOF

Length of output: 206


Composer.json Already Allows PHP 8.4—Please Verify Dependencies

Your composer.json specifies:

  • php require: >=8.1
  • no config.platform.php override

This means PHP 8.4 is already permitted by your project’s PHP constraint. However, some dependencies may declare maximum PHP versions that could block 8.4. If you run into errors, you can:

  • Bump any max-version constraints in your dependencies
  • Optionally pin CI to 8.4 in composer.json:
    "config": {
      "platform": { "php": "8.4.0" }
    }

Please run your test suite against PHP 8.4 to confirm everything is compatible:

docker run --rm -v "$PWD":/app -w /app php:8.4-cli \
  bash -c "composer install && vendor/bin/phpunit"

25-25:

✅ Verification successful

Validate consistency of the yiisoft/yii2 version.

The build job also uses yiisoft/yii2:22.0.x-dev. Ensure this aligns with the project’s requirements and matches the version used elsewhere in your workflows.

Check available versions with:


🏁 Script executed:

composer show yiisoft/yii2 --all | grep versions

Length of output: 803


🏁 Script executed:

#!/bin/bash
# Check version constraint in composer.json
rg "yiisoft/yii2" -n composer.json

# Search for any other references in GitHub workflows
rg "yiisoft/yii2" -n .github/workflows

Length of output: 902


Versions Aligned with composer.json: No changes required

Confirmed that composer.json allows both ^22 and ^2.0.52. All dev‐focused workflows (static.yml, ecs.yml, dependency-check.yml, build.yml) consistently require 22.0.x-dev (matching the ^22 constraint), and the compatibility job intentionally tests against the stable ^2.0.52. No inconsistencies detected.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.

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: 5

♻️ Duplicate comments (1)
src/type/ActiveRecordDynamicStaticMethodReturnTypeExtension.php (1)

71-72: 🛠️ Refactor suggestion

Second occurrence of the undefined method

See previous comment – replace with isSubclassOf(ActiveQuery::class) or the reflection-aware overload.

🧹 Nitpick comments (1)
composer.json (1)

45-47: Running ECS with --fix inside CI may introduce unstaged changes

Invoking ECS with --fix mutates source files. If this script is meant for CI, prefer --no-interaction/--dry-run (or separate check vs fix scripts) to fail the build instead of silently modifying code.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1aecdf2 and 26f0096.

📒 Files selected for processing (23)
  • composer.json (3 hunks)
  • ecs.php (3 hunks)
  • extension.neon (1 hunks)
  • phpstan.neon (1 hunks)
  • src/ServiceMap.php (2 hunks)
  • src/reflection/ApplicationPropertiesClassReflectionExtension.php (3 hunks)
  • src/reflection/ComponentPropertyReflection.php (2 hunks)
  • src/reflection/RequestMethodsClassReflectionExtension.php (2 hunks)
  • src/reflection/RequestPropertiesClassReflectionExtension.php (1 hunks)
  • src/reflection/ResponsePropertiesClassReflectionExtension.php (1 hunks)
  • src/reflection/UserPropertiesClassReflectionExtension.php (1 hunks)
  • src/type/ActiveQueryDynamicMethodReturnTypeExtension.php (1 hunks)
  • src/type/ActiveQueryObjectType.php (1 hunks)
  • src/type/ActiveRecordDynamicMethodReturnTypeExtension.php (2 hunks)
  • src/type/ActiveRecordDynamicStaticMethodReturnTypeExtension.php (3 hunks)
  • src/type/ActiveRecordObjectType.php (2 hunks)
  • src/type/ContainerDynamicMethodReturnTypeExtension.php (1 hunks)
  • src/type/HeaderCollectionDynamicMethodReturnTypeExtension.php (1 hunks)
  • stubs/BaseYii.stub (0 hunks)
  • tests/ServiceMapTest.php (7 hunks)
  • tests/fixture/yii-config-valid.php (1 hunks)
  • tests/yii/MyActiveRecord.php (1 hunks)
  • tests/yii/MyController.php (1 hunks)
💤 Files with no reviewable changes (1)
  • stubs/BaseYii.stub
🧰 Additional context used
🧬 Code Graph Analysis (3)
tests/fixture/yii-config-valid.php (1)
tests/yii/MyActiveRecord.php (1)
  • MyActiveRecord (12-37)
tests/ServiceMapTest.php (2)
src/ServiceMap.php (1)
  • ServiceMap (26-141)
tests/yii/MyActiveRecord.php (1)
  • MyActiveRecord (12-37)
src/type/ContainerDynamicMethodReturnTypeExtension.php (1)
src/ServiceMap.php (1)
  • ServiceMap (26-141)
🔇 Additional comments (30)
src/type/ActiveQueryObjectType.php (1)

5-5:

✅ Verification successful

LGTM! Verify consistent namespace updates across the codebase.

The namespace change from PascalCase to lowercase aligns with the PR objective to standardize naming conventions.

Please run the following script to ensure all namespace references have been updated consistently:


🏁 Script executed:

#!/bin/bash
# Description: Verify all references to the old PascalCase namespace have been updated

# Search for any remaining PascalCase namespace references
echo "Checking for old PascalCase namespace references..."
rg -i "Yii2\\\\Extensions\\\\PHPStan" --type php

# Search for new lowercase namespace usage
echo "Verifying new lowercase namespace usage..."
rg "yii2\\\\extensions\\\\phpstan" --type php

# Check composer.json autoload configuration
echo "Checking composer.json autoload configuration..."
cat composer.json | jq '.autoload'

Length of output: 4448


Namespace Standardization Verified

All references to the old Yii2\Extensions\PHPStan namespace have been checked with a case-sensitive search—no matches remain. The PSR-4 autoload mapping in composer.json correctly uses the new lowercase prefix.

  • No Yii2\Extensions\PHPStan (PascalCase) occurrences in PHP files
  • composer.json autoloads "yii2\\extensions\\phpstan\\": "src" as expected

No further changes required.

src/type/HeaderCollectionDynamicMethodReturnTypeExtension.php (1)

5-5: LGTM! Namespace standardization is consistent.

The namespace change follows the same lowercase convention being applied across the codebase, maintaining consistency with the broader refactoring effort.

src/type/ActiveRecordDynamicMethodReturnTypeExtension.php (2)

5-5: LGTM! Consistent namespace standardization.

The namespace change aligns with the project-wide standardization to lowercase naming conventions.


54-54: LGTM! Improved code readability.

The added blank line improves readability by providing visual separation before the conditional logic that handles the exception case.

src/type/ActiveRecordObjectType.php (2)

5-5: LGTM! Consistent namespace standardization.

The namespace change follows the same lowercase convention being applied across all files in this PR.


35-36: Excellent bug fix with the nullsafe operator!

The addition of the nullsafe operator (?->) prevents a potential null pointer exception since the $offsetType parameter is nullable (?Type $offsetType). This is a meaningful improvement that enhances the robustness of the code.

The added blank line also improves code readability by providing visual separation in the logic flow.

src/type/ActiveQueryDynamicMethodReturnTypeExtension.php (2)

48-50: AI summary discrepancy: @throws annotation still present
The AI-generated summary mentioned that the @throws ShouldNotHappenException PHPDoc was removed, but it remains in lines 48–50. Please confirm whether this annotation should be dropped or kept.

Likely an incorrect or invalid review comment.


5-5:

✅ Verification successful

Lowercase namespace normalization
The namespace has been converted from Yii2\Extensions\PHPStan\Type to yii2\extensions\phpstan\type, aligning with the project-wide standard.
Please verify that your composer.json PSR-4 autoload mapping has been updated to reflect this change.


🏁 Script executed:

#!/bin/bash
# Verify PSR-4 autoload mapping for phpstan namespaces
rg -n '"yii2\\\\extensions\\\\phpstan"' composer.json

Length of output: 55


Let's list out the PSR-4 mappings and explicitly search for the updated namespace entry in composer.json to confirm it’s present:


🏁 Script executed:

#!/bin/bash
# Show all PSR-4 mappings
jq '.autoload["psr-4"]' composer.json

# Check for the exact phpstan namespace key (with trailing backslash)
rg -n '"yii2\\\\extensions\\\\phpstan\\\\":' composer.json

Length of output: 195


PSR-4 autoload mapping verified
Confirmed that composer.json includes the required entry under autoload.psr-4:

"yii2\\extensions\\phpstan\\": "src"

No further changes needed.

phpstan.neon (1)

20-22: Updated fixture path
The yii2.config_path was updated to point to tests/fixture/yii-config-valid.php, matching the renamed test fixtures directory. This aligns with the changes in tests/ServiceMapTest.php and other test files.

tests/yii/MyActiveRecord.php (1)

5-5:

✅ Verification successful

Normalized test namespace to lowercase
The namespace has been converted to yii2\extensions\phpstan\tests\yii. Ensure that the PSR-4 autoload in composer.json for dev dependencies covers this updated namespace.


🏁 Script executed:

#!/bin/bash
# Verify PSR-4 mapping for test namespace
rg -n '"yii2\\\\extensions\\\\phpstan\\\\tests\\\\yii"' composer.json

Length of output: 71


🏁 Script executed:

#!/bin/bash
# Inspect autoload-dev PSR-4 mappings in composer.json
rg -n '"autoload-dev"' composer.json -A5
rg -n '"psr-4"' composer.json -A5

Length of output: 502


PSR-4 autoload-dev mapping confirmed

The composer.json already includes the following PSR-4 entry under autoload-dev, which covers yii2\extensions\phpstan\tests\ (and thus the yii2\extensions\phpstan\tests\yii namespace):

"autoload-dev": {
    "psr-4": {
        "yii2\\extensions\\phpstan\\tests\\": "tests"
    }
}

No further changes are required.

tests/yii/MyController.php (1)

5-5:

✅ Verification successful

Normalized test namespace to lowercase
The namespace has been updated to yii2\extensions\phpstan\tests\yii. Confirm that your dev autoload configuration in composer.json includes this path.


🏁 Script executed:

#!/bin/bash
# Verify PSR-4 mapping for test namespace
rg -n '"yii2\\\\extensions\\\\phpstan\\\\tests\\\\yii"' composer.json

Length of output: 71


🏁 Script executed:

#!/bin/bash
# List PSR-4 autoload-dev mappings to verify test namespace mapping
jq -r '
  .["autoload-dev"]["psr-4"]?
  | to_entries[]
  | "\(.key) => \(.value)"
' composer.json || echo "No PSR-4 autoload-dev mappings found in composer.json"

Length of output: 139


PSR-4 autoload-dev mapping validated
The yii2\extensions\phpstan\tests\yii namespace is correctly mapped to the tests/ directory in composer.json. No further changes needed.

src/reflection/RequestPropertiesClassReflectionExtension.php (1)

5-5:

✅ Verification successful

Lowercase namespace normalization
Changed namespace from Yii2\Extensions\PHPStan\Reflection to yii2\extensions\phpstan\reflection. This matches the refactoring in other source and config files.
Please verify that the main composer.json autoload PSR-4 section has been updated accordingly.


🏁 Script executed:

#!/bin/bash
# Verify PSR-4 autoload mapping for reflection namespace
rg -n '"yii2\\\\extensions\\\\phpstan\\\\reflection"' composer.json

Length of output: 69


🏁 Script executed:

#!/bin/bash
# List PSR-4 autoload mappings in composer.json to verify namespace casing
if command -v jq >/dev/null; then
  jq '.autoload["psr-4"]' composer.json
else
  # Fallback to grep if jq is unavailable
  grep -R -n '"psr-4"' -n composer.json -A10
fi

Length of output: 98


PSR-4 Autoload Namespace Verified
The composer.json PSR-4 section already maps "yii2\\extensions\\phpstan\\" to "src", which covers the new lowercase yii2\extensions\phpstan\reflection namespace. No further changes are required.

src/reflection/ResponsePropertiesClassReflectionExtension.php (1)

5-5: Consistent namespace standardization.

The namespace change follows the same pattern as other files in this refactoring. Ensure this is coordinated with updates to configuration files and external references.

tests/fixture/yii-config-valid.php (1)

5-5: Import statement correctly updated.

The import statement has been properly updated to use the new lowercase namespace convention, maintaining consistency with the overall refactoring.

src/type/ContainerDynamicMethodReturnTypeExtension.php (2)

5-5: Namespace standardization applied consistently.

The namespace has been correctly converted to lowercase following the established pattern.


16-16: ServiceMap import updated correctly.

The import statement for ServiceMap has been properly updated to use the new lowercase namespace convention.

src/reflection/RequestMethodsClassReflectionExtension.php (1)

5-5: Namespace change consistent with refactoring pattern.

The namespace has been correctly updated to follow the lowercase convention.

src/reflection/ComponentPropertyReflection.php (2)

5-5: LGTM: Namespace standardization to lowercase.

This change aligns with the overall refactoring effort to standardize namespaces from PascalCase to lowercase throughout the codebase.


14-14:

❓ Verification inconclusive

Verify the impact of removing readonly modifiers.

The readonly property modifier has been removed from both $fallbackProperty and $type constructor parameters. This changes these properties from immutable to mutable, which could affect the intended design and thread safety of this class.

Please confirm that this change is intentional and that the class doesn't rely on the immutability guarantees provided by readonly properties.


🏁 Script executed:

#!/bin/bash
# Description: Check if readonly modifier was removed consistently across other reflection classes
# Expected: Find other reflection classes that may have had similar constructor changes

# Search for other reflection classes and their constructors
ast-grep --pattern $'class $_ implements $_Reflection {
  $$$
  public function __construct($$$) {
    $$$
  }
  $$$
}'

# Also check for any remaining readonly usage in reflection classes
rg -A 3 -B 3 "readonly" --include="*Reflection*.php"

Length of output: 615


🏁 Script executed:

#!/bin/bash
# Re-run search for any remaining readonly modifiers in Reflection classes
rg -A 3 -B 3 readonly -g '*Reflection*.php'

Length of output: 2234


Verify consistent immutability across reflection classes

It looks like ComponentPropertyReflection’s constructor parameters were changed from immutable to mutable by dropping readonly, whereas other reflection extensions still use private readonly. This inconsistency could introduce unintended mutability.

Please confirm that removing readonly here is intentional and that this class’s design does not rely on immutability guarantees.

• src/reflection/UserPropertiesClassReflectionExtension.php (constructor uses private readonly)
• src/reflection/ResponsePropertiesClassReflectionExtension.php
• src/reflection/RequestPropertiesClassReflectionExtension.php

tests/ServiceMapTest.php (3)

5-5: LGTM: Namespace standardization to lowercase.

The namespace and use statement changes consistently convert from PascalCase to lowercase, aligning with the codebase-wide refactoring.

Also applies to: 15-16


135-135: LGTM: Good testing practice.

Adding $this->expectNotToPerformAssertions() is a good practice for tests that verify behavior through constructor execution without explicit assertions, making the test intent clear.


36-38:

✅ Verification successful

Verify that the fixture directory structure exists.

All test fixture paths have been updated from 'assets' to 'fixture'. Please ensure that the fixture directory and all referenced configuration files exist at the new location.

Also applies to: 49-50, 52-52, 63-64, 66-66, 77-78, 80-80, 88-88, 90-90, 137-137


🏁 Script executed:

#!/bin/bash
# Description: Verify that all fixture files referenced in tests exist
# Expected: All fixture files should be present in the tests/fixture directory

echo "Checking if tests/fixture directory exists..."
ls -la tests/fixture/ || echo "Directory tests/fixture/ does not exist"

echo -e "\nChecking specific fixture files referenced in tests..."
test_files=(
    "tests/fixture/yii-config-invalid.php"
    "tests/fixture/yii-config-invalid-unsupported-type.php" 
    "tests/fixture/yii-config-invalid-unsupported-array.php"
    "tests/fixture/yii-config-invalid-component.php"
    "tests/fixture/yii-config-valid.php"
    "tests/fixture/yii-config-no-singletons.php"
)

for file in "${test_files[@]}"; do
    if [ -f "$file" ]; then
        echo "$file exists"
    else
        echo "$file is missing"
    fi
done

Length of output: 2391


All referenced test fixtures are present

Verified that the tests/fixture/ directory exists and contains all files referenced in ServiceMapTest.php. No further changes are required.

extension.neon (1)

14-44: LGTM: PHPStan configuration updated to match namespace changes.

All service class references have been consistently updated from PascalCase to lowercase namespaces, ensuring the PHPStan configuration aligns with the codebase refactoring. The configuration structure and service definitions remain intact.

src/ServiceMap.php (2)

5-5: LGTM: Namespace standardization to lowercase.

This change aligns with the overall refactoring effort to standardize namespaces from PascalCase to lowercase throughout the codebase.


106-106: LGTM: PHPStan type annotation reordering.

The type annotation has been reordered from string|Closure|array<mixed>|int to array<mixed>|string|Closure|int. This change doesn't affect runtime behavior and may improve consistency or readability.

ecs.php (1)

47-55: Potential rule collision / duplicate inclusion

SingleQuoteFixer::class is registered via ->withRules() while perCS20: true already pulls in the PhpCsFixer set that contains SingleQuoteFixer with default config. This can lead to duplicate rule definitions or unexpected config precedence.
Double-check the executed rule set and, if unnecessary, remove the explicit entry.

src/reflection/ApplicationPropertiesClassReflectionExtension.php (4)

5-5: LGTM! Namespace standardization improves consistency.

The namespace casing standardization from PascalCase to lowercase aligns with the broader project-wide effort mentioned in the summary. This improves consistency across the codebase.

Also applies to: 17-17


29-34: Excellent improvement using PHPStan's reflection API.

The change from native PHP is_subclass_of to PHPStan's isSubclassOfClass() method is a significant improvement. Using PHPStan's reflection system provides more accurate analysis capabilities and better integration with the static analysis context.


57-60: LGTM! Improved code formatting.

The multi-line formatting with trailing commas improves readability and follows modern PHP coding standards. This makes future diffs cleaner when adding or modifying parameters.


22-24:

✅ Verification successful

Verify the removal of readonly modifiers.

The readonly modifiers have been removed from constructor properties. This allows these properties to be modified after construction, which could be intentional but might also introduce unintended mutability.

Please confirm that removing the readonly modifiers is intentional and that these properties don't need to remain immutable after construction.


🏁 Script executed:

#!/bin/bash
# Description: Check for any assignments to these properties outside the constructor
# Expected: No assignments found outside constructor, or intentional mutations

# Search for assignments to these properties
rg -A 3 -B 3 '\$this->annotationsProperties\s*=' --type php
rg -A 3 -B 3 '\$this->reflectionProvider\s*=' --type php  
rg -A 3 -B 3 '\$this->serviceMap\s*=' --type php

Length of output: 811


No unintended mutability detected after removing readonly modifiers

I checked the entire codebase for assignments to these three properties and found that all of them are only ever set in their constructors—there are no external mutations. Removing readonly here does not introduce unintended mutability.

@terabytesoftw terabytesoftw requested a review from Copilot June 2, 2025 15:09
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 improves PHPStan integration by standardizing namespaces, adjusting constructor modifiers, refining code style rules, and updating CI/workflow configurations.

  • Standardize all namespaces and class references to lowercase for PSR-4 compliance
  • Remove readonly modifiers from constructors for broader compatibility
  • Enhance coding standards (import order, single-quote enforcement) and update CI scripts and workflows

Reviewed Changes

Copilot reviewed 34 out of 34 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/type/ActiveRecordDynamicMethodReturnTypeExtension.php Namespace casing update
src/type/ActiveQueryObjectType.php Namespace casing update
src/type/ActiveQueryDynamicMethodReturnTypeExtension.php Refactor method return type logic
src/reflection/UserPropertiesClassReflectionExtension.php Namespace casing update
src/reflection/ResponsePropertiesClassReflectionExtension.php Namespace casing update
src/reflection/RequestPropertiesClassReflectionExtension.php Namespace casing update
src/reflection/RequestMethodsClassReflectionExtension.php Namespace casing update
src/reflection/ComponentPropertyReflection.php Removed readonly in constructor
src/reflection/ApplicationPropertiesClassReflectionExtension.php Namespace update & subclass-of check refactor
src/ServiceMap.php Namespace update & PHPDoc union type normalization
phpstan.neon Updated config_path to fixtures folder
extension.neon Updated service class references to lowercase namespaces
ecs.php Added import/order & single-quote style rules
composer.json Extended constraints and updated scripts
.github/workflows/static.yml Aligned Yii2 dev version requirement
.github/workflows/ecs.yml Aligned Yii2 dev version requirement
.github/workflows/dependency-check.yml Aligned Yii2 dev version requirement
.github/workflows/compatibility.yml Bumped Yii2 composer requirement
.github/workflows/build.yml Bumped PHP and Yii2 versions
.github/FUNDING.yml Added GitHub funding information
Comments suppressed due to low confidence (2)

src/type/ActiveQueryDynamicMethodReturnTypeExtension.php:73

  • Removing the default initialization of $boolValue can lead to an undefined variable when neither branch runs. Consider reintroducing a default assignment or adding an else clause to ensure $boolValue is always defined.
if ($argType->isTrue()->yes()) {

ecs.php:31

  • Configuring VisibilityRequiredFixer with an empty elements array disables the rule. Verify whether you intend to enforce specific element visibilities or remove the rule if unused.
'elements' => [],

@terabytesoftw terabytesoftw merged commit 34446d4 into main Jun 2, 2025
42 of 43 checks passed
@terabytesoftw terabytesoftw deleted the fix-mini-1 branch June 2, 2025 15:13
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.

1 participant