Skip to content

refactor(sites): change from multiple servers to single server per site - #88

Merged
loadinglucian merged 1 commit into
mainfrom
refactor/sites-single-server
Nov 16, 2025
Merged

refactor(sites): change from multiple servers to single server per site#88
loadinglucian merged 1 commit into
mainfrom
refactor/sites-single-server

Conversation

@loadinglucian

@loadinglucian loadinglucian commented Nov 16, 2025

Copy link
Copy Markdown
Owner

BREAKING CHANGE: SiteDTO.servers property changed from array to string server

Summary by CodeRabbit

  • Refactor
    • Sites now associate with a single server instead of multiple servers per site
    • Site model updated to handle one server association
    • Site display and detail views adapted for single-server relationship
    • Data storage and retrieval queries updated to reflect new server association structure

BREAKING CHANGE: SiteDTO.servers property changed from array<string> to string server
@coderabbitai

coderabbitai Bot commented Nov 16, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The PR refactors the site domain model from supporting multiple servers to a single server per site. This involves updating the SiteDTO constructor parameter from array $servers to string $server, and propagating this change through the command handler, repository serialization/deserialization logic, and display traits.

Changes

Cohort / File(s) Summary
Core Data Model
app/DTOs/SiteDTO.php
Constructor parameter changed from array $servers to string $server; public property updated from $servers to $server; docblock clarified to reflect single server association.
Site Management Layer
app/Console/Site/SiteAddCommand.php, app/Repositories/SiteRepository.php
SiteAddCommand passes single server string to SiteDTO instead of array; repository's hydrateSiteDTO method reads and passes 'server' (not 'servers') to SiteDTO constructor.
Repository Serialization
app/Repositories/SiteRepository.php
dehydrateSiteDTO serializes to 'server' key instead of 'servers'; findByServer filters using exact equality ($site->server) instead of array membership check.
Display and Traits
app/Traits/SitesTrait.php
Simplified display logic to always set Server field from $site->server directly, removing conditional logic that previously distinguished between single and multiple servers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Changes follow a consistent refactoring pattern across all files (multi-server → single server)
  • No complex logic introduced; primarily parameter and field name updates
  • All four affected files apply the same conceptual change uniformly
  • Repository filtering and serialization changes are straightforward conditional/key replacements

Possibly related PRs

  • refactor: site and server CRUD improvements #60: Implements the identical multi-server-to-single-server refactoring pattern, updating SiteDTO constructor signature and propagating the change through command handlers and repository logic.

Poem

🐰 One server, no more,
Instead of many to explore,
Simpler paths we now adore,
A single hop through every door! 🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: refactoring the sites module to transition from supporting multiple servers to a single server per site, which aligns with all the code modifications shown in the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ 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 refactor/sites-single-server

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/Repositories/SiteRepository.php (2)

172-180: Consider inlining this single-use method.

The dehydrateSiteDTO method is only called once (line 64). Per coding guidelines, single-use methods should be inlined to reduce method call overhead.

As per coding guidelines.

Apply this diff to inline the method:

     public function create(SiteDTO $site): void
     {
         $this->assertInventoryLoaded();
 
         $existing = $this->findByDomain($site->domain);
         if (null !== $existing) {
             throw new \RuntimeException("Site '{$site->domain}' already exists");
         }
 
-        $this->sites[] = $this->dehydrateSiteDTO($site);
+        $this->sites[] = [
+            'domain' => $site->domain,
+            'repo' => $site->repo,
+            'branch' => $site->branch,
+            'server' => $site->server,
+        ];
 
         $this->inventory->set(self::PREFIX, $this->sites);
     }

Then remove the dehydrateSiteDTO method (lines 172-180).


188-200: Consider backward compatibility for existing inventory data.

The hydration method now reads $data['server'] (string), but existing inventory files may still contain $data['servers'] (array) from before this refactor. Sites will silently default to an empty server string, which could cause issues.

Consider adding a migration path:

 private function hydrateSiteDTO(array $data): SiteDTO
 {
     $domain = $data['domain'] ?? '';
     $repo = $data['repo'] ?? '';
     $branch = $data['branch'] ?? '';
-    $server = $data['server'] ?? '';
+    
+    // Support migration from old 'servers' array to new 'server' string
+    $server = '';
+    if (isset($data['server']) && is_string($data['server'])) {
+        $server = $data['server'];
+    } elseif (isset($data['servers']) && is_array($data['servers']) && count($data['servers']) > 0) {
+        // Migrate: take first server from old format
+        $server = is_string($data['servers'][0]) ? $data['servers'][0] : '';
+    }
 
     return new SiteDTO(
         domain: is_string($domain) ? $domain : '',
         repo: is_string($repo) ? $repo : '',
         branch: is_string($branch) ? $branch : '',
         server: is_string($server) ? $server : '',
     );
 }

This would provide a smoother upgrade experience by automatically migrating old data format on read.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4e0c8ed and a8d7ebf.

📒 Files selected for processing (4)
  • app/Console/Site/SiteAddCommand.php (1 hunks)
  • app/DTOs/SiteDTO.php (1 hunks)
  • app/Repositories/SiteRepository.php (2 hunks)
  • app/Traits/SitesTrait.php (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.php

📄 CodeRabbit inference engine (.cursor/rules/00-main.mdc)

**/*.php: Eliminate single-use methods: inline if a method is called only once
Cache computed values: initialize expensive calculations in the constructor
Avoid method call overhead: prefer direct property access when appropriate

Files:

  • app/Traits/SitesTrait.php
  • app/Console/Site/SiteAddCommand.php
  • app/DTOs/SiteDTO.php
  • app/Repositories/SiteRepository.php
🧬 Code graph analysis (1)
app/Repositories/SiteRepository.php (1)
app/DTOs/SiteDTO.php (1)
  • SiteDTO (7-24)
🔇 Additional comments (4)
app/DTOs/SiteDTO.php (1)

10-21: LGTM! Clean refactor from multiple servers to single server.

The DTO has been correctly updated to support a single server string instead of an array. The docblock accurately reflects the change.

app/Traits/SitesTrait.php (1)

118-118: LGTM! Display logic correctly updated for single server.

The site details display has been simplified to show a single server value, which aligns with the refactored SiteDTO structure.

app/Console/Site/SiteAddCommand.php (1)

70-75: LGTM! SiteDTO construction correctly updated.

The command now passes a single server name string to the SiteDTO constructor, consistent with the refactored signature.

app/Repositories/SiteRepository.php (1)

118-118: LGTM! Filter logic correctly updated for single server.

The filtering now uses direct equality comparison instead of in_array, which aligns with the single server model.

@loadinglucian
loadinglucian merged commit f03d2e0 into main Nov 16, 2025
5 checks passed
@loadinglucian
loadinglucian deleted the refactor/sites-single-server branch November 16, 2025 16:22
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