Skip to content

refactor: Update PHPStan configuration paths and create new config files for improved structure and clarity. #48

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 5 commits into from
Jun 18, 2025

Conversation

terabytesoftw
Copy link
Member

@terabytesoftw terabytesoftw commented Jun 18, 2025

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

Summary by CodeRabbit

  • Documentation
    • Updated documentation to reflect new configuration file naming conventions and added instructions for specifying a temporary directory for PHPStan runtime files.
    • Improved configuration examples and clarified parameter usage in guides and README.
  • Chores
    • Updated configuration files and test setups to use new config file paths and temporary directory settings.
    • Added a .gitignore to exclude runtime files from version control.
    • Refactored test classes to centralize configuration file path definitions for improved maintainability.
  • Bug Fixes
    • Documented updates to PHPStan configuration paths and file structure in the changelog.

Copy link

coderabbitai bot commented Jun 18, 2025

Walkthrough

Configuration file paths throughout the project were updated from config.php to phpstan-config.php (and similarly for console configs). A new tmpDir parameter was added to specify a temporary directory for PHPStan runtime files. Documentation and test files were modified to reflect these changes, and a .gitignore was added for the runtime directory.

Changes

Files/Group Change Summary
CHANGELOG.md Added bug fix entry for PHPStan config path updates and new config files.
README.md, docs/configuration.md, docs/installation.md Updated documentation to reference new config filenames and added tmpDir parameter in examples.
phpstan.neon, phpstan-console.neon, tests/extension-test.neon, tests/console/extension-console-test.neon Changed yii2.config_path to new config filenames; added tmpDir parameter.
tests/ServiceMapBehaviorTest.php, tests/ServiceMapComponentTest.php, tests/ServiceMapServiceTest.php, tests/ServiceMapTest.php Introduced private BASE_PATH constant for config paths in tests; simplified config file path usage.
tests/StubFilesExtensionTest.php Updated config file path from config.php to phpstan-config.php.
tests/runtime/.gitignore Added to ignore all files in tests/runtime except .gitignore itself.

Sequence Diagram(s)

sequenceDiagram
    participant PHPStan
    participant ProjectConfig
    participant RuntimeDir

    PHPStan->>ProjectConfig: Load config from phpstan-config.php
    PHPStan->>RuntimeDir: Use tmpDir for temp files (%cwd%/tests/runtime)
    Note right of PHPStan: All analysis uses updated config paths and tmpDir
Loading

Poem

In the warren where configs hop and play,
We’ve tidied up the paths today!
With phpstan-config.php now clear and bright,
And a tmpDir for files out of sight.
Our tests all nibble from the right file,
🐇— this rabbit’s code is neat and 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 2a57d80 and 3aaf40c.

📒 Files selected for processing (8)
  • README.md (1 hunks)
  • phpstan-console.neon (1 hunks)
  • phpstan.neon (1 hunks)
  • tests/ServiceMapBehaviorTest.php (5 hunks)
  • tests/ServiceMapComponentTest.php (8 hunks)
  • tests/ServiceMapServiceTest.php (15 hunks)
  • tests/ServiceMapTest.php (3 hunks)
  • tests/console/extension-console-test.neon (1 hunks)
✅ Files skipped from review due to trivial changes (3)
  • phpstan-console.neon
  • tests/ServiceMapComponentTest.php
  • tests/ServiceMapServiceTest.php
🚧 Files skipped from review as they are similar to previous changes (5)
  • phpstan.neon
  • tests/console/extension-console-test.neon
  • README.md
  • tests/ServiceMapTest.php
  • tests/ServiceMapBehaviorTest.php
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-ubuntu-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.3-windows-latest
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.1-windows-latest
  • GitHub Check: phpunit / PHP 8.2-windows-latest
  • GitHub Check: phpunit / PHP 8.3-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.

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

codecov bot commented Jun 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (ad8bed7) to head (3aaf40c).
Report is 1 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##                main       #48   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity        71        71           
===========================================
  Files              2         2           
  Lines            129       129           
===========================================
  Hits             129       129           

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

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

🔭 Outside diff range comments (1)
README.md (1)

70-86: Documentation path mismatch: snippet still instructs to create config/test.php

The sample phpstan.neon now expects

yii2:
    config_path: config/phpstan-config.php

