Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/Console/Site/SiteAddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
domain: $domain,
repo: $repo,
branch: $branch,
servers: [$server->name]
server: $server->name
);

$this->displaySiteDeets($site);
Expand Down
6 changes: 3 additions & 3 deletions app/DTOs/SiteDTO.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@
readonly class SiteDTO
{
/**
* Create a SiteDTO containing the site's domain, repository, branch, and associated servers.
* Create a SiteDTO containing the site's domain, repository, branch, and associated server.
*
* @param string $domain The site's domain name (e.g. example.com).
* @param string $repo The repository URL for git sites.
* @param string $branch The repository branch for git sites (e.g. main).
* @param array<int, string> $servers Ordered list of server hostnames or addresses associated with the site.
* @param string $server Server name associated with the site.
*/
public function __construct(
public string $domain,
public string $repo,
public string $branch,
public array $servers,
public string $server,
) {
}
}
12 changes: 6 additions & 6 deletions app/Repositories/SiteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function findByServer(string $serverName): array
$filtered = [];
foreach ($this->sites as $siteData) {
$site = $this->hydrateSiteDTO($siteData);
if (in_array($serverName, $site->servers, true)) {
if ($site->server === $serverName) {
$filtered[] = $site;
}
}
Expand Down Expand Up @@ -167,36 +167,36 @@ private function assertInventoryLoaded(): void
* Serialize a SiteDTO into an associative array suitable for inventory storage.
*
* @param SiteDTO $site The site DTO to serialize.
* @return array<string, mixed> Associative array with keys `domain`, `repo`, `branch`, and `servers`.
* @return array<string, mixed> Associative array with keys `domain`, `repo`, `branch`, and `server`.
*/
private function dehydrateSiteDTO(SiteDTO $site): array
{
return [
'domain' => $site->domain,
'repo' => $site->repo,
'branch' => $site->branch,
'servers' => $site->servers,
'server' => $site->server,
];
}

/**
* Create a SiteDTO from raw inventory data.
*
* @param array<string,mixed> $data Raw associative array from inventory.
* @return SiteDTO A SiteDTO where `domain`, `repo`, and `branch` are strings (empty if missing), and `servers` is an array of strings.
* @return SiteDTO A SiteDTO where `domain`, `repo`, `branch`, and `server` are strings (empty if missing).
*/
private function hydrateSiteDTO(array $data): SiteDTO
{
$domain = $data['domain'] ?? '';
$repo = $data['repo'] ?? '';
$branch = $data['branch'] ?? '';
$servers = $data['servers'] ?? [];
$server = $data['server'] ?? '';

return new SiteDTO(
domain: is_string($domain) ? $domain : '',
repo: is_string($repo) ? $repo : '',
branch: is_string($branch) ? $branch : '',
servers: is_array($servers) ? array_values(array_filter($servers, is_string(...))) : [],
server: is_string($server) ? $server : '',
);
}
}
7 changes: 1 addition & 6 deletions app/Traits/SitesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,9 @@ protected function displaySiteDeets(SiteDTO $site): void
'Source' => 'Git',
'Repo' => $site->repo,
'Branch' => $site->branch,
'Server' => $site->server,
];

if (count($site->servers) > 1) {
$details['Servers'] = $site->servers;
} elseif (count($site->servers) === 1) {
$details['Server'] = $site->servers[0];
}

$this->io->displayDeets($details);
$this->io->writeln('');
}
Expand Down