Skip to content

feat: add SchemaValidator and integrate it into XliffParser#4

Merged
konradmichalik merged 2 commits intomainfrom
schema-validator
Jun 25, 2025
Merged

feat: add SchemaValidator and integrate it into XliffParser#4
konradmichalik merged 2 commits intomainfrom
schema-validator

Conversation

@konradmichalik
Copy link
Copy Markdown
Contributor

@konradmichalik konradmichalik commented Jun 25, 2025

Summary by CodeRabbit

  • New Features

    • Introduced a new SchemaValidator for validating XML schema compliance of translation files.
  • Documentation

    • Updated the README to improve validator listings and added a new section with testing instructions.
  • Chores

    • Updated PHP and Symfony package requirements for compatibility and added new required PHP extensions.
    • Added a development dependency for composer in the test application.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Jun 25, 2025

Walkthrough

This update introduces a new SchemaValidator class for validating XML schema compliance of translation files. The validator is registered in the XliffParser's list of available validators. Documentation in the README is updated to reflect these changes and provide new testing instructions. Dependency requirements are updated in composer.json files.

Changes

File(s) Change Summary
README.md Updated validator names, added SchemaValidator, and introduced a new "Testing" section.
composer.json Increased PHP version requirement, added/ext-libxml, updated Symfony dependencies.
src/Parser/XliffParser.php Registered SchemaValidator in the static getValidators() method.
src/Validator/SchemaValidator.php Added new SchemaValidator class implementing XML schema validation logic for translation files.
tests/Build/app/composer.json Added require-dev section with composer/composer as a development dependency.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ConsoleApp
    participant SchemaValidator
    participant XliffParser
    participant FileDetector

    User->>ConsoleApp: Run validation command
    ConsoleApp->>SchemaValidator: validate(fileDetector, parserClass, files)
    loop For each file
        SchemaValidator->>XliffParser: Instantiate parser (dynamic)
        SchemaValidator->>FileDetector: Detect and load file
        SchemaValidator->>SchemaValidator: Validate XML schema
        alt Errors found
            SchemaValidator->>ConsoleApp: Output warning and error table
        else No errors
            SchemaValidator->>ConsoleApp: Output success checkmark
        end
    end
    SchemaValidator-->>ConsoleApp: Return validation result
Loading

Possibly related PRs

Poem

🐇
A schema validator hops in with glee,
Checking XML files for all to see.
With new docs and tests, dependencies tight,
Our translations are now just right!
The console cheers, the warnings clear—
Hooray for code that’s crystal clear!


📜 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 80fa0c1 and efe260f.

📒 Files selected for processing (1)
  • src/Validator/SchemaValidator.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/Validator/SchemaValidator.php
✨ 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
Copy Markdown

@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: 1

🔭 Outside diff range comments (1)
src/Parser/XliffParser.php (1)

66-71: Fix the return type annotation to match actual return types.

The method now returns validators of different types, but the return type annotation is too restrictive.

Apply this diff to fix the type annotation:

-    /**
-     * @return array<int, class-string<MismatchValidator>>
-     */
+    /**
+     * @return array<int, class-string<ValidatorInterface>>
+     */

You'll also need to add the import for ValidatorInterface:

+use MoveElevator\ComposerTranslationValidator\Validator\ValidatorInterface;
🧹 Nitpick comments (2)
src/Validator/SchemaValidator.php (2)

29-34: Consider clarifying the @throws annotation.

The @throws \ReflectionException annotation is present, but it's not immediately clear where this exception could be thrown from this method directly.

If the exception comes from ParserUtility::resolveParserClass() or the dynamic class instantiation on line 45, consider making this more explicit in the documentation.


77-81: Consider making the error message cleanup more robust.

The regular expression for cleaning XML element prefixes from error messages could be fragile with different XML namespaces or error message formats.

Consider adding fallback handling or making the regex more flexible:

                     $message = preg_replace(
                         "/^Element ('(?:\{[^}]+\})?[^']+'):?\s*/",
                         '',
                         $error['message']
-                    );
+                    ) ?: $error['message']; // Fallback to original message if regex fails
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ffd901d and 80fa0c1.

📒 Files selected for processing (5)
  • README.md (2 hunks)
  • composer.json (1 hunks)
  • src/Parser/XliffParser.php (2 hunks)
  • src/Validator/SchemaValidator.php (1 hunks)
  • tests/Build/app/composer.json (1 hunks)
🧰 Additional context used
🪛 PHPStan (2.1.15)
src/Parser/XliffParser.php

70-70: Method MoveElevator\ComposerTranslationValidator\Parser\XliffParser::getValidators() should return array<int, class-string<MoveElevator\ComposerTranslationValidator\Validator\MismatchValidator>> but returns array<int, string>.

(return.type)

🔇 Additional comments (9)
tests/Build/app/composer.json (1)

5-7: LGTM! Development dependency addition is well-justified.

The addition of composer/composer as a development dependency aligns with the new testing instructions in the README and uses an appropriate version constraint.

composer.json (2)

14-22: Dependency updates properly support the new SchemaValidator functionality.

The changes are well-justified:

  • PHP 8.1 requirement is appropriate for modern development
  • ext-libxml is needed for XML schema validation
  • New Symfony packages (config, translation) support the SchemaValidator implementation
  • Version constraints are consistent across Symfony dependencies

30-30: Good cleanup of duplicate dependency.

Removing symfony/translation from require-dev makes sense since it's now in the main requirements.

README.md (2)

12-14: Documentation improvements enhance clarity and completeness.

Good formatting fixes by removing .php extensions and properly documenting the new SchemaValidator.


31-38: Testing section provides valuable user guidance.

The new testing instructions complement the development dependency changes and give users a clear way to verify functionality.

src/Parser/XliffParser.php (1)

9-9: Import addition is correct.

The new import for SchemaValidator is properly placed and follows the existing import pattern.

src/Validator/SchemaValidator.php (3)

18-27: Well-structured validator class with proper dependency injection.

The constructor properly initializes dependencies and the SymfonyStyle instance for consistent console output.


69-90: Excellent error reporting implementation.

The table-based error display with proper styling and column formatting provides clear, actionable feedback to users.


96-111: Good use of debug output with appropriate verbosity controls.

The debug output implementation properly respects verbosity levels and provides useful feedback during validation.

@konradmichalik konradmichalik merged commit 436d363 into main Jun 25, 2025
1 check passed
@konradmichalik konradmichalik deleted the schema-validator branch June 28, 2025 09:16
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