refactor(sites): change from multiple servers to single server per site - #88
Conversation
BREAKING CHANGE: SiteDTO.servers property changed from array<string> to string server
WalkthroughThe PR refactors the site domain model from supporting multiple servers to a single server per site. This involves updating the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
app/Repositories/SiteRepository.php (2)
172-180: Consider inlining this single-use method.The
dehydrateSiteDTOmethod 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
dehydrateSiteDTOmethod (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
📒 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.phpapp/Console/Site/SiteAddCommand.phpapp/DTOs/SiteDTO.phpapp/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.
BREAKING CHANGE: SiteDTO.servers property changed from array to string server
Summary by CodeRabbit