Skip to content

Conversation

@TatevikGr
Copy link
Contributor

@TatevikGr TatevikGr commented Nov 8, 2025

"

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced invalid email detection and tracking during CSV imports, now recording invalid email errors in import statistics for better visibility.
  • Refactor

    • Improved internal CSV import workflow and service organization.
"

Thanks for contributing to phpList!

@coderabbitai
Copy link

coderabbitai bot commented Nov 8, 2025

📝 Walkthrough

Walkthrough

This pull request refactors CSV import services by renaming classes and methods for semantic clarity. CsvImporter becomes CsvToDtoImporter, CsvRowToDtoMapper becomes ArrayToDtoMapper, and the import() method becomes parseAndValidate(). Additional invalid_email stat tracking is introduced in the subscriber import flow.

Changes

Cohort / File(s) Summary
Service configuration
config/services/mappers.yml
Updated service declarations: CsvRowToDtoMapperArrayToDtoMapper and CsvImporterCsvToDtoImporter with autowire/autoconfigure preserved.
Domain services
src/Domain/Subscription/Service/ArrayToDtoMapper.php, src/Domain/Subscription/Service/CsvToDtoImporter.php
Renamed mapper class from CsvRowToDtoMapper to ArrayToDtoMapper; renamed importer class from CsvImporter to CsvToDtoImporter with updated constructor dependency and method renamed from import() to parseAndValidate().
Service consumer
src/Domain/Subscription/Service/SubscriberCsvImporter.php
Updated constructor parameter from CsvImporter to CsvToDtoImporter, property renamed accordingly, method calls changed from import() to parseAndValidate(), and added invalid_email stat tracking for skipped rows with invalid email addresses.
Tests
tests/Unit/Domain/Subscription/Service/SubscriberCsvImporterTest.php
Updated mock type from CsvImporter to CsvToDtoImporter, method expectations changed from import() to parseAndValidate(), and constructor parameter names aligned with new API.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

  • Changes follow a consistent, homogeneous refactoring pattern (class/method renames applied uniformly across multiple files)
  • Verify that all call sites are updated to use parseAndValidate() instead of import()
  • Confirm the new invalid_email stat tracking in SubscriberCsvImporter properly increments and records error messages as intended
  • Ensure test expectations align with the renamed method and updated dependency injection

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Rename classes/functions' is vague and generic, using non-descriptive terms that don't convey the specific changes being made. Consider a more specific title like 'Rename CSV mappers and importer classes for clarity' that describes what's actually being renamed and why.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev

Comment @coderabbitai help to get the list of available commands and usage tips.

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

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 033aa54 and 1dbb679.

