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

@@ -10,10 +10,13 @@ class AiFormCompletion extends Model
{
use HasFactory;
const STATUS_PENDING = 'pending';
const STATUS_PROCESSING = 'processing';
const STATUS_COMPLETED = 'completed';
const STATUS_FAILED = 'failed';
public const STATUS_PENDING = 'pending';
public const STATUS_PROCESSING = 'processing';
public const STATUS_COMPLETED = 'completed';
public const STATUS_FAILED = 'failed';
protected $table = 'ai_form_completions';
@@ -21,11 +24,11 @@ class AiFormCompletion extends Model
'form_prompt',
'status',
'result',
'ip'
'ip',
];
protected $attributes = [
'status' => self::STATUS_PENDING
'status' => self::STATUS_PENDING,
];
protected static function booted()

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);
}
}

View File

@@ -2,20 +2,19 @@
namespace App\Models\Forms;
use App\Models\Forms\Form;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class FormStatistic extends Model
{
use HasFactory;
public $timestamps = false;
protected $fillable = [
'form_id',
'data',
'date'
'date',
];
/**
@@ -34,5 +33,4 @@ class FormStatistic extends Model
{
return $this->belongsTo(Form::class);
}
}

View File

@@ -2,7 +2,6 @@
namespace App\Models\Forms;
use App\Models\Forms\Form;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -11,17 +10,18 @@ class FormSubmission extends Model
use HasFactory;
protected $fillable = [
'data'
'data',
];
protected $casts = [
'data' => 'array'
'data' => 'array',
];
/**
* RelationShips
*/
public function form() {
public function form()
{
return $this->belongsTo(Form::class);
}
}

View File

@@ -2,7 +2,6 @@
namespace App\Models\Forms;
use App\Models\Forms\Form;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
@@ -13,7 +12,8 @@ class FormView extends Model
/**
* RelationShips
*/
public function form() {
public function form()
{
return $this->belongsTo(Form::class);
}
}

View File

@@ -7,11 +7,11 @@ use App\Service\Forms\Webhooks\WebhookHandlerProvider;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\WebhookServer\WebhookCall;
class FormZapierWebhook extends Model
{
use HasFactory, SoftDeletes;
use HasFactory;
use SoftDeletes;
protected $table = 'form_zapier_webhooks';
@@ -28,7 +28,7 @@ class FormZapierWebhook extends Model
return $this->belongsTo(Form::class);
}
public function triggerHook(array $data)
public function triggerHook(array $data)
{
WebhookHandlerProvider::getProvider(
$this->form,

View File

@@ -7,17 +7,17 @@ use Illuminate\Database\Eloquent\Model;
class License extends Model
{
const STATUS_ACTIVE = 'active';
const STATUS_INACTIVE = 'inactive';
use HasFactory;
public const STATUS_ACTIVE = 'active';
public const STATUS_INACTIVE = 'inactive';
protected $fillable = [
'license_key',
'user_id',
'license_provider',
'status',
'meta'
'meta',
];
protected $casts = [

View File

@@ -11,7 +11,8 @@ use Stevebauman\Purify\Facades\Purify;
class Template extends Model
{
use HasFactory, HasSlug;
use HasFactory;
use HasSlug;
protected $fillable = [
'creator_id',
@@ -25,7 +26,7 @@ class Template extends Model
'publicly_listed',
'industries',
'types',
'related_templates'
'related_templates',
];
protected $casts = [
@@ -93,7 +94,8 @@ class Template extends Model
array_values(
json_decode(
file_get_contents(resource_path('data/forms/templates/types.json')),
true)
true
)
)
)->values();
}
@@ -104,7 +106,8 @@ class Template extends Model
array_values(
json_decode(
file_get_contents(resource_path('data/forms/templates/industries.json')),
true)
true
)
)
)->values();
}

View File

@@ -9,9 +9,6 @@ interface CachableAttributes
/**
* Get an item from the cache, or execute the given Closure and store the result.
*
* @param string $key
* @param int|null $ttl
* @param Closure $callback
*
* @return mixed
*/
@@ -20,8 +17,6 @@ interface CachableAttributes
/**
* Get an item from the cache, or execute the given Closure and store the result forever.
*
* @param string $key
* @param \Closure $callback
*
* @return mixed
*/
@@ -29,17 +24,11 @@ interface CachableAttributes
/**
* Remove an item from the cache.
*
* @param string $key
*
* @return bool
*/
public function forget(string $key): bool;
/**
* Remove all items from the cache.
*
* @return bool
*/
public function flush(): bool;
}

View File

@@ -84,7 +84,7 @@ trait CachesAttributes
$this->getTable(),
$this->getKey(),
$attribute,
$this->updated_at?->timestamp ?? '0'
$this->updated_at?->timestamp ?? '0',
]);
}

View File