but the paragraph right below says “Create a PHPStan-specific config file (config/test.php).”
This inconsistency will confuse users.

-Create a PHPStan-specific config file (`config/test.php`).
+Create a PHPStan-specific config file (`config/phpstan-config.php`).

Update the filename everywhere (and in the code block header if present).

♻️ Duplicate comments (1)
tests/ServiceMapTest.php (1)

40-42: Apply the same DRY helper for config paths

These two snippets duplicate the logic already noted in ServiceMapBehaviorTest.php. Once a helper/constant is introduced, switch to:

$configPath = self::CONFIG_BASE . 'phpstan-config.php';          // web
$configPath = self::CONFIG_BASE . 'console/phpstan-console-config.php'; // console

(replace with whatever helper you decide on).

Also applies to: 56-58

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

18-18: Consider mentioning tmpDir addition.

The entry summarizes config path updates but omits the new tmpDir parameter. You may want to note the addition of the runtime directory in the changelog.

tests/StubFilesExtensionTest.php (1)

31-34: Avoid hard-coding identical path construction in every test

Nearly every test class now repeats

$ds = DIRECTORY_SEPARATOR;
$configPath = __DIR__ . "{$ds}config{$ds}phpstan-config.php";

Consider extracting a helper (e.g. TestCaseWithConfig::getConfigPath()) or defining a const CONFIG_PATH in a base test to reduce duplication and the risk of typos when the path changes again.

tests/ServiceMapServiceTest.php (1)

60-72: Repeated $configPath construction clutters the test file

The same 3-line snippet is duplicated nine times. A tiny helper will make the intent clearer and centralise future changes:

+    private static function configPath(): string
+    {
+        return __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'phpstan-config.php';
+    }
...
-        $ds = DIRECTORY_SEPARATOR;
-        $configPath = __DIR__ . "{$ds}config{$ds}phpstan-config.php";
-        $serviceMap = new ServiceMap($configPath);
+        $serviceMap = new ServiceMap(self::configPath());

This keeps each test focused on its assertion and eliminates duplicated string interpolation.

Also applies to: 84-88, 100-104, 116-120, 132-136, 148-152, 164-168, 180-184, 196-200

tests/ServiceMapComponentTest.php (1)

40-58: Same duplication issue – extract a helper in a base test

ServiceMapComponentTest repeats the identical path building logic four times.
Re-use the helper/constant suggested for ServiceMapServiceTest to keep tests DRY.

Also applies to: 72-90, 104-122, 134-138

tests/ServiceMapBehaviorTest.php (1)

40-42: Factor-out repeated config-path construction

Every test re-builds the same path string; this is four identical snippets in this file (and appears in other test classes, too). Replacing the duplication with a small helper or constant will cut noise and make future renames cheaper:

