Skip to content

Commit

Permalink
Inline many variables.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot committed Oct 31, 2024
1 parent aa7fa16 commit 1ec224f
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 79 deletions.
4 changes: 1 addition & 3 deletions app/Actions/Proxy/StartProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@ public function handle(Server $server, bool $async = true, bool $force = false):
}

if ($async) {
$activity = remote_process($commands, $server, callEventOnFinish: 'ProxyStarted', callEventData: $server);

return $activity;
return remote_process($commands, $server, callEventOnFinish: 'ProxyStarted', callEventData: $server);
} else {
instant_remote_process($commands, $server);
$server->proxy->set('status', 'running');
Expand Down
4 changes: 1 addition & 3 deletions app/Actions/Server/RunCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class RunCommand

public function handle(Server $server, $command)
{
$activity = remote_process(command: [$command], server: $server, ignore_errors: true, type: ActivityTypes::COMMAND->value);

return $activity;
return remote_process(command: [$command], server: $server, ignore_errors: true, type: ActivityTypes::COMMAND->value);
}
}
3 changes: 1 addition & 2 deletions app/Actions/Service/StartService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public function handle(Service $service)
$commands[] = "docker network connect --alias {$serviceName}-{$service->uuid} $network {$serviceName}-{$service->uuid} >/dev/null 2>&1 || true";
}
}
$activity = remote_process($commands, $service->server, type_uuid: $service->uuid, callEventOnFinish: 'ServiceStatusChanged');

return $activity;
return remote_process($commands, $service->server, type_uuid: $service->uuid, callEventOnFinish: 'ServiceStatusChanged');
}
}
3 changes: 1 addition & 2 deletions app/Http/Controllers/Api/ApplicationsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1691,9 +1691,8 @@ public function envs(Request $request)
'standalone_postgresql_id',
'standalone_redis_id',
]);
$env = $this->removeSensitiveData($env);

return $env;
return $this->removeSensitiveData($env);
});

return response()->json($envs);
Expand Down
3 changes: 1 addition & 2 deletions app/Http/Controllers/Api/ServicesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -566,9 +566,8 @@ public function envs(Request $request)
'standalone_postgresql_id',
'standalone_redis_id',
]);
$env = $this->removeSensitiveData($env);

return $env;
return $this->removeSensitiveData($env);
});

return response()->json($envs);
Expand Down
8 changes: 2 additions & 6 deletions app/Jobs/ScheduledTaskJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,9 @@ public function __construct($task)
private function getServerTimezone(): string
{
if ($this->resource instanceof Application) {
$timezone = $this->resource->destination->server->settings->server_timezone;

return $timezone;
return $this->resource->destination->server->settings->server_timezone;
} elseif ($this->resource instanceof Service) {
$timezone = $this->resource->server->settings->server_timezone;

return $timezone;
return $this->resource->server->settings->server_timezone;
}

return 'UTC';
Expand Down
3 changes: 1 addition & 2 deletions app/Livewire/Project/Database/BackupExecutions.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,8 @@ public function getServerTimezone()
if (! $server) {
return 'UTC';
}
$serverTimezone = $server->settings->server_timezone;

return $serverTimezone;
return $server->settings->server_timezone;
}

public function formatDateInServerTimezone($date)
Expand Down
3 changes: 1 addition & 2 deletions app/Livewire/Project/Shared/ScheduledTask/Executions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ public function getServerTimezone()
if (! $server) {
return 'UTC';
}
$serverTimezone = $server->settings->server_timezone;

return $serverTimezone;
return $server->settings->server_timezone;
}

