testing php storm code cleanup and styling

This commit is contained in:
Andras Bacsai
2023-08-08 11:51:36 +02:00
parent a8ee779b31
commit f2228cec7b
368 changed files with 23834 additions and 2623 deletions

View File

@@ -2,28 +2,12 @@
namespace App\Models;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Spatie\Activitylog\Models\Activity;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Masmerise\Toaster\Toastable;
use Masmerise\Toaster\Toaster;
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
use Spatie\Activitylog\Models\Activity;
class Application extends BaseModel
{
protected static function booted()
{
static::created(function ($application) {
ApplicationSetting::create([
'application_id' => $application->id,
]);
});
static::deleting(function ($application) {
$application->settings()->delete();
$application->persistentStorages()->delete();
});
}
protected $fillable = [
'name',
'repository_project_id',
@@ -43,15 +27,42 @@ class Application extends BaseModel
'publish_directory',
'private_key_id'
];
public function type() {
protected static function booted()
{
static::created(function ($application) {
ApplicationSetting::create([
'application_id' => $application->id,
]);
});
static::deleting(function ($application) {
$application->settings()->delete();
$application->persistentStorages()->delete();
});
}
public function settings()
{
return $this->hasOne(ApplicationSetting::class);
}
public function persistentStorages()
{
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
public function type()
{
return 'application';
}
public function publishDirectory(): Attribute
{
return Attribute::make(
set: fn ($value) => $value ? '/' . ltrim($value, '/') : null,
set: fn($value) => $value ? '/' . ltrim($value, '/') : null,
);
}
public function gitBranchLocation(): Attribute
{
return Attribute::make(
@@ -63,6 +74,7 @@ class Application extends BaseModel
);
}
public function gitCommits(): Attribute
{
return Attribute::make(
@@ -73,99 +85,108 @@ class Application extends BaseModel
}
);
}
public function baseDirectory(): Attribute
{
return Attribute::make(
set: fn ($value) => '/' . ltrim($value, '/'),
set: fn($value) => '/' . ltrim($value, '/'),
);
}
public function portsMappings(): Attribute
{
return Attribute::make(
set: fn ($value) => $value === "" ? null : $value,
set: fn($value) => $value === "" ? null : $value,
);
}
// Normal Deployments
public function portsMappingsArray(): Attribute
{
return Attribute::make(
get: fn () =>
is_null($this->ports_mappings)
get: fn() => is_null($this->ports_mappings)
? []
: explode(',', $this->ports_mappings),
);
}
public function portsExposesArray(): Attribute
{
return Attribute::make(
get: fn () =>
is_null($this->ports_exposes)
get: fn() => is_null($this->ports_exposes)
? []
: explode(',', $this->ports_exposes)
);
}
// Normal Deployments
public function environment_variables(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', false);
}
public function runtime_environment_variables(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', false)->where('key', 'not like', 'NIXPACKS_%');
}
// Preview Deployments
public function build_environment_variables(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', false)->where('is_build_time', true)->where('key', 'not like', 'NIXPACKS_%');
}
public function nixpacks_environment_variables(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', false)->where('key', 'like', 'NIXPACKS_%');
}
// Preview Deployments
public function environment_variables_preview(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true);
}
public function runtime_environment_variables_preview(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true)->where('key', 'not like', 'NIXPACKS_%');
}
public function build_environment_variables_preview(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true)->where('is_build_time', true)->where('key', 'not like', 'NIXPACKS_%');
}
public function nixpacks_environment_variables_preview(): HasMany
{
return $this->hasMany(EnvironmentVariable::class)->where('is_preview', true)->where('key', 'like', 'NIXPACKS_%');
}
public function private_key()
{
return $this->belongsTo(PrivateKey::class);
}
public function environment()
{
return $this->belongsTo(Environment::class);
}
public function previews()
{
return $this->hasMany(ApplicationPreview::class);
}
public function settings()
{
return $this->hasOne(ApplicationSetting::class);
}
public function destination()
{
return $this->morphTo();
}
public function source()
{
return $this->morphTo();
}
public function persistentStorages()
{
return $this->morphMany(LocalPersistentVolume::class, 'resource');
}
public function deployments(int $skip = 0, int $take = 10)
{
@@ -177,10 +198,12 @@ class Application extends BaseModel
'deployments' => $deployments
];
}
public function get_deployment(string $deployment_uuid)
{
return Activity::where('subject_id', $this->id)->where('properties->type_uuid', '=', $deployment_uuid)->first();
}
public function isDeployable(): bool
{
if ($this->settings->is_auto_deploy_enabled) {
@@ -188,6 +211,7 @@ class Application extends BaseModel
}
return false;
}
public function isPRDeployable(): bool
{
if ($this->settings->is_preview_deployments_enabled) {
@@ -195,6 +219,7 @@ class Application extends BaseModel
}
return false;
}
public function deploymentType()
{
if (data_get($this, 'private_key_id')) {