-final class ServiceMapBehaviorTest extends TestCase
+final class ServiceMapBehaviorTest extends TestCase
 {
+    private const CONFIG_BASE = __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;
+
     public function testReturnBehaviorsWhenValidClassIsClassString(): void
     {
-        $ds = DIRECTORY_SEPARATOR;
-        $configPath = __DIR__ . "{$ds}config{$ds}phpstan-config.php";
+        $configPath = self::CONFIG_BASE . 'phpstan-config.php';

Same simplification applies to the other three occurrences and the sibling test classes.

Also applies to: 61-63, 82-84, 100-102

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ad8bed7 and 2a57d80.

📒 Files selected for processing (13)
  • CHANGELOG.md (1 hunks)
  • README.md (1 hunks)
  • docs/configuration.md (12 hunks)
  • docs/installation.md (4 hunks)
  • phpstan.neon (2 hunks)
  • tests/ServiceMapBehaviorTest.php (4 hunks)
  • tests/ServiceMapComponentTest.php (7 hunks)
  • tests/ServiceMapServiceTest.php (9 hunks)
  • tests/ServiceMapTest.php (2 hunks)
  • tests/StubFilesExtensionTest.php (1 hunks)
  • tests/console/extension-console-test.neon (1 hunks)
  • tests/extension-test.neon (1 hunks)
  • tests/runtime/.gitignore (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
docs/configuration.md (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.
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.2-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.3-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.4-windows-latest
  • GitHub Check: phpunit / PHP 8.4-windows-latest
  • GitHub Check: phpunit-compatibility / PHP 8.1-windows-latest
🔇 Additional comments (11)
tests/runtime/.gitignore (1)

1-2: Configuration directory properly ignored.

The .gitignore correctly omits all runtime files except the .gitignore itself, aligning with the tmpDir setting.

phpstan.neon (2)

20-20: Add tmpDir for PHPStan runtime files.

The new tmpDir parameter points to tests/runtime, matching the .gitignore and ensuring temp files don’t clutter the repo.


33-33: Update yii2.config_path.

Changed path to tests/config/phpstan-config.php aligns with the relocated config fixtures.

docs/installation.md (5)

91-91: Document tmpDir parameter.

The tmpDir entry reflects the new runtime directory setting, ensuring docs mirror the config.


94-94: Update example config_path.

Changed to config/phpstan-config.php to match the new filename in instructions.


103-103: Clarify creation of web config.

Instruction to create config/phpstan-config.php is clear and matches code.


144-144: Clarify creation of console config.

Instruction to create config/phpstan-console-config.php correctly documents the console setup.


170-170: Update console config_path in docs.

Example now points to config/phpstan-console-config.php, matching the file rename.

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

6-6: Update console test config path.

Revised to point at tests/console/config/phpstan-console-config.php, aligning with relocated config fixture.

tests/extension-test.neon (1)

6-6: Confirm the new relative path is resolvable by PHPStan when executed from project root

%rootDir% points to PHPStan’s vendor directory, so the resulting path will be
vendor/phpstan/phpstan/../../../tests/config/phpstan-config.php → effectively tests/config/phpstan-config.php.
That looks correct, but an unnoticed ../ mismatch would silently break all tests.

Please run a quick realpath() check (or let CI run phpstan analyse) to verify the file is really picked up.

docs/configuration.md (1)

17-22: Docs update LGTM

Renamed config_path references and the new tmpDir default are consistently reflected. No further action needed.

Also applies to: 37-42, 51-55, 61-64, 78-82, 104-108, 290-305, 328-342

@terabytesoftw terabytesoftw requested a review from Copilot June 18, 2025 10:45
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 PHPStan configuration by renaming config files, updating paths in tests and docs, and centralizing test config directory handling.

  • Renamed PHPStan config files to phpstan-config.php and phpstan-console-config.php and updated all references.
  • Updated phpstan.neon and phpstan-console.neon to set tmpDir and new config_path.
  • Refactored test classes to use a shared BASE_PATH constant and added .gitignore for runtime files.
  • Updated documentation and README to reflect new filenames and temporary directory instructions.

Reviewed Changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/runtime/.gitignore Added ignore rule for runtime cache files
tests/extension-test.neon Updated config_path to new PHPStan config filename
tests/console/extension-console-test.neon Updated config_path to new PHPStan console config filename
tests/StubFilesExtensionTest.php Updated test to use renamed config file
tests/ServiceMapTest.php Introduced BASE_PATH constant and updated config references
tests/ServiceMapServiceTest.php Introduced BASE_PATH constant and updated config references
tests/ServiceMapComponentTest.php Introduced BASE_PATH constant and updated config references
tests/ServiceMapBehaviorTest.php Introduced BASE_PATH constant and updated config references
phpstan.neon Set tmpDir and updated yii2.config_path
phpstan-console.neon Set tmpDir and updated yii2.config_path
docs/installation.md Updated example filenames and added tmpDir instructions
docs/configuration.md Updated example filenames, added tmpDir and excludePaths
README.md Updated example filenames and added tmpDir instructions
CHANGELOG.md Added entry for updating PHPStan configuration paths
Comments suppressed due to low confidence (2)

tests/ServiceMapServiceTest.php:42

  • [nitpick] The constant name BASE_PATH is generic. Consider renaming it to something more descriptive like CONFIG_BASE_PATH to clarify its purpose.
    private const BASE_PATH = __DIR__ . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR;

docs/configuration.md:21

  • [nitpick] The tmpDir parameter is repeated multiple times across this document. Consider consolidating common parameters or using includes to avoid duplication and reduce maintenance.
    tmpDir: %currentWorkingDirectory%/tests/runtime        

@terabytesoftw terabytesoftw merged commit 9edac44 into main Jun 18, 2025
45 checks passed
@terabytesoftw terabytesoftw deleted the fix-mini-24 branch June 18, 2025 10:47
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