@@ -7,14 +7,15 @@ use App\Notifications\ResetPassword;
use App\Notifications\VerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Cashier\Billable;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use Notifiable, HasFactory, Billable;
use Billable;
use HasFactory;
use Notifiable;
/**
* The attributes that are mass assignable.
@@ -25,7 +26,7 @@ class User extends Authenticatable implements JWTSubject
'name',
'email',
'password',
'hear_about_us'
'hear_about_us',
];
/**
@@ -36,7 +37,7 @@ class User extends Authenticatable implements JWTSubject
protected $hidden = [
'password',
'remember_token',
'hear_about_us'
'hear_about_us',
];
/**
@@ -59,12 +60,12 @@ class User extends Authenticatable implements JWTSubject
public function ownsForm(Form $form)
{
return $this->workspaces()->where('workspaces.id',$form->workspace_id)->exists();
return $this->workspaces()->where('workspaces.id', $form->workspace_id)->exists();
}
public function ownsWorkspace(Workspace $workspace)
{
return $this->workspaces()->where('workspaces.id',$workspace->id)->exists();
return $this->workspaces()->where('workspaces.id', $workspace->id)->exists();
}
/**
@@ -89,12 +90,12 @@ class User extends Authenticatable implements JWTSubject
{
return $this->subscribed()
|| in_array($this->email, config('opnform.extra_pro_users_emails'))
|| !is_null($this->activeLicense());
|| ! is_null($this->activeLicense());
}
public function getHasCustomerIdAttribute()
{
return !is_null($this->stripe_id);
return ! is_null($this->stripe_id);
}
public function getAdminAttribute()
@@ -121,7 +122,7 @@ class User extends Authenticatable implements JWTSubject
/**
* Send the password reset notification.
*
* @param string $token
* @param string $token
* @return void
*/
public function sendPasswordResetNotification($token)
@@ -136,7 +137,7 @@ class User extends Authenticatable implements JWTSubject
*/
public function sendEmailVerificationNotification()
{
$this->notify(new VerifyEmail);
$this->notify(new VerifyEmail());
}
/**
@@ -144,7 +145,6 @@ class User extends Authenticatable implements JWTSubject
* Relationship
* =================================
*/
public function workspaces()
{
return $this->belongsToMany(Workspace::class);
@@ -246,5 +246,4 @@ class User extends Authenticatable implements JWTSubject
});
});
}
}

View File

@@ -10,11 +10,15 @@ use Illuminate\Database\Eloquent\Model;
class Workspace extends Model implements CachableAttributes
{
use HasFactory, CachesAttributes;
use CachesAttributes;
use HasFactory;
public const MAX_FILE_SIZE_FREE = 5000000; // 5 MB
public const MAX_FILE_SIZE_PRO = 50000000; // 50 MB
public const MAX_DOMAIN_PRO = 1;
const MAX_FILE_SIZE_FREE = 5000000; // 5 MB
const MAX_FILE_SIZE_PRO = 50000000; // 50 MB
const MAX_DOMAIN_PRO = 1;
protected $fillable = [
'name',
'icon',
@@ -24,7 +28,7 @@ class Workspace extends Model implements CachableAttributes
protected $appends = [
'is_pro',
'is_enterprise'
'is_enterprise',
];
protected $casts = [
@@ -37,16 +41,16 @@ class Workspace extends Model implements CachableAttributes
'is_risky',
'submissions_count',
'max_file_size',
'custom_domain_count'
'custom_domain_count',
];
public function getMaxFileSizeAttribute()
{
if(is_null(config('cashier.key'))){
if (is_null(config('cashier.key'))) {
return self::MAX_FILE_SIZE_PRO;
}
return $this->remember('max_file_size', 15 * 60, function(): int {
return $this->remember('max_file_size', 15 * 60, function (): int {
// Return max file size depending on subscription
foreach ($this->owners as $owner) {
if ($owner->is_subscribed) {
@@ -55,6 +59,7 @@ class Workspace extends Model implements CachableAttributes
return $license->max_file_size;
}
}
return self::MAX_FILE_SIZE_PRO;
}
@@ -64,17 +69,18 @@ class Workspace extends Model implements CachableAttributes
public function getCustomDomainCountLimitAttribute()
{
if(is_null(config('cashier.key'))){
if (is_null(config('cashier.key'))) {
return null;
}
return $this->remember('custom_domain_count', 15 * 60, function(): ?int {
return $this->remember('custom_domain_count', 15 * 60, function (): ?int {
foreach ($this->owners as $owner) {
if ($owner->is_subscribed) {
if ($license = $owner->activeLicense()) {
// In case of special License
return $license->custom_domain_limit_count;
}
return self::MAX_DOMAIN_PRO;
}
}
@@ -85,44 +91,46 @@ class Workspace extends Model implements CachableAttributes
public function getIsProAttribute()
{
if(is_null(config('cashier.key'))){
if (is_null(config('cashier.key'))) {
return true; // If no paid plan so TRUE for ALL
}
return $this->remember('is_pro', 15 * 60, function(): bool {
return $this->remember('is_pro', 15 * 60, function (): bool {
// Make sure at least one owner is pro
foreach ($this->owners as $owner) {
if ($owner->is_subscribed) {
return true;
}
}
return false;
});
}
public function getIsEnterpriseAttribute()
{
if(is_null(config('cashier.key'))){
if (is_null(config('cashier.key'))) {
return true; // If no paid plan so TRUE for ALL
}
return $this->remember('is_enterprise', 15 * 60, function(): bool {
return $this->remember('is_enterprise', 15 * 60, function (): bool {
// Make sure at least one owner is pro
foreach ($this->owners as $owner) {
if ($owner->has_enterprise_subscription) {
return true;
}
}
return false;
});
}
public function getIsRiskyAttribute()
{
return $this->remember('is_risky', 15 * 60, function(): bool {
return $this->remember('is_risky', 15 * 60, function (): bool {
// A workspace is risky if all of his users are risky
foreach ($this->owners as $owner) {
if (!$owner->is_risky) {
if (! $owner->is_risky) {
return false;
}
}
@@ -133,7 +141,7 @@ class Workspace extends Model implements CachableAttributes
public function getSubmissionsCountAttribute()
{
return $this->remember('submissions_count', 15 * 60, function(): int {
return $this->remember('submissions_count', 15 * 60, function (): int {
$total = 0;
foreach ($this->forms as $form) {
$total += $form->submissions_count;
@@ -146,7 +154,6 @@ class Workspace extends Model implements CachableAttributes
/**
* Relationships
*/
public function users()
{
return $this->belongsToMany(User::class);