Lint PHP code psr-12, add GH action

This commit is contained in:
Julien Nahum
2024-02-23 11:54:12 +01:00
parent e85e4df7fe
commit 62971a2ef4
226 changed files with 2338 additions and 2144 deletions

View File

@@ -9,26 +9,31 @@ use App\Models\Traits\CachesAttributes;
use App\Models\User;
use App\Models\Workspace;
use Database\Factories\FormFactory;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
use Stevebauman\Purify\Facades\Purify;
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Casts\Attribute;
class Form extends Model implements CachableAttributes
{
use CachesAttributes;
const DARK_MODE_VALUES = ['auto', 'light', 'dark'];
const THEMES = ['default', 'simple', 'notion'];
const WIDTHS = ['centered', 'full'];
const VISIBILITY = ['public', 'draft', 'closed'];
use HasFactory;
use HasSlug;
use SoftDeletes;
use HasFactory, HasSlug, SoftDeletes;
public const DARK_MODE_VALUES = ['auto', 'light', 'dark'];
public const THEMES = ['default', 'simple', 'notion'];
public const WIDTHS = ['centered', 'full'];
public const VISIBILITY = ['public', 'draft', 'closed'];
protected $fillable = [
'workspace_id',
@@ -94,7 +99,7 @@ class Form extends Model implements CachableAttributes
'password',
// Custom SEO
'seo_meta'
'seo_meta',
];
protected $casts = [
@@ -104,7 +109,7 @@ class Form extends Model implements CachableAttributes
'tags' => 'array',
'removed_properties' => 'array',
'seo_meta' => 'object',
'notification_settings' => 'object'
'notification_settings' => 'object',
];
protected $appends = [
@@ -127,13 +132,13 @@ class Form extends Model implements CachableAttributes
'password',
'tags',
'notification_emails',
'removed_properties'
'removed_properties',
];
protected $cachableAttributes = [
'is_pro',
'views_count',
'max_file_size'
'max_file_size',
];
/**
@@ -155,14 +160,15 @@ class Form extends Model implements CachableAttributes
public function getShareUrlAttribute()
{
if ($this->custom_domain) {
return 'https://' . $this->custom_domain . '/forms/' . $this->slug;
return 'https://'.$this->custom_domain.'/forms/'.$this->slug;
}
return front_url('/forms/' . $this->slug);
return front_url('/forms/'.$this->slug);
}
public function getEditUrlAttribute()
{
return front_url('/forms/' . $this->slug . '/show');
return front_url('/forms/'.$this->slug.'/show');
}
public function getSubmissionsCountAttribute()
@@ -174,9 +180,10 @@ class Form extends Model implements CachableAttributes
{
return $this->remember('views_count', 15 * 60, function (): int {
if (env('DB_CONNECTION') == 'mysql') {
return (int)($this->views()->count() +
return (int) ($this->views()->count() +
$this->statistics()->sum(DB::raw("json_extract(data, '$.views')")));
}
return $this->views()->count() +
$this->statistics()->sum(DB::raw("cast(data->>'views' as integer)"));
});
@@ -204,20 +211,21 @@ class Form extends Model implements CachableAttributes
public function getIsClosedAttribute()
{
return ($this->closes_at && now()->gt($this->closes_at));
return $this->closes_at && now()->gt($this->closes_at);
}
public function getFormPendingSubmissionKeyAttribute()
{
if ($this->updated_at?->timestamp) {
return "openform-" . $this->id . "-pending-submission-" . substr($this->updated_at?->timestamp, -6);
return 'openform-'.$this->id.'-pending-submission-'.substr($this->updated_at?->timestamp, -6);
}
return null;
}
public function getMaxNumberOfSubmissionsReachedAttribute()
{
return ($this->max_submissions_count && $this->max_submissions_count <= $this->submissions_count);
return $this->max_submissions_count && $this->max_submissions_count <= $this->submissions_count;
}
public function setClosedTextAttribute($value)
@@ -232,12 +240,12 @@ class Form extends Model implements CachableAttributes
public function getHasPasswordAttribute()
{
return !empty($this->password);
return ! empty($this->password);
}
public function getMaxFileSizeAttribute()
{
return $this->remember('max_file_size', 15 * 60, function(): int {
return $this->remember('max_file_size', 15 * 60, function (): int {
return $this->workspace->max_file_size;
});
}
@@ -292,7 +300,7 @@ class Form extends Model implements CachableAttributes
return SlugOptions::create()
->doNotGenerateSlugsOnUpdate()
->generateSlugsFrom(function (Form $form) {
return $form->title . ' ' . Str::random(6);
return $form->title.' '.Str::random(6);
})
->saveSlugsTo('slug');
}
@@ -302,19 +310,18 @@ class Form extends Model implements CachableAttributes
return FormFactory::new();
}
public function getNotifiesWebhookAttribute()
{
return !empty($this->webhook_url);
return ! empty($this->webhook_url);
}
public function getNotifiesDiscordAttribute()
{
return !empty($this->discord_webhook_url);
return ! empty($this->discord_webhook_url);
}
public function getNotifiesSlackAttribute()
{
return !empty($this->slack_webhook_url);
return ! empty($this->slack_webhook_url);
}
}