public function formatDateInServerTimezone($date)
Expand Down
12 changes: 3 additions & 9 deletions app/Models/ScheduledTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,15 @@ public function server()
{
if ($this->application) {
if ($this->application->destination && $this->application->destination->server) {
$server = $this->application->destination->server;

return $server;
return $this->application->destination->server;
}
} elseif ($this->service) {
if ($this->service->destination && $this->service->destination->server) {
$server = $this->service->destination->server;

return $server;
return $this->service->destination->server;
}
} elseif ($this->database) {
if ($this->database->destination && $this->database->destination->server) {
$server = $this->database->destination->server;

return $server;
return $this->database->destination->server;
}
}

Expand Down
13 changes: 4 additions & 9 deletions app/Models/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,10 @@ public function getCpuMetrics(int $mins = 5)
throw new \Exception($error);
}
$cpu = json_decode($cpu, true);
$parsedCollection = collect($cpu)->map(function ($metric) {

return collect($cpu)->map(function ($metric) {
return [(int) $metric['time'], (float) $metric['percent']];
});

return $parsedCollection;
}
}

Expand Down Expand Up @@ -837,9 +836,7 @@ public function user(): Attribute
{
return Attribute::make(
get: function ($value) {
$sanitizedValue = preg_replace('/[^A-Za-z0-9\-_]/', '', $value);

return $sanitizedValue;
return preg_replace('/[^A-Za-z0-9\-_]/', '', $value);
}
);
}
Expand Down Expand Up @@ -1096,9 +1093,7 @@ public function validateConnection(bool $isManualCheck = true, bool $justCheckin

public function installDocker()
{
$activity = InstallDocker::run($this);

return $activity;
return InstallDocker::run($this);
}

public function validateDockerEngine($throwError = false)
Expand Down
4 changes: 1 addition & 3 deletions app/Models/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -1307,9 +1307,7 @@ public function parse(bool $isNew = false): Collection

public function networks()
{
$networks = getTopLevelNetworks($this);

return $networks;
return getTopLevelNetworks($this);
}

protected function isDeployable(): Attribute
Expand Down
7 changes: 2 additions & 5 deletions app/Models/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ public function getRecepients($notification)
{
$recipients = data_get($notification, 'emails', null);
if (is_null($recipients)) {
$recipients = $this->members()->pluck('email')->toArray();

return $recipients;
return $this->members()->pluck('email')->toArray();
}

return explode(',', $recipients);
Expand Down Expand Up @@ -251,9 +249,8 @@ public function sources()
$sources = collect([]);
$github_apps = $this->hasMany(GithubApp::class)->whereisPublic(false)->get();
$gitlab_apps = $this->hasMany(GitlabApp::class)->whereisPublic(false)->get();
$sources = $sources->merge($github_apps)->merge($gitlab_apps);

return $sources;
return $sources->merge($github_apps)->merge($gitlab_apps);
}

public function s3s()
Expand Down
4 changes: 1 addition & 3 deletions app/Notifications/Application/StatusChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ public function toMail(): MailMessage

public function toDiscord(): DiscordMessage
{
$message = new DiscordMessage(
return new DiscordMessage(
title: ':cross_mark: Application stopped',
description: '[Open Application in Coolify]('.$this->resource_url.')',
color: DiscordMessage::errorColor(),
isCritical: true,
);

return $message;
}

public function toTelegram(): array
Expand Down
4 changes: 1 addition & 3 deletions bootstrap/helpers/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function invalidTokenResponse()
function serializeApiResponse($data)
{
if ($data instanceof Collection) {
$data = $data->map(function ($d) {
return $data->map(function ($d) {
$d = collect($d)->sortKeys();
$created_at = data_get($d, 'created_at');
$updated_at = data_get($d, 'updated_at');
Expand Down Expand Up @@ -49,8 +49,6 @@ function serializeApiResponse($data)

return $d;
});

return $data;
} else {
$d = collect($data)->sortKeys();
$created_at = data_get($d, 'created_at');
Expand Down
6 changes: 2 additions & 4 deletions bootstrap/helpers/docker.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ function getCurrentApplicationContainerStatus(Server $server, int $id, ?int $pul

return null;
});
$containers = $containers->filter();

return $containers;
return $containers->filter();
}

return $containers;
Expand All @@ -46,9 +45,8 @@ function getCurrentServiceContainerStatus(Server $server, int $id): Collection
if (! $server->isSwarm()) {
$containers = instant_remote_process(["docker ps -a --filter='label=coolify.serviceId={$id}' --format '{{json .}}' "], $server);
$containers = format_docker_command_output_to_json($containers);
$containers = $containers->filter();

return $containers;
return $containers->filter();
}

return $containers;
Expand Down
5 changes: 2 additions & 3 deletions bootstrap/helpers/github.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,13 @@ function generate_github_jwt_token(GithubApp $source)
$tokenBuilder = (new Builder(new JoseEncoder, ChainedFormatter::default()));
$now = CarbonImmutable::now();
$now = $now->setTime($now->format('H'), $now->format('i'));
$issuedToken = $tokenBuilder

return $tokenBuilder
->issuedBy($source->app_id)
->issuedAt($now->modify('-1 minute'))
->expiresAt($now->modify('+10 minutes'))
->getToken($algorithm, $signingKey)
->toString();

return $issuedToken;
}

function githubApi(GithubApp|GitlabApp|null $source, string $endpoint, string $method = 'get', ?array $data = null, bool $throwError = true)
Expand Down
5 changes: 2 additions & 3 deletions bootstrap/helpers/proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ function collectProxyDockerNetworksByServer(Server $server)
return collect();
}
$networks = instant_remote_process(['docker inspect --format="{{json .NetworkSettings.Networks }}" coolify-proxy'], $server, false);
$networks = collect($networks)->map(function ($network) {

return collect($networks)->map(function ($network) {
return collect(json_decode($network))->keys();
})->flatten()->unique();

return $networks;
}
function collectDockerNetworksByServer(Server $server)
{
Expand Down
5 changes: 1 addition & 4 deletions bootstrap/helpers/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,5 @@ function updateCompose(ServiceApplication|ServiceDatabase $resource)
}
function serviceKeys()
{
$services = get_service_templates();
$serviceKeys = $services->keys();

return $serviceKeys;
return get_service_templates()->keys();
}
12 changes: 4 additions & 8 deletions bootstrap/helpers/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -501,9 +501,8 @@ function generateFqdn(Server $server, string $random, bool $forceHttps = false):
if ($forceHttps) {
$scheme = 'https';
}
$finalFqdn = "$scheme://{$random}.$host$path";

return $finalFqdn;
return "$scheme://{$random}.$host$path";
}
function sslip(Server $server)
{
Expand Down Expand Up @@ -653,19 +652,17 @@ function generateTagDeployWebhook($tag_name)
$baseUrl = base_url();
$api = Url::fromString($baseUrl).'/api/v1';
$endpoint = "/deploy?tag=$tag_name";
$url = $api.$endpoint;

return $url;
return $api.$endpoint;
}
function generateDeployWebhook($resource)
{
$baseUrl = base_url();
$api = Url::fromString($baseUrl).'/api/v1';
$endpoint = '/deploy';
$uuid = data_get($resource, 'uuid');
$url = $api.$endpoint."?uuid=$uuid&force=false";

return $url;
return $api.$endpoint."?uuid=$uuid&force=false";
}
function generateGitManualWebhook($resource, $type)
{
Expand All @@ -674,9 +671,8 @@ function generateGitManualWebhook($resource, $type)
}
if ($resource->getMorphClass() === \App\Models\Application::class) {
$baseUrl = base_url();
$api = Url::fromString($baseUrl)."/webhooks/source/$type/events/manual";

return $api;
return Url::fromString($baseUrl)."/webhooks/source/$type/events/manual";
}

return null;
Expand Down
5 changes: 2 additions & 3 deletions bootstrap/helpers/subscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,11 @@ function getStripeCustomerPortalSession(Team $team)
if (! $stripe_customer_id) {
return null;
}
$session = \Stripe\BillingPortal\Session::create([

return \Stripe\BillingPortal\Session::create([
'customer' => $stripe_customer_id,
'return_url' => $return_url,
]);

return $session;
}
function allowedPathsForUnsubscribedAccounts()
{
Expand Down

0 comments on commit 1ec224f

Please sign in to comment.