style: improve code formatting and readability across multiple files#28
style: improve code formatting and readability across multiple files#28konradmichalik merged 1 commit intomainfrom
Conversation
WalkthroughThis update refactors several classes across the codebase, focusing on formatting, code style, and minor logic simplifications. Method signatures are reformatted for readability, some control flow is streamlined, and repetitive logic is centralized. No core logic or error handling is altered; all modifications are non-functional and aimed at improving maintainability. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant ValidateTranslationCommand
participant Collector
participant ClassUtility
User->>ValidateTranslationCommand: Execute command with options
ValidateTranslationCommand->>Collector: collectFiles(paths, detector, excludePatterns)
Collector-->>ValidateTranslationCommand: List of files
ValidateTranslationCommand->>ClassUtility: validateClassInput(interface, type, className)
ClassUtility-->>ValidateTranslationCommand: Array of class instances
ValidateTranslationCommand->>ValidateTranslationCommand: resolveValidators(input, config)
ValidateTranslationCommand-->>User: Outputs validation results
Possibly related PRs
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 0
🔭 Outside diff range comments (2)
src/FileDetector/Collector.php (1)
31-35: Possible null-logger dereference
$this->loggeris nullable yet accessed without the null-safe operator, which will trigger a fatal error when no logger is provided.- $this->logger->error('The provided path "'.$path.'" is not a valid directory.'); + $this->logger?->error('The provided path "'.$path.'" is not a valid directory.');Apply the same guard to the
debugcall on line 58, or enforce a non-null logger in the constructor.src/Command/ValidateTranslationCommand.php (1)
282-305: Whitespace in comma-separated class lists can break validationWhen users pass
--only "FooValidator, BarValidator"the second entry includes a leading space (" BarValidator"), causingclass_existsto fail.Add
trim()to each exploded segment and ignore empty strings.- $classNames = str_contains($className, ',') ? explode(',', $className) : [$className]; + $classNames = array_filter( + array_map( + 'trim', + str_contains($className, ',') ? explode(',', $className) : [$className] + ) + );
🧹 Nitpick comments (4)
src/Parser/YamlParser.php (1)
81-85: Regex too restrictive for locale codes
/\.(\w{2})\./matches only two-character language tags (e.g. “de”), rejecting common variants likeen_USorfr-CA. Consider broadening the pattern:-if (preg_match( - '/\.(\w{2})\./', +if (preg_match( + '/\.([a-z]{2}(?:[_-][A-Z]{2})?)\./',This still captures the primary language in
$matches[1]while allowing optional region parts.src/FileDetector/Collector.php (1)
48-54: Nestedarray_filterhard to readConsider extracting the exclusion check into a named function/closure for clarity or using
array_diffwith a pre-built “to-exclude” list.src/Result/ValidationResultCliRenderer.php (1)
211-216: Trailing comma requires PHP ≥ 8.0The trailing comma after
$isVerbose = falseis valid only from PHP 8.0 upwards.
Ensure yourcomposer.json(orplatform.php) already requires PHP 8.0+; otherwise this will be a syntax error on older runtimes.src/Command/ValidateTranslationCommand.php (1)
295-301: Instantiation purely for validation is heavy
ClassUtility::instantiate()actually creates an object even though you throw the result away.
If you only need validation, callClassUtility::validateClass()instead to avoid unnecessary object construction and side-effects (e.g. expensive constructors).This is optional but recommended.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (13)
src/Command/ValidateTranslationCommand.php(5 hunks)src/Config/ConfigFactory.php(1 hunks)src/FileDetector/Collector.php(2 hunks)src/Parser/AbstractParser.php(1 hunks)src/Parser/ParserRegistry.php(1 hunks)src/Parser/XliffParser.php(2 hunks)src/Parser/YamlParser.php(2 hunks)src/Result/AbstractValidationResultRenderer.php(1 hunks)src/Result/ValidationResultCliRenderer.php(3 hunks)src/Utility/ClassUtility.php(2 hunks)src/Validator/AbstractValidator.php(4 hunks)src/Validator/DuplicateKeysValidator.php(2 hunks)src/Validator/DuplicateValuesValidator.php(1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (9)
src/Parser/AbstractParser.php (2)
src/Parser/XliffParser.php (1)
getSupportedFileExtensions(62-65)src/Parser/YamlParser.php (1)
getSupportedFileExtensions(74-77)
src/Result/AbstractValidationResultRenderer.php (2)
src/Result/ValidationResult.php (1)
getOverallResult(52-55)src/Validator/ResultType.php (1)
resolveErrorToCommandExitCode(25-36)
src/Parser/XliffParser.php (2)
src/Parser/AbstractParser.php (1)
getFileName(32-35)src/Parser/ParserInterface.php (1)
getFileName(23-23)
src/Parser/YamlParser.php (1)
src/Parser/AbstractParser.php (1)
getFileName(32-35)
src/Config/ConfigFactory.php (1)
src/Config/TranslationValidatorConfig.php (1)
TranslationValidatorConfig(7-266)
src/Parser/ParserRegistry.php (4)
src/Parser/AbstractParser.php (1)
getSupportedFileExtensions(50-50)src/Parser/XliffParser.php (1)
getSupportedFileExtensions(62-65)src/Parser/YamlParser.php (1)
getSupportedFileExtensions(74-77)src/Parser/ParserInterface.php (1)
getSupportedFileExtensions(14-14)
src/Validator/DuplicateKeysValidator.php (1)
src/Parser/AbstractParser.php (1)
getFileName(32-35)
src/Command/ValidateTranslationCommand.php (4)
src/FileDetector/Collector.php (2)
Collector(11-78)collectFiles(25-77)src/Config/TranslationValidatorConfig.php (5)
TranslationValidatorConfig(7-266)only(131-136)getOnly(151-154)skip(156-161)getSkip(176-179)src/Validator/ValidatorRegistry.php (2)
ValidatorRegistry(7-21)getAvailableValidators(12-20)src/Utility/ClassUtility.php (2)
ClassUtility(9-68)instantiate(11-35)
src/FileDetector/Collector.php (4)
src/Parser/AbstractParser.php (1)
getSupportedFileExtensions(50-50)src/Parser/XliffParser.php (1)
getSupportedFileExtensions(62-65)src/Parser/YamlParser.php (1)
getSupportedFileExtensions(74-77)src/Parser/ParserInterface.php (1)
getSupportedFileExtensions(14-14)
🔇 Additional comments (30)
src/Parser/ParserRegistry.php (3)
25-28: LGTM: Improved method signature readability.The multiline formatting with trailing comma enhances readability and follows modern PHP formatting conventions.
34-38: LGTM: Consistent multiline formatting for in_array call.The multiline formatting improves readability by making each parameter clearly visible and aligns with the formatting style used throughout the codebase.
43-45: LGTM: Improved logger call formatting.The multiline formatting enhances readability of the warning message construction.
src/Config/ConfigFactory.php (2)
30-33: LGTM: Clean refactoring that improves maintainability.The extraction of configuration logic into a dedicated method is a good improvement that reduces code duplication.
35-59: Excellent refactoring that centralizes configuration logic.The new
applyConfigurationSettingsmethod effectively eliminates repetitive code by using a mapping approach. This makes the code more maintainable and easier to extend when adding new configuration options.The mapping array clearly shows all supported configuration keys and their corresponding setter methods, improving code readability and reducing the chance of errors.
src/Utility/ClassUtility.php (4)
11-16: LGTM: Improved method signature readability.The multiline parameter formatting with trailing comma enhances readability and follows modern PHP conventions.
23-28: LGTM: Better formatting for sprintf call.The multiline formatting makes the sprintf parameters more readable, especially with multiple interpolation values.
37-41: LGTM: Consistent multiline parameter formatting.The method signature formatting aligns with the style used in the
instantiatemethod above.
47-61: LGTM: Improved readability of error logging.The multiline formatting for both sprintf calls makes the error messages more readable and maintains consistency with the formatting style used throughout the file.
src/Parser/XliffParser.php (2)
14-15: LGTM: Improved docblock formatting.The multiline exception annotation improves readability by providing better visual separation of the exception description.
69-73: LGTM: Consistent multiline formatting for preg_match call.The multiline formatting makes the regex pattern and function parameters more readable and aligns with the formatting style used throughout the codebase.
src/Parser/AbstractParser.php (1)
21-25: LGTM: Consistent multiline formatting for in_array call.The multiline formatting improves readability by making each parameter clearly visible and maintains consistency with the formatting style used in other parser classes like
ParserRegistry.php.src/Result/AbstractValidationResultRenderer.php (1)
129-131: Formatting change looks goodSplitting the chained call across two lines improves readability without affecting behaviour.
src/Parser/YamlParser.php (1)
30-33: PHP version compatibility confirmed
The project’s composer.json specifies PHP ^8.1, so trailing commas in closures are fully supported—no changes required.src/Validator/DuplicateValuesValidator.php (1)
73-75: Message split is purely cosmetic – looks finesrc/Validator/DuplicateKeysValidator.php (3)
21-23: Good use of multi-line logging call
28-31: Readable callback refactor approved
50-51: String concatenation split improves claritysrc/Result/ValidationResultCliRenderer.php (2)
57-60: Readability improved – no functional impact observedThe reformatted multi-line condition is clearer and keeps the early-exit logic intact.
No additional concerns.
235-238: Guard condition reformatted correctlyVisual style change only; behaviour stays the same. Looks good.
src/Validator/AbstractValidator.php (6)
44-50: Parser resolution split across lines – OKPure formatting; call signature unchanged and still lazy-resolves the parser class.
No issues.
56-58: Minor string-concatenation style changeLogging message is unchanged semantically; nothing to flag.
76-82: Verbose file-level debug log – fineOnly style changes. Note that very large projects may produce a lot of output in
--verbose, but that’s outside the scope here.
85-95: Early-continue optimisation acknowledgedSkipping empty validation results avoids needless
Issueobjects – a welcome micro-optimisation.
114-116: Clarifying comment – goodComment clarifies the extension hook; nothing further.
180-181: Use of null-coalescing assignment operator
??=is concise and safe here. Works on PHP 7.4+. No objections.src/Command/ValidateTranslationCommand.php (4)
100-102: Help text wrapped – OKPure documentation change, improves readability.
156-160: MultilinecollectFilescall – OKNo behavioural change; call remains identical.
228-233: Path resolution readable – no functional changeThe multiline
array_mapis fine and still prependsgetcwd()for relative paths.
254-276:matchexpression simplifies branching – looks correctLogic mirrors the previous if/else chain:
--only/ config-only takes precedence--skipfilters from registry- default uses all validators
Edge cases are preserved.
No issues spotted.
Summary by CodeRabbit
Refactor
Style