Skip to content

refactor: Improve ServiceMap configuration for application types (Base, Console, Web) #45

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 25 commits into from
Jun 16, 2025

Conversation

terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jun 16, 2025

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

Summary by CodeRabbit

  • New Features

    • Added support for specifying and analyzing different Yii application types (Web, Console, Base) in static analysis.
    • Introduced automatic stub file resolution for accurate property and method reflection based on application type.
    • Added new PHPStan configuration and test files for console application analysis.
  • Bug Fixes

    • Improved ServiceMap configuration handling for application type detection and validation.
  • Refactor

    • Removed legacy PHPStan extensions for request and response property/method reflection in favor of stub-based resolution.
    • Updated test and configuration file paths for consistency and clarity.
  • Tests

    • Added and updated comprehensive test suites for property and type reflection across web and console application contexts.
    • Enhanced test coverage for application type resolution and stub file integration.
  • Chores

    • Updated documentation and changelog to reflect new features and fixes.
    • Adjusted workflow and configuration files for improved CI and static analysis support.

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

coderabbitai bot commented Jun 16, 2025

Walkthrough

This update introduces application type awareness for PHPStan analysis in Yii2 projects. It removes specialized PHPStan reflection extensions for request and response classes, replacing them with a stub files extension that selects appropriate stubs based on the configured application type. The configuration and tests are updated to support and validate this new approach, including new stub files and test fixtures.

Changes

File(s)/Group Change Summary
.github/workflows/static.yml, .github/workflows/build.yml Refined job parameters and concurrency group naming in GitHub Actions workflows; added a new PHPStan job for console analysis.
CHANGELOG.md Added changelog entry for application type configuration bug fix.
composer-require-checker.json Whitelisted the new PHPStan StubFilesExtension symbol.
extension.neon Removed request/response reflection extensions, added StubFilesExtension service.
phpstan-console.neon, phpstan.neon Added/updated PHPStan configs for console/web, including strict rules and new analysis paths.
src/ServiceMap.php Added application type support and validation; refactored error handling and comments.
src/StubFilesExtension.php Introduced class to resolve stub files based on application type for PHPStan.
src/property/ApplicationPropertiesClassReflectionExtension.php Refactored to use configured application type for property reflection; updated logic and constants.
src/property/BehaviorPropertiesClassReflectionExtension.php, src/type/ActiveQueryDynamicMethodReturnTypeExtension.php, src/type/ContainerDynamicMethodReturnTypeExtension.php Updated PHPDoc comments for clarity and consistency.
src/reflection/RequestMethodsClassReflectionExtension.php, src/reflection/RequestPropertiesClassReflectionExtension.php, src/reflection/ResponsePropertiesClassReflectionExtension.php Deleted: removed specialized reflection extensions for request and response classes.
stub/BaseYii.stub, stub/BaseYiiConsole.stub, stub/BaseYiiWeb.stub Added new stub files for base, console, and web application types.
tests/ServiceMapBehaviorTest.php, tests/ServiceMapComponentTest.php, tests/ServiceMapServiceTest.php Updated config file paths and assertion messages for new structure.
tests/ServiceMapTest.php, tests/StubFilesExtensionTest.php Added new test classes for application type resolution and stub file extension.
tests/bootstrap.php Removed Composer autoloader include.
tests/config/config.php, tests/config/phpstan-unsupported-is-not-array.php, tests/config/phpstan-unsupported-type-array-invalid.php, tests/console/config/config.php Updated/added config files for application type and component setup.
tests/console/data/property/ApplicationPropertiesClassReflectionType.php, tests/web/data/property/ApplicationPropertiesClassReflectionType.php Added/updated property type assertion test fixtures for console and web application contexts.
tests/console/extension-console-test.neon, tests/extension-test.neon Added/updated test configuration files.
tests/extension-tests.neon, tests/fixture/data/property/ApplicationConsolePropertiesClassReflectionType.php, tests/fixture/data/property/ApplicationCustomPropertiesClassReflectionType.php, tests/fixture/data/property/ApplicationWebPropertiesClassReflectionType.php Deleted obsolete or replaced test fixtures and configs.
tests/console/property/ApplicationPropertiesClassReflectionExtensionTest.php Refocused test to console application context, updated data providers and config usage.
tests/data/method/BehaviorMethodsClassReflectionType.php, tests/data/property/BehaviorPropertiesClassReflectionType.php, tests/data/property/UserPropertiesClassReflectionType.php, tests/data/type/ActiveQueryDynamicMethodReturnType.php, tests/data/type/ActiveRecordDynamicMethodReturnType.php, tests/data/type/ActiveRecordDynamicStaticMethodReturnType.php, tests/data/type/ContainerDynamicMethodReturnType.php Updated namespaces and refactored assertions for conciseness.
tests/method/BehaviorMethodsClassReflectionExtensionTest.php, tests/property/BehaviorPropertiesClassReflectionExtensionTest.php, tests/property/UserPropertiesClassReflectionExtensionTest.php, tests/type/ActiveQueryDynamicReturnTypeExtensionTest.php, tests/type/ActiveRecordDynamicMethodReturnTypeExtensionTest.php, tests/type/ActiveRecordDynamicStaticMethodReturnTypeExtensionTest.php, tests/type/ContainerDynamicMethodReturnTypeExtensionTest.php Updated fixture/config paths and doc comments for new structure.
tests/stub/MyActiveRecord.php Simplified docblock comments.
tests/web/property/ApplicationPropertiesClassReflectionExtensionTest.php Added new test for property type inference in web application context.