📒 Files selected for processing (5)
  • config/services/mappers.yml (1 hunks)
  • src/Domain/Subscription/Service/ArrayToDtoMapper.php (1 hunks)
  • src/Domain/Subscription/Service/CsvToDtoImporter.php (2 hunks)
  • src/Domain/Subscription/Service/SubscriberCsvImporter.php (7 hunks)
  • tests/Unit/Domain/Subscription/Service/SubscriberCsvImporterTest.php (10 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/Domain/**

⚙️ CodeRabbit configuration file

src/Domain/**: You are reviewing PHP domain-layer code. Enforce strict domain purity:

  • ❌ Do not allow infrastructure persistence side effects here.
  • Flag ANY usage of Doctrine persistence APIs, especially:
  • $entityManager->flush(...), $this->entityManager->flush(...)
  • $em->persist(...), $em->remove(...)
  • direct transaction control ($em->beginTransaction(), commit(), rollback())
  • If found, request moving these calls to application-layer Command handlers or background Jobs.
  • Also flag repositories in Domain that invoke flush/transactional logic; Domain repositories should be abstractions without side effects.
  • Encourage domain events/outbox or return-values to signal write-intent, leaving orchestration to Commands/Jobs.

Files:

  • src/Domain/Subscription/Service/ArrayToDtoMapper.php
  • src/Domain/Subscription/Service/CsvToDtoImporter.php
  • src/Domain/Subscription/Service/SubscriberCsvImporter.php
🧬 Code graph analysis (3)
src/Domain/Subscription/Service/CsvToDtoImporter.php (2)
src/Domain/Subscription/Service/SubscriberCsvImporter.php (1)
  • __construct (47-67)
src/Domain/Subscription/Service/ArrayToDtoMapper.php (1)
  • ArrayToDtoMapper (9-52)
src/Domain/Subscription/Service/SubscriberCsvImporter.php (1)
src/Domain/Subscription/Service/CsvToDtoImporter.php (2)
  • CsvToDtoImporter (14-62)
  • parseAndValidate (28-61)
tests/Unit/Domain/Subscription/Service/SubscriberCsvImporterTest.php (1)
src/Domain/Subscription/Service/CsvToDtoImporter.php (1)
  • CsvToDtoImporter (14-62)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: phpList on PHP 8.1 [Build, Test]
  • GitHub Check: phpList on PHP 8.1 [Build, Test]
🔇 Additional comments (11)
src/Domain/Subscription/Service/ArrayToDtoMapper.php (1)

9-9: LGTM! Clean semantic rename.

The rename from CsvRowToDtoMapper to ArrayToDtoMapper better reflects that this mapper works with generic arrays rather than being tightly coupled to CSV-specific concepts. The implementation remains unchanged and continues to handle the mapping logic correctly.

config/services/mappers.yml (1)

7-13: LGTM! Service configuration properly updated.

The service definitions have been correctly updated to reference the renamed classes while preserving all autowiring and autoconfiguration settings.

src/Domain/Subscription/Service/CsvToDtoImporter.php (3)

14-14: LGTM! Better semantic clarity.

The rename to CsvToDtoImporter more explicitly conveys that this class transforms CSV data into DTOs, making the codebase more self-documenting.


17-17: LGTM! Dependency updated consistently.

The constructor parameter type correctly reflects the ArrayToDtoMapper rename, maintaining consistency across the refactoring.


28-28: LGTM! Method name is more descriptive.

Renaming import() to parseAndValidate() better describes what this method actually does—it parses CSV data and validates DTOs without performing any persistence. This improves code readability and sets clearer expectations for callers.

tests/Unit/Domain/Subscription/Service/SubscriberCsvImporterTest.php (2)

15-15: LGTM! Tests properly updated for API changes.

The test imports, mock declarations, and constructor invocations have been correctly updated to use CsvToDtoImporter instead of CsvImporter, maintaining test coverage for the renamed classes.

Also applies to: 32-32, 42-42, 51-51


111-111: LGTM! Method expectations consistently updated.

All mock method expectations have been updated from import to parseAndValidate, ensuring the tests align with the new public API surface.

Also applies to: 176-176, 247-247, 312-312, 372-372, 432-432

src/Domain/Subscription/Service/SubscriberCsvImporter.php (4)

41-41: LGTM! Dependency properly updated.

The property, constructor parameter, and assignment have been correctly updated from CsvImporter to CsvToDtoImporter, maintaining consistency with the class rename.

Also applies to: 52-52, 62-62


84-84: LGTM! Stats array extended for invalid email tracking.

The addition of invalid_email to the stats array initialization properly supports the new tracking requirement.


96-96: LGTM! Method call updated consistently.

The call correctly uses the renamed parseAndValidate() method, maintaining alignment with the CsvToDtoImporter API.


251-252: LGTM! Invalid email tracking implemented.

When skipInvalidEmail is enabled, the code now properly increments the invalid_email counter and records a translated error message, providing better visibility into data quality issues during import.

Comment on lines +26 to +31
* Handles full subscriber import workflow, including DB transactions and message dispatching.
*
* Note: Although this lives in the Service namespace, it acts as an *application service* —
* it orchestrates multiple domain services and manages transactions/flushes directly.
* This is an intentional exception for this complex import use case.
*
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Domain layer purity concern: persistence operations in Domain.

While the docblock acknowledges this service uses transactions and flush() calls, the coding guidelines for src/Domain/** are strict: domain-layer code should not contain infrastructure persistence side effects like $entityManager->flush(), beginTransaction(), commit(), or rollback().

The guidelines recommend moving transaction orchestration and flush operations to application-layer Command handlers or background Jobs, with the Domain layer signaling write-intent via domain events, outbox patterns, or return values.

Consider refactoring this as an application-layer service that coordinates Domain services, rather than housing transaction management within the Domain namespace.

As per coding guidelines

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.

3 participants