Skip to content

build: raise phpstan to level 8#44

Merged
konradmichalik merged 1 commit intomainfrom
phpstan-8
Jul 24, 2025
Merged

build: raise phpstan to level 8#44
konradmichalik merged 1 commit intomainfrom
phpstan-8

Conversation

@konradmichalik
Copy link
Copy Markdown
Contributor

@konradmichalik konradmichalik commented Jul 24, 2025

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling in command execution and validation to prevent issues when I/O interfaces or loggers are uninitialized.
    • Enhanced test robustness by adding null checks before performing assertions or operations on potentially null variables.
  • Refactor

    • Updated type annotations for better accuracy and code clarity.
  • Chores

    • Increased static analysis strictness for improved code quality.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jul 24, 2025

Walkthrough

This update introduces stricter static analysis by raising PHPStan's level, applies null-safe operator usage to logger and I/O calls to prevent errors from uninitialized properties, adds runtime checks for command input/output initialization, refines type annotations for array properties, and improves test robustness by guarding assertions with null checks.

Changes

File(s) Change Summary
phpstan.neon Increased PHPStan strictness level from 7 to 8.
src/Command/ValidateTranslationCommand.php Added null-safe calls to $this->io, runtime checks for input/output initialization, and imported exception.
src/Validator/AbstractValidator.php Applied null-safe operator to logger debug calls.
src/Validator/MismatchValidator.php Refined PHPDoc type annotation for $keyArray to allow `string
tests/src/Parser/JsonParserTest.php
tests/src/Parser/PhpParserTest.php
tests/src/Result/ValidationRunTest.php
Added null checks before performing assertions or operations on potentially null variables in tests.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Command as ValidateTranslationCommand
    participant IO
    participant Exception

    User->>Command: execute()
    alt input/output not initialized
        Command->>Exception: throw RuntimeException
    else input/output initialized
        Command->>IO: io?->error()/warning()
        Command->>IO: proceed with execution
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Poem

A hop, a skip, a null-safe leap,
PHPStan strictness climbs so steep!
With checks for input, output, too—
Our tests now guard what they must do.
Arrays refined, exceptions thrown,
This rabbit’s code is finely honed! 🐇✨


📜 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 7eba781 and 8e9c797.

📒 Files selected for processing (7)
  • phpstan.neon (1 hunks)
  • src/Command/ValidateTranslationCommand.php (4 hunks)
  • src/Validator/AbstractValidator.php (2 hunks)
  • src/Validator/MismatchValidator.php (1 hunks)
  • tests/src/Parser/JsonParserTest.php (1 hunks)
  • tests/src/Parser/PhpParserTest.php (2 hunks)
  • tests/src/Result/ValidationRunTest.php (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/src/Parser/PhpParserTest.php (2)
tests/src/Parser/YamlParserTest.php (1)
  • testExtractKeys (132-141)
tests/src/Parser/XliffParserTest.php (1)
  • testExtractKeys (162-168)
🔇 Additional comments (14)
phpstan.neon (1)

2-2: LGTM! Raising PHPStan to the highest strictness level.

This change increases static analysis to level 8, which enforces the strictest type checking and null safety rules. The coordinated changes in other files show proper preparation for this stricter analysis.

tests/src/Parser/PhpParserTest.php (2)

230-234: Good defensive programming for null safety.

The null check before assertions ensures the test handles cases where extractKeys() returns null, which is consistent with the stricter PHPStan level 8 requirements.


276-282: Consistent null safety pattern applied.

The same defensive null check pattern is properly applied here, maintaining consistency across the test methods.

tests/src/Parser/JsonParserTest.php (1)

268-270: Proper null safety before array operation.

The null check before sort($keys) prevents potential runtime errors if extractKeys() returns null, aligning with PHPStan level 8 requirements.

tests/src/Result/ValidationRunTest.php (2)

266-269: Appropriate null safety for error condition testing.

The null check ensures the test handles cases where statistics might be incomplete due to parser exceptions, which is proper defensive programming for error condition tests.


281-284: Consistent error handling pattern.

The same null safety pattern is correctly applied when testing parsers that return null keys, maintaining robust error condition testing.

src/Validator/MismatchValidator.php (1)

40-42: Improved type annotation accuracy.

The refined PHPDoc correctly reflects that inner array values can be string|null, matching the actual implementation where $value ?? null is assigned on line 56. This improves type safety compliance with PHPStan level 8.

src/Validator/AbstractValidator.php (2)

53-58: LGTM! Proper null-safe operator usage for logger debug call.

The null-safe operator prevents potential errors when the logger is not initialized, which is essential for PHPStan level 8 compliance.


93-99: LGTM! Consistent null-safe operator usage for logger debug call.

This change maintains consistency with other logger calls in the class and properly handles the nullable logger property.

src/Command/ValidateTranslationCommand.php (5)

41-41: LGTM! Correct import for RuntimeException.

The RuntimeException import is properly added to support the new runtime check.


183-183: LGTM! Proper null-safe operator usage for I/O error call.

The null-safe operator prevents potential errors when the I/O interface is not initialized, which is essential for PHPStan level 8 compliance.


195-195: LGTM! Consistent null-safe operator usage for I/O warning call.

This change maintains consistency with other I/O calls and properly handles the nullable SymfonyStyle property.


209-209: LGTM! Consistent null-safe operator usage for I/O error call.

This change maintains consistency with other I/O calls in the class and properly handles the nullable SymfonyStyle property.


214-217: LGTM! Well-implemented runtime check for uninitialized interfaces.

The runtime check ensures both output and input interfaces are properly initialized before creating the Output object. The error message is clear and the exception type is appropriate. This is a good defensive programming practice for PHPStan level 8 compliance.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch phpstan-8

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 generate unit tests to generate unit tests for 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.

@konradmichalik konradmichalik merged commit e4a5bbe into main Jul 24, 2025
26 of 28 checks passed
@konradmichalik konradmichalik deleted the phpstan-8 branch July 28, 2025 17: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