Sequence Diagram(s)

sequenceDiagram
    participant PHPStan
    participant ServiceMap
    participant StubFilesExtension

    PHPStan->>ServiceMap: Load config (with phpstan.application_type)
    ServiceMap->>ServiceMap: Validate and store application type
    PHPStan->>StubFilesExtension: getFiles()
    StubFilesExtension->>ServiceMap: getApplicationType()
    StubFilesExtension->>StubFilesExtension: Resolve stub file for application type
    StubFilesExtension-->>PHPStan: Return stub file path(s)
    PHPStan->>StubFiles: Load stub for analysis
Loading

Possibly related PRs

  • #43: Adds tests for session property availability in console/web applications, closely related to this PR's overhaul of property reflection via stubs and application type config.
  • #26: Improves ServiceMap configuration validation and modularization, overlapping with this PR's enhancements to application type handling.
  • #35: Moves config fixtures and updates test paths, directly related to the config/test path updates in this PR.

Poem

In the warren of code, a rabbit did leap,
Swapping old reflections for stubs nice and neat.
Now PHPStan knows if it's web or console in play,
With ServiceMap guiding the type-aware way.
No more guessing, just hop to the right file—
This bunny brings static analysis in style!
🐇✨


📜 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 250c3c8 and dce363b.

📒 Files selected for processing (3)
  • phpstan.neon (2 hunks)
  • tests/extension-test.neon (1 hunks)
  • tests/web/property/ApplicationPropertiesClassReflectionExtensionTest.php (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • tests/web/property/ApplicationPropertiesClassReflectionExtensionTest.php
🚧 Files skipped from review as they are similar to previous changes (2)
  • tests/extension-test.neon
  • phpstan.neon
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.3-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.2-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.3-windows-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
  • GitHub Check: phpunit / PHP 8.4-ubuntu-latest
  • GitHub Check: phpunit / PHP 8.1-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
  • GitHub Check: phpunit / PHP 8.3-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
✨ 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.

Copy link

codecov bot commented Jun 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (4e5ae70) to head (dce363b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #45   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
- Complexity        62        71    +9     
===========================================
  Files              1         2    +1     
  Lines            107       129   +22     
===========================================
+ Hits             107       129   +22     

☔ 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 and others added 21 commits June 16, 2025 12:00
…d add new test fixtures for invalid configurations.
…d unit tests for web application type resolution.
…iveRecord`, and `Container` for `PHPStan` analysis.
…sts for Yii Console Application properties.
@terabytesoftw terabytesoftw marked this pull request as ready for review June 16, 2025 23:15
@terabytesoftw terabytesoftw requested a review from Copilot June 16, 2025 23:15
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 ServiceMap configuration to improve how the application type is determined while updating test configuration paths and error message formats. Key changes include replacing fixture paths with configuration paths in tests, updating doc comments and exception messages across the codebase, and introducing a new mechanism to set the application type via the configuration.

Reviewed Changes

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

Show a summary per file
File Description
tests/ServiceMapComponentTest.php Updated configuration file paths and doc comments for component tests.
tests/ServiceMapBehaviorTest.php Updated configuration file paths and revised doc comments for behavior tests.
stub/*.stub New stub files added for different Yii Application types.
src/type/*.php Updated doc comments clarifying dynamic return type extension usage.
src/property/ApplicationPropertiesClassReflectionExtension.php Refactored normalization logic using a new constant for supported application classes.
src/ServiceMap.php Introduces application type extraction from config, updates error messaging, and refactors.
phpstan/neon, phpstan-console.neon, extension.neon Updated configuration paths and service registrations to align with the refactored mapping.
.github/workflows/static.yml Adjusted workflow configuration for concurrency and PHP version.
Comments suppressed due to low confidence (2)

src/reflection/RequestMethodsClassReflectionExtension.php:1

  • This file has been completely removed. Please ensure that any configuration or references to this reflection extension are updated accordingly to avoid broken dependencies.
<?php

src/ServiceMap.php:397

  • Consider clarifying in either documentation or inline comments that the default application type (Application::class) references yii\web\Application, if this behavior is intentional for PHPStan analysis.
        $this->applicationType = $config['phpstan']['application_type'] ?? Application::class;

@terabytesoftw terabytesoftw changed the title refactor: Improve ServiceMap configuration for application types. refactor: Improve ServiceMap configuration for application types (Base, Console, Web) Jun 16, 2025
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: 7

🧹 Nitpick comments (23)
src/reflection/ComponentPropertyReflection.php (1)

44-44: Refine constructor PHPDoc for precision.

The current description “Reflection of the class being analyzed.” is generic and may confuse the declaring‐class role. Consider restoring specificity:

- @param ClassReflection $declaringClass Reflection of the class being analyzed.
+ @param ClassReflection $declaringClass Class reflection of the class declaring the dynamic property.
src/type/ContainerDynamicMethodReturnTypeExtension.php (1)

32-32: Doc comment clarity: The PHPDoc now states "application class resolution," but this extension uses ServiceMap to resolve container service IDs to component class names. Consider rewording to reflect service/component resolution.

Example:

- * @see ServiceMap for application class resolution.
+ * @see ServiceMap for component/service class resolution.
tests/data/property/BehaviorPropertiesClassReflectionType.php (1)

36-79: Nit: keep array notation consistent with PHPStan conventions

assertType('array<mixed>', …) passes, but PHPStan’s preferred generic form is array.
(Not blocking, purely cosmetic.)

-        assertType('array<mixed>', $component->arrayProperty);
+        assertType('array', $component->arrayProperty);
tests/console/config/config.php (1)

12-16: Consider using yii\web\View instead of yii\base\View

yii\base\View is an abstract base; console and web apps typically register yii\web\View. Swapping to the concrete class avoids accidental instantiation errors if this config is reused outside tests.

-use yii\base\View;
+use yii\web\View;
tests/type/ActiveRecordDynamicMethodReturnTypeExtensionTest.php (2)

40-42: Windows-compatibility: avoid hard-coding forward slashes in fixture path

gatherAssertTypes() will happily read the file, but the literal forward-slash will break the build on Windows runners.
Using DIRECTORY_SEPARATOR (or sprintf('%s/data/type/…', $directory)) keeps the test platform-agnostic.

-        yield from self::gatherAssertTypes(
-            "{$directory}/data/type/ActiveRecordDynamicMethodReturnType.php",
-        );
+        yield from self::gatherAssertTypes(
+            $directory . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'type' .
+            DIRECTORY_SEPARATOR . 'ActiveRecordDynamicMethodReturnType.php',
+        );

45-48: Nit: dirname(DIR) repetition

The same expression appears in every test class; consider extracting a private static helper (or a PHPUnit base class) to centralise the path construction and cut duplication.

tests/ServiceMapBehaviorTest.php (2)

23-24: Grammar nitpick in docblock

“Ensures compatibility with based configuration files.” reads awkwardly after dropping “fixture-”. Suggest:

- * - Ensures compatibility with based configuration files.
+ * - Ensures compatibility with the provided configuration files.

39-42: Path construction duplicated across tests

Every test method builds $configPath the same way. Extracting a private helper will:

  1. Reduce 17+ identical concatenations,
  2. Prevent future typos,
  3. Make the path change-friendly.

Example:

private static function config(string $file): string
{
    return __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . $file;
}

Then:

-$configPath = __DIR__ . "{$ds}config{$ds}config.php";
+$configPath = self::config('config.php');
tests/ServiceMapServiceTest.php (2)

27-28: Docblock wording

Same grammar tweak as in the behaviour test.

- * - Ensures compatibility with based configuration files.
+ * - Ensures compatibility with the provided configuration files.

60-62: Consider helper for repeated config-file paths

The concatenation pattern is copy-pasted in ~30 places in this file. A small helper (see previous comment) would improve maintainability.

stub/BaseYiiWeb.stub (1)

11-18: Consider using a typed static property for better analysis

Since PHP 7.4 allows typed static properties and this file exists solely for static analysis, declaring the type directly helps PHPStan without relying on the docblock.

-        /**
-         * @var \yii\web\Application
-         */
-        public static $app;
+        public static \yii\web\Application $app;

Optional, but increases precision and removes the need for the phpDoc.

tests/ServiceMapComponentTest.php (1)

24-24: Doc-block grammar typo

The phrase “Ensures compatibility with based configuration files.” is missing a word – it should read “with configuration files” (or similar).

tests/console/property/ApplicationPropertiesClassReflectionExtensionTest.php (2)

38-40: Prefer DIRECTORY_SEPARATOR-independent concatenation

Interpolating a Unix separator directly ("{$directory}/data/…") will break on Windows if the tests are ever executed there.
Use DIRECTORY_SEPARATOR or, even simpler, sprintf('%s%s…', $directory, DIRECTORY_SEPARATOR)/$directory . '/data/…' because PHP resolves forward-slashes fine on Windows.

-            "{$directory}/data/property/ApplicationPropertiesClassReflectionType.php",
+            $directory . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'property' . DIRECTORY_SEPARATOR
+            . 'ApplicationPropertiesClassReflectionType.php',

45-45: Hard-coded filename duplicates path logic

dirname(__DIR__) . '/extension-console-test.neon' repeats the forward-slash pattern called out above; consider refactoring to a small helper or reuse $directory for consistency & cross-platform safety.

No functional bug, only maintainability.

tests/ServiceMapTest.php (3)

23-28: Minor wording typo in docblock

“Ensures compatibility with based configuration files…” → “base configuration files…”.

Pure documentation; no runtime impact.


40-63: Path building repetition

Each test assembles paths manually with $ds. This is verbose and easy to mistype. Consider extracting a private function fixture(string $relative): string helper to DRY these lines.

Example:

-        $ds = DIRECTORY_SEPARATOR;
-        $configPath = __DIR__ . "{$ds}console{$ds}config{$ds}config.php";
+        $configPath = $this->fixture('console/config/config.php');

69-94: Exception messages are brittle

Hard-coding the full path in the expected message ($configPath interpolation) means the test will fail if it is executed from a different directory (e.g. vendor-dir inside another project).
Match only the stable part of the message or use expectExceptionMessageMatches() with a regex.

-        $this->expectExceptionMessage("Configuration file '{$configPath}' must contain a valid 'phpstan' 'array'.");
+        $this->expectExceptionMessageMatches('/must contain a valid .*phpstan.*array/');
src/StubFilesExtension.php (1)

81-86: Nit: Path assembly can be simplified

dirname(__DIR__) . '/stub' is cross-platform safe; the extra {$ds} indirection is unnecessary.

Not a blocker.

tests/web/property/ApplicationPropertiesClassReflectionExtensionTest.php (1)

26-27: Update copyright year to reflect current year.

The copyright notice shows 2023, but this is a new file being added in 2025.

Apply this diff to update the copyright year:

- * @copyright Copyright (C) 2023 Terabytesoftw.
+ * @copyright Copyright (C) 2025 Terabytesoftw.
tests/console/data/property/ApplicationPropertiesClassReflectionType.php (1)

35-36: Update copyright year to reflect current year.

The copyright notice shows 2023, but this is a new file being added in 2025.

Apply this diff to update the copyright year:

- * @copyright Copyright (C) 2023 Terabytesoftw.
+ * @copyright Copyright (C) 2025 Terabytesoftw.
src/property/ApplicationPropertiesClassReflectionExtension.php (1)

44-46: Fix incorrect PHPDoc @see syntax.

The ::class notation is not valid in PHPDoc @see tags.

Apply this diff to fix the PHPDoc syntax:

- * @see \yii\base\Application::class for Yii Base Application class.
- * @see \yii\console\Application::class for Yii Console Application class.
- * @see \yii\web\Application::class for Yii Web Application class.
+ * @see \yii\base\Application for Yii Base Application class.
+ * @see \yii\console\Application for Yii Console Application class.
+ * @see \yii\web\Application for Yii Web Application class.
src/ServiceMap.php (1)

110-112: Consider adding @throws tag for potential exceptions.

The constructor can throw InvalidArgumentException from the new processApplicationType method if validation is added.

Add the missing @throws tag to the constructor docblock after the suggested validation is implemented:

  * @throws InvalidArgumentException if one or more arguments are invalid, of incorrect type or format.
+ * @throws InvalidArgumentException if the configured application type is not a valid Yii Application class.
  * @throws ReflectionException if the service definitions can't be resolved or are invalid.
tests/web/data/property/ApplicationPropertiesClassReflectionType.php (1)

38-41: Docblock polish: replace stray period with a colon

Slight wording tweak for consistency/readability.

- * Key features.
+ * Key features:
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4e5ae70 and bf5eb4a.

📒 Files selected for processing (55)
  • .github/workflows/static.yml (1 hunks)
  • composer-require-checker.json (1 hunks)
  • extension.neon (1 hunks)
  • phpstan-console.neon (1 hunks)
  • phpstan.neon (2 hunks)
  • src/ServiceMap.php (22 hunks)
  • src/StubFilesExtension.php (1 hunks)
  • src/property/ApplicationPropertiesClassReflectionExtension.php (4 hunks)
  • src/property/BehaviorPropertiesClassReflectionExtension.php (2 hunks)
  • src/reflection/ComponentPropertyReflection.php (1 hunks)
  • src/reflection/RequestMethodsClassReflectionExtension.php (0 hunks)
  • src/reflection/RequestPropertiesClassReflectionExtension.php (0 hunks)
  • src/reflection/ResponsePropertiesClassReflectionExtension.php (0 hunks)
  • src/type/ActiveQueryDynamicMethodReturnTypeExtension.php (1 hunks)
  • src/type/ContainerDynamicMethodReturnTypeExtension.php (1 hunks)
  • stub/BaseYii.stub (1 hunks)
  • stub/BaseYiiConsole.stub (1 hunks)
  • stub/BaseYiiWeb.stub (1 hunks)
  • tests/ServiceMapBehaviorTest.php (8 hunks)
  • tests/ServiceMapComponentTest.php (10 hunks)
  • tests/ServiceMapServiceTest.php (24 hunks)
  • tests/ServiceMapTest.php (1 hunks)
  • tests/StubFilesExtensionTest.php (1 hunks)
  • tests/bootstrap.php (0 hunks)
  • tests/config/config.php (2 hunks)
  • tests/config/phpstan-unsupported-is-not-array.php (1 hunks)
  • tests/config/phpstan-unsupported-type-array-invalid.php (1 hunks)
  • tests/console/config/config.php (1 hunks)
  • tests/console/data/property/ApplicationPropertiesClassReflectionType.php (1 hunks)
  • tests/console/extension-console-test.neon (1 hunks)
  • tests/console/property/ApplicationPropertiesClassReflectionExtensionTest.php (2 hunks)
  • tests/data/method/BehaviorMethodsClassReflectionType.php (2 hunks)
  • tests/data/property/BehaviorPropertiesClassReflectionType.php (2 hunks)
  • tests/data/property/UserPropertiesClassReflectionType.php (2 hunks)
  • tests/data/type/ActiveQueryDynamicMethodReturnType.php (7 hunks)
  • tests/data/type/ActiveRecordDynamicMethodReturnType.php (2 hunks)
  • tests/data/type/ActiveRecordDynamicStaticMethodReturnType.php (3 hunks)
  • tests/data/type/ContainerDynamicMethodReturnType.php (13 hunks)
  • tests/extension-test.neon (1 hunks)
  • tests/extension-tests.neon (0 hunks)
  • tests/fixture/data/property/ApplicationConsolePropertiesClassReflectionType.php (0 hunks)
  • tests/fixture/data/property/ApplicationCustomPropertiesClassReflectionType.php (0 hunks)
  • tests/fixture/data/property/ApplicationWebPropertiesClassReflectionType.php (0 hunks)
  • tests/method/BehaviorMethodsClassReflectionExtensionTest.php (1 hunks)
  • tests/property/BehaviorPropertiesClassReflectionExtensionTest.php (2 hunks)
  • tests/property/UserPropertiesClassReflectionExtensionTest.php (1 hunks)
  • tests/stub/MyActiveRecord.php (0 hunks)
  • tests/type/ActiveQueryDynamicReturnTypeExtensionTest.php (1 hunks)
  • tests/type/ActiveRecordDynamicMethodReturnTypeExtensionTest.php (1 hunks)
  • tests/type/ActiveRecordDynamicStaticMethodReturnTypeExtensionTest.php (1 hunks)
  • tests/type/ContainerDynamicMethodReturnTypeExtensionTest.php (1 hunks)
  • tests/web/config/config.php (1 hunks)
  • tests/web/data/property/ApplicationPropertiesClassReflectionType.php (1 hunks)
  • tests/web/extension-test.neon (1 hunks)
  • tests/web/property/ApplicationPropertiesClassReflectionExtensionTest.php (1 hunks)
💤 Files with no reviewable changes (9)
  • tests/bootstrap.php
  • tests/extension-tests.neon
  • tests/stub/MyActiveRecord.php
  • tests/fixture/data/property/ApplicationCustomPropertiesClassReflectionType.php
  • src/reflection/RequestPropertiesClassReflectionExtension.php
  • src/reflection/ResponsePropertiesClassReflectionExtension.php
  • src/reflection/RequestMethodsClassReflectionExtension.php
  • tests/fixture/data/property/ApplicationWebPropertiesClassReflectionType.php
  • tests/fixture/data/property/ApplicationConsolePropertiesClassReflectionType.php
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: terabytesoftw
PR: yii2-extensions/phpstan#40
File: src/ServiceMap.php:0-0
Timestamp: 2025-06-14T17:41:48.780Z
Learning: The yii2-extensions/phpstan repository contains a PHPStan extension specifically designed for static analysis of Yii framework applications.
phpstan.neon (1)
Learnt from: terabytesoftw
PR: yii2-extensions/phpstan#40
File: src/ServiceMap.php:0-0
Timestamp: 2025-06-14T17:41:48.780Z
Learning: The yii2-extensions/phpstan repository contains a PHPStan extension specifically designed for static analysis of Yii framework applications.
extension.neon (1)
Learnt from: terabytesoftw
PR: yii2-extensions/phpstan#40
File: src/ServiceMap.php:0-0
Timestamp: 2025-06-14T17:41:48.780Z
Learning: The yii2-extensions/phpstan repository contains a PHPStan extension specifically designed for static analysis of Yii framework applications.
src/StubFilesExtension.php (1)
Learnt from: terabytesoftw
PR: yii2-extensions/phpstan#40
File: src/ServiceMap.php:0-0
Timestamp: 2025-06-14T17:41:48.780Z
Learning: The yii2-extensions/phpstan repository contains a PHPStan extension specifically designed for static analysis of Yii framework applications.
🧬 Code Graph Analysis (19)
tests/type/ActiveRecordDynamicStaticMethodReturnTypeExtensionTest.php (3)
tests/type/ActiveQueryDynamicReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/type/ActiveRecordDynamicMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/type/ContainerDynamicMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/data/property/BehaviorPropertiesClassReflectionType.php (1)
tests/stub/MyComponent.php (1)
  • MyComponent (22-28)
tests/ServiceMapBehaviorTest.php (1)
src/ServiceMap.php (1)
  • ServiceMap (64-608)
tests/type/ActiveRecordDynamicMethodReturnTypeExtensionTest.php (3)
tests/type/ActiveQueryDynamicReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/type/ActiveRecordDynamicStaticMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/type/ContainerDynamicMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/data/type/ActiveQueryDynamicMethodReturnType.php (3)
tests/stub/MyActiveRecord.php (1)
  • MyActiveRecord (23-48)
tests/stub/Post.php (1)
  • find (18-21)
tests/stub/PostQuery.php (1)
  • published (18-21)
tests/data/type/ActiveRecordDynamicStaticMethodReturnType.php (3)
tests/stub/Category.php (1)
  • Category (31-46)
tests/stub/MyActiveRecord.php (1)
  • MyActiveRecord (23-48)
tests/stub/User.php (1)
  • User (26-66)
tests/property/BehaviorPropertiesClassReflectionExtensionTest.php (2)
tests/method/BehaviorMethodsClassReflectionExtensionTest.php (1)
  • getAdditionalConfigFiles (43-46)
tests/property/UserPropertiesClassReflectionExtensionTest.php (1)
  • getAdditionalConfigFiles (43-46)
tests/web/config/config.php (5)
tests/stub/BehaviorOne.php (1)
  • BehaviorOne (22-56)
tests/stub/BehaviorTwo.php (1)
  • BehaviorTwo (22-40)
tests/stub/MyActiveRecord.php (1)
  • MyActiveRecord (23-48)
tests/stub/MyComponent.php (1)
  • MyComponent (22-28)
tests/stub/User.php (1)
  • User (26-66)
tests/data/type/ActiveRecordDynamicMethodReturnType.php (3)
tests/stub/Category.php (1)
  • Category (31-46)
tests/stub/MyActiveRecord.php (1)
  • MyActiveRecord (23-48)
tests/stub/User.php (1)
  • User (26-66)
tests/type/ActiveQueryDynamicReturnTypeExtensionTest.php (3)
tests/type/ActiveRecordDynamicMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/type/ActiveRecordDynamicStaticMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/type/ContainerDynamicMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/property/UserPropertiesClassReflectionExtensionTest.php (1)
tests/property/BehaviorPropertiesClassReflectionExtensionTest.php (1)
  • getAdditionalConfigFiles (43-46)
tests/console/property/ApplicationPropertiesClassReflectionExtensionTest.php (1)
tests/web/property/ApplicationPropertiesClassReflectionExtensionTest.php (2)
  • DataProvider (48-52)
  • getAdditionalConfigFiles (43-46)
tests/data/type/ContainerDynamicMethodReturnType.php (1)
tests/stub/MyActiveRecord.php (1)
  • MyActiveRecord (23-48)
tests/method/BehaviorMethodsClassReflectionExtensionTest.php (1)
tests/property/BehaviorPropertiesClassReflectionExtensionTest.php (1)
  • getAdditionalConfigFiles (43-46)
tests/ServiceMapTest.php (1)
src/ServiceMap.php (2)
  • ServiceMap (64-608)
  • getApplicationType (150-153)
tests/console/data/property/ApplicationPropertiesClassReflectionType.php (1)
tests/web/data/property/ApplicationPropertiesClassReflectionType.php (21)
  • ApplicationPropertiesClassReflectionType (47-163)
  • testReturnApplicationInstanceFromYiiApp (49-52)
  • testReturnAssetManagerFromComponent (54-57)
  • testReturnCacheFromComponent (59-62)
  • testReturnStringFromCharsetProperty (64-67)
  • testReturnControllerFromProperty (69-72)
  • testReturnDbFromComponent (74-77)
  • testReturnStringFromDefaultRouteProperty (79-82)
  • testReturnErrorHandlerFromComponent (84-87)
  • testReturnFormatterFromComponent (89-92)
  • testReturnI18nFromComponent (99-102)
  • testReturnStringFromLanguageProperty (104-107)
  • testReturnLogFromComponent (109-112)
  • testReturnMailerFromComponent (114-117)
  • testReturnRequestFromComponent (119-122)
  • testReturnResponseFromComponent (124-127)
  • testReturnStringFromSourceLanguageProperty (134-137)
  • testReturnStringFromTimeZoneProperty (139-142)
  • testReturnStringFromUniqueIdProperty (144-147)
  • testReturnUrlManagerFromComponent (149-152)
  • testReturnViewFromComponent (159-162)
tests/type/ContainerDynamicMethodReturnTypeExtensionTest.php (3)
tests/type/ActiveQueryDynamicReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/type/ActiveRecordDynamicMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
tests/type/ActiveRecordDynamicStaticMethodReturnTypeExtensionTest.php (1)
  • getAdditionalConfigFiles (45-48)
src/StubFilesExtension.php (2)
src/type/ContainerDynamicMethodReturnTypeExtension.php (1)
  • __construct (45-48)
src/ServiceMap.php (3)
  • __construct (118-138)
  • ServiceMap (64-608)
  • getApplicationType (150-153)
tests/web/property/ApplicationPropertiesClassReflectionExtensionTest.php (1)
tests/console/property/ApplicationPropertiesClassReflectionExtensionTest.php (4)
  • DataProvider (48-52)
  • ApplicationPropertiesClassReflectionExtensionTest (29-53)
  • dataFileAsserts (34-41)
  • getAdditionalConfigFiles (43-46)
🔇 Additional comments (46)
src/type/ActiveQueryDynamicMethodReturnTypeExtension.php (1)

258-258: Approve PHPDoc refinement for clarity.

The updated description “Reflection of the class being analyzed.” accurately conveys the role of $classReflection in this context and aligns with similar doc improvements elsewhere.

tests/data/property/UserPropertiesClassReflectionType.php (3)

5-5: Verify test namespace mapping.

You’ve updated the namespace to yii2\extensions\phpstan\tests\data\property; ensure your composer.json (autoload-dev PSR-4) reflects this path change so PHPUnit and PHPStan can locate the fixtures.


12-12: Approve docblock wording enhancement.

The refined class‐level description is clearer and aligns with overall test fixture restructuring.


22-22: Approve list item clarification.

The improved phrasing of the second bullet enhances readability without altering intent.

composer-require-checker.json (1)

5-5: Approve symbol-whitelist update.

Adding "PHPStan\\PhpDoc\\StubFilesExtension" matches your new stub extension implementation and keeps the dependency-checker in sync.

phpstan.neon (2)

18-18: Verify updated analysis paths.

You’ve narrowed paths to tests/web; confirm that tests/web exists and contains all intended web tests, and that phpstan-console.neon covers console fixtures.


31-31: Verify config_path alignment.

Ensure tests/web/config/config.php is present (and updated from the old fixture directory), so PHPStan can bootstrap the correct Yii application context.

tests/config/config.php (2)

5-5: Approve addition of View import. The import of yii\web\View is required for the new view component configuration.


30-32: Approve view component configuration. Including the view component with View::class aligns the web application test setup with the new application type-aware PHPStan enhancements.

tests/console/extension-console-test.neon (1)

1-7: Approve new console PHPStan test configuration. This NEON file correctly includes extension.neon and sets yii2.config_path to the console config, mirroring the web setup for application type separation.

tests/extension-test.neon (1)

1-7: Approve new web PHPStan extension test configuration. Including extension.neon and pointing yii2.config_path to the web config file aligns with the application type-specific testing strategy.

tests/config/phpstan-unsupported-is-not-array.php (1)

1-8: Approve edge-case PHPStan config test. Returning 'phpstan' => 1 intentionally validates how the system handles non-array config values, bolstering robustness.

tests/data/method/BehaviorMethodsClassReflectionType.php (1)

5-6: Namespace update looks correct

The new namespace matches the relocated fixtures directory and keeps PSR-4 consistency. No issues spotted.

tests/config/phpstan-unsupported-type-array-invalid.php (1)

5-9: Good negative-case fixture

Explicitly supplying an invalid non-string application_type will help ensure ServiceMap throws as expected. No changes required.

tests/data/property/BehaviorPropertiesClassReflectionType.php (1)

5-6: Namespace realignment confirmed

Directory and namespace now align; this prevents autoloading issues in the test suite.

tests/web/extension-test.neon (2)

1-2: Set up base PHPStan extension config.
Including ../../extension.neon correctly pulls in the main extension configuration for web tests.


4-6: Define web application config path.
yii2.config_path points to the web application fixture at %rootDir%/../../../tests/web/config/config.php. Confirm this matches the test fixture layout.

tests/type/ActiveQueryDynamicReturnTypeExtensionTest.php (2)

40-42: Update fixture path in dataFileAsserts.
The intermediate fixture directory has been removed; the path now correctly points to data/type/ActiveQueryDynamicMethodReturnType.php.


47-48: Correct configuration filename.
Using extension-test.neon ensures consistency with the new naming convention across the test suite.

tests/type/ActiveRecordDynamicStaticMethodReturnTypeExtensionTest.php (2)

40-42: Update fixture path in dataFileAsserts.
The path now points to data/type/ActiveRecordDynamicStaticMethodReturnType.php, reflecting the removal of the fixture folder.


47-48: Align config file reference.
Switched to extension-test.neon to match the unified test configuration naming.

tests/type/ContainerDynamicMethodReturnTypeExtensionTest.php (2)

40-42: Update fixture path in dataFileAsserts.
The path now correctly targets data/type/ContainerDynamicMethodReturnType.php after removing the fixture directory.


47-48: Unify config file naming.
Returning extension-test.neon aligns this class with the other tests’ configuration references.

tests/property/UserPropertiesClassReflectionExtensionTest.php (2)

38-40: Standardize fixture path.
Now correctly pointing to data/property/UserPropertiesClassReflectionType.php, reflecting the simplified directory structure.


45-46: Correct configuration file reference.
Using extension-test.neon here matches the convention used across all test suites.

src/property/BehaviorPropertiesClassReflectionExtension.php (2)

100-101: Docblock wording only – no action required

Parameter description was unified; implementation untouched. ✅


126-127: Docblock consistency looks good

The same clarification was applied to findPropertyInBehaviors(). No further comments.

tests/ServiceMapBehaviorTest.php (1)

134-136: Updated exception message matches source implementation – LGTM

Message now mirrors ServiceMap::throwErrorWhenIsNotString(). ✅

tests/ServiceMapServiceTest.php (1)

216-218: Dynamic path in expected message

Embedding $configPath directly in expectExceptionMessage() is great; it avoids brittle hard-coding. 👍

tests/data/type/ActiveRecordDynamicStaticMethodReturnType.php (2)

5-5: Namespace update matches new directory structure

The change aligns the namespace with the moved file. No issues spotted.


38-145: Refactored assertions are clearer

Inlining the expressions into assertType() removes unnecessary variables and keeps the tests succinct. Tests still exercise the same scenarios – good refactor.

tests/property/BehaviorPropertiesClassReflectionExtensionTest.php (1)

38-40: Confirm updated fixture & config paths work at runtime

The fixture/ segment was dropped and the config file renamed to extension-test.neon.
Both look consistent with the other tests, but please double-check that:

  1. tests/data/property/BehaviorPropertiesClassReflectionType.php really exists, and
  2. the new extension-test.neon is picked up by phpstan analyse (it replaces the old pluralised file).

A quick grep/script will prevent a silent “file not found” during CI.

#!/bin/bash
fd BehaviorPropertiesClassReflectionType.php tests/data | head
fd extension-test.neon tests | head

Also applies to: 45-45

tests/data/type/ContainerDynamicMethodReturnType.php (2)

5-5: Namespace realignment LGTM

The namespace switch to tests\data\type matches the new folder layout – nothing else to flag.


88-92: Minor style change only – fine

Inlining the get() call and using the trailing-comma style is purely cosmetic and does not affect PHPStan inference.

tests/data/type/ActiveRecordDynamicMethodReturnType.php (1)

40-44: Assertions updated – no functional change

All modified assertType() calls simply collapse temporary variables and adopt trailing-comma formatting.
Type strings remain identical; the refactor is safe.

Also applies to: 50-54, 60-64, 70-74, 80-84, 90-94, 100-104, 110-114, 120-124, 130-136, 143-147, 153-156

tests/ServiceMapComponentTest.php (1)

41-43: ```shell
#!/usr/bin/env bash
echo "Occurrences of default config path in tests/ServiceMapComponentTest.php:"
rg -n '{$ds}config{$ds}config.php' tests/ServiceMapComponentTest.php || true
echo
echo "Total count:"
rg -c '{$ds}config{$ds}config.php' tests/ServiceMapComponentTest.php


</details>
<details>
<summary>tests/data/type/ActiveQueryDynamicMethodReturnType.php (2)</summary>

`5-8`: **Namespace/import update looks correct**

The namespace realignment and addition of `yii\db\Exception` keep the file consistent with the new directory layout.

---

`43-46`: **Updated `assertType()` expectations align with new generics**

All revised `assertType()` invocations correctly express the expected union/generic types after the refactor. No issues spotted.  



Also applies to: 51-51, 63-64, 82-84, 111-113, 164-168, 174-181, 208-213, 217-221

</details>
<details>
<summary>stub/BaseYiiConsole.stub (1)</summary>

`1-23`: **Minimal console-app stub is sound**

The stub mirrors Yii’s real class hierarchy and gives PHPStan the `$app` property typed to `\yii\console\Application`. LGTM.

</details>
<details>
<summary>tests/web/config/config.php (1)</summary>

`5-66`: **Comprehensive test config – no blocking issues**

Configuration is syntactically valid, uses strict types, and covers a rich set of scenarios (behaviors, components, DI container). 👍

</details>
<details>
<summary>tests/method/BehaviorMethodsClassReflectionExtensionTest.php (2)</summary>

`38-40`: **Path correction matches new fixture layout**

Switching to `data/method/...` is consistent with the flattened test structure.

---

`45-46`: **Config filename update aligns with other tests**

`extension-test.neon` path mirrors the change made across the suite. All good.

</details>
<details>
<summary>extension.neon (1)</summary>

`47-50`: **Service registration LGTM**

`StubFilesExtension` is correctly tagged with `phpstan.stubFilesExtension`; PHPStan will autowire the `ServiceMap` dependency.

No changes required.

</details>
<details>
<summary>phpstan-console.neon (1)</summary>

`1-32`: **Configuration baseline looks solid**

The console-specific config cleanly isolates console tests, enables strict rules, and wires the bootstrap file.  
Nothing blocking here.

</details>
<details>
<summary>tests/console/data/property/ApplicationPropertiesClassReflectionType.php (1)</summary>

`45-48`: **Verify the necessity of AssetManager in console application context.**

`AssetManager` is typically a web-specific component used for managing CSS and JavaScript assets. Its presence in a console application test is unusual and might indicate a configuration issue or unnecessary component.

```shell
#!/bin/bash
# Description: Check if AssetManager is commonly used in console applications within the codebase

# Search for AssetManager usage in console-related files
echo "=== Searching for AssetManager in console contexts ==="
rg -A 5 "AssetManager" --glob "*console*" --glob "!*test*"

# Check if AssetManager is configured in console config files
echo -e "\n=== Checking console configuration files ==="
fd -e php -e neon "console.*config" --exec grep -l "assetManager" {} \;

# Look for the console application configuration used in tests
echo -e "\n=== Checking test console config ==="
cat tests/console/config/config.php 2>/dev/null || echo "Console config file not found"
src/property/ApplicationPropertiesClassReflectionExtension.php (1)

110-120: Verify the impact of reordering property resolution checks.

The order of checks has been changed to prioritize service map component lookup before annotation properties. This could affect behavior if a property exists in both the service map and annotations.

#!/bin/bash
# Description: Check for potential conflicts between service map components and annotation properties

# Search for properties that might be defined in both annotations and service map
echo "=== Searching for @property annotations in Application classes ==="
ast-grep --pattern '@property $_ $$PROP_NAME' --lang php | grep -E "(Application|BaseApplication)" -A 2

# Check if any common property names exist in both component definitions and annotations
echo -e "\n=== Common Yii component names that might conflict ==="
rg -o "'\w+' =>" extension.neon | cut -d"'" -f2 | sort | uniq | while read comp; do
    echo "Checking for @property.*$comp in Application classes:"
    rg "@property.*\$$comp" --glob "*Application*.php"
done

@terabytesoftw terabytesoftw merged commit 58ea6fb into main Jun 16, 2025
45 checks passed
@terabytesoftw terabytesoftw deleted the fix-mini-23 branch June 16, 2025 23:44
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.

2 participants