phpcs:pass

This commit is contained in:
Jérémy Munsch 2022-08-11 09:32:24 +02:00
parent f4490e18d7
commit 18f104ae80
No known key found for this signature in database
GPG key ID: 18361AF3BFEC0FEC
65 changed files with 429 additions and 147 deletions

View file

@ -4,14 +4,13 @@ namespace App\Console\Commands;
use Illuminate\Console\Command;
/*
/**
* Command Name: LDC Web Status Checker
* Description: Envoi des infos Serveur/Laravel vers LDC Web
* Version: 1.1
* Author: Vincent BRIDIER
* Author URI: vincent.bridier@ldc.fr
*/
class LdcWebStatusChecker extends Command
{
/**
@ -52,7 +51,7 @@ class LdcWebStatusChecker extends Command
$data['robots'] = 'false';
}
// Check logs
// * Check logs
$data['logs'] = 0;
$patherror = storage_path('/logs');
$files = glob($patherror . '/*.log');
@ -64,7 +63,7 @@ class LdcWebStatusChecker extends Command
$data['code']['version'] = app()->version();
// Send by cURL
// * Send by cURL
$url = 'https://ldc-web.ldc.fr/api/status-checker';
$ch = curl_init($url);
$payload = ['token' => 'CE8S52Qq7stf5k8frF4T', 'datas' => json_encode($data)];

View file

@ -12,9 +12,13 @@ use Kwaadpepper\Enum\BaseEnumRoutable;
* @method static self informations()
* @method static self feedback()
*/
class FileCategory extends BaseEnumRoutable
{
/**
* Enum values
*
* @return array
*/
protected static function values(): array
{
return [
@ -27,6 +31,11 @@ class FileCategory extends BaseEnumRoutable
];
}
/**
* Enum labels
*
* @return array
*/
protected static function labels(): array
{
return [

View file

@ -8,9 +8,13 @@ use Kwaadpepper\Enum\BaseEnumRoutable;
* @method static self stringlink()
* @method static self binfile()
*/
class FileType extends BaseEnumRoutable
{
/**
* Enum values
*
* @return array
*/
protected static function values(): array
{
return [
@ -19,6 +23,11 @@ class FileType extends BaseEnumRoutable
];
}
/**
* Enum labels
*
* @return array
*/
protected static function labels(): array
{
return [

View file

@ -10,9 +10,13 @@ use Kwaadpepper\Enum\BaseEnumRoutable;
* @method static self high()
* @method static self overload()
*/
class LoadLevel extends BaseEnumRoutable
{
/**
* Enum values
*
* @return array
*/
protected static function values(): array
{
return [
@ -23,6 +27,11 @@ class LoadLevel extends BaseEnumRoutable
];
}
/**
* Enum labels
*
* @return array
*/
protected static function labels(): array
{
return [

View file

@ -18,6 +18,11 @@ use Kwaadpepper\Enum\BaseEnumRoutable;
*/
class ActivityType extends BaseEnumRoutable
{
/**
* Enum labels
*
* @return array
*/
public static function labels()
{
return [
@ -30,6 +35,11 @@ class ActivityType extends BaseEnumRoutable
];
}
/**
* Enum colors
*
* @return array
*/
public static function colors(): array
{
return [

View file

@ -20,6 +20,11 @@ use Kwaadpepper\Enum\BaseEnumRoutable;
*/
class CellModel extends BaseEnumRoutable
{
/**
* Enum values
*
* @return array
*/
protected static function values(): array
{
return [
@ -29,6 +34,11 @@ class CellModel extends BaseEnumRoutable
];
}
/**
* Enum labels
*
* @return array
*/
protected static function labels(): array
{
return [

View file

@ -17,6 +17,11 @@ use Kwaadpepper\Enum\BaseEnumRoutable;
*/
class CellType extends BaseEnumRoutable
{
/**
* Enum values
*
* @return array
*/
protected static function values(): array
{
return [
@ -29,6 +34,11 @@ class CellType extends BaseEnumRoutable
];
}
/**
* Enum labels
*
* @return array
*/
protected static function labels(): array
{
return [

View file

@ -18,6 +18,11 @@ use Kwaadpepper\Enum\BaseEnumRoutable;
*/
class TableRow extends BaseEnumRoutable
{
/**
* Enum values
*
* @return array
*/
protected static function values(): array
{
return [
@ -32,6 +37,11 @@ class TableRow extends BaseEnumRoutable
];
}
/**
* Enum labels
*
* @return array
*/
protected static function labels(): array
{
return [

View file

@ -7,12 +7,14 @@ use App\Models\User;
class FileCreated extends Loggable
{
/** @var File */
/** @var \App\Models\File */
public $file;
/**
* Create a new event instance.
*
* @param \App\Models\File $file
* @param \App\Models\User $user
* @return void
*/
public function __construct(File $file, User $user)

View file

@ -11,14 +11,16 @@ abstract class Loggable
use Dispatchable;
use SerializesModels;
/** @var User */
/** @var \App\Models\User */
public $user;
/** @var string */
public $message = '';
/**
* Create a new event instance.
*
* @param \App\Models\User $user
* @return void
*/
public function __construct(User $user)

View file

@ -13,7 +13,7 @@ class NotifyAdmin
use InteractsWithSockets;
use SerializesModels;
/** @var Ticket */
/** @var \App\Models\Ticket */
public $ticket;
/** @var string */
@ -22,6 +22,8 @@ class NotifyAdmin
/**
* Create a new event instance.
*
* @param \App\Models\Ticket $ticket
* @param string $corpsMaj
* @return void
*/
public function __construct(Ticket $ticket, string $corpsMaj)

View file

@ -14,7 +14,7 @@ class NotifySubscriptions
use InteractsWithSockets;
use SerializesModels;
/** @var Ticket */
/** @var \App\Models\Ticket */
public $ticket;
/** @var string */
@ -26,6 +26,9 @@ class NotifySubscriptions
/**
* Create a new event instance.
*
* @param \App\Models\Ticket $ticket
* @param string $corpsMaj
* @param \Illuminate\Support\Collection|null $ignoreUsers
* @return void
*/
public function __construct(Ticket $ticket, string $corpsMaj, Collection $ignoreUsers = null)

View file

@ -13,7 +13,7 @@ class NotifyTicketCreator
use InteractsWithSockets;
use SerializesModels;
/** @var Ticket */
/** @var \App\Models\Ticket */
public $ticket;
/** @var string */
@ -22,6 +22,8 @@ class NotifyTicketCreator
/**
* Create a new event instance.
*
* @param \App\Models\Ticket $ticket
* @param string $corpsMaj
* @return void
*/
public function __construct(Ticket $ticket, string $corpsMaj)

View file

@ -7,12 +7,14 @@ use App\Models\User;
class ProjectUpdated extends Loggable
{
/** @var Project */
/** @var \App\Models\Project */
public $project;
/**
* Create a new event instance.
*
* @param \App\Models\Project $project
* @param \App\Models\User $user
* @return void
*/
public function __construct(Project $project, User $user)

View file

@ -7,12 +7,14 @@ use App\Models\User;
class SiteUpdated extends Loggable
{
/** @var Site */
/** @var \App\Models\Site */
public $site;
/**
* Create a new event instance.
*
* @param \App\Models\Site $site
* @param \App\Models\User $user
* @return void
*/
public function __construct(Site $site, User $user)

View file

@ -2,6 +2,7 @@
namespace App\Events;
use App\Enums\TicketStatus;
use App\Models\Ticket;
use App\Models\User;
use Illuminate\Broadcasting\InteractsWithSockets;
@ -14,12 +15,13 @@ class TicketStatusChanged
use InteractsWithSockets;
use SerializesModels;
/** @var Ticket */
/** @var \App\Models\Site */
public $ticket;
/** @var User */
/** @var \App\Models\User */
public $user;
/** @var \App\Enums\TicketStatus */
public $status;
/** @var string */
@ -28,9 +30,13 @@ class TicketStatusChanged
/**
* Create a new event instance.
*
* @param \App\Models\Ticket $ticket
* @param \App\Enums\TicketStatus $status
* @param \App\Models\User|null $user
* @param string|null $message
* @return void
*/
public function __construct(Ticket $ticket, $status, User $user = null, string $message = null)
public function __construct(Ticket $ticket, TicketStatus $status, User $user = null, string $message = null)
{
$this->ticket = $ticket;
$this->status = $status;

View file

@ -8,16 +8,6 @@ use Illuminate\Foundation\Auth\ConfirmsPasswords;
class ConfirmPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Confirm Password Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password confirmations and
| uses a simple trait to include the behavior. You're free to explore
| this trait and override any functions that require customization.
|
*/
use ConfirmsPasswords;
/**

View file

@ -7,18 +7,13 @@ use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
class ForgotPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset emails and
| includes a trait which assists in sending these notifications from
| your application to your users. Feel free to explore this trait.
|
*/
use SendsPasswordResetEmails;
/**
* ForgotPasswordController
*
* @return void
*/
public function __construct()
{
$this->middleware('guest:web');

View file

@ -8,16 +8,6 @@ use Illuminate\Foundation\Auth\AuthenticatesUsers;
class LoginController extends Controller
{
/*
|--------------------------------------------------------------------------
| Login Controller
|--------------------------------------------------------------------------
|
| This controller handles authenticating users for the application and
| redirecting them to your home screen. The controller uses a trait
| to conveniently provide its functionality to your applications.
|
*/
use AuthenticatesUsers;
/**

View file

@ -9,16 +9,6 @@ use Illuminate\Validation\Rules\Password;
class ResetPasswordController extends Controller
{
/*
|--------------------------------------------------------------------------
| Password Reset Controller
|--------------------------------------------------------------------------
|
| This controller is responsible for handling password reset requests
| and uses a simple trait to include this behavior. You're free to
| explore this trait and override any methods you wish to tweak.
|
*/
use ResetsPasswords;
/**

View file

@ -16,8 +16,19 @@ class LogController extends Controller
/** @var Log */
public static $modelClass = Log::class;
/**
* Crud Layout
*
* @var string
*/
public static $layout = 'layout.app';
/**
* Index query middleware
*
* @param Builder $query
* @return Builder
*/
public function indexQuery(Builder $query): Builder
{
$parent = request()->site ?? request()->project;
@ -29,9 +40,15 @@ class LogController extends Controller
return $query;
}
/**
* Crud index view
*
* @param \Kwaadpepper\CrudPolicies\Http\Requests\CrudIndexRequest $request
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function index(CrudIndexRequest $request)
{
// Autosort
// * Autosort
if (!$request->sort_col and !$request->sort_way) {
$request->merge([
'sort_col' => 'created_at',
@ -47,6 +64,12 @@ class LogController extends Controller
return view('logs.index', $view->getData());
}
/**
* Before store model middleware
*
* @param \App\Models\Log $log
* @return void
*/
public function storeModel(Log &$log)
{
$log->parent()->associate(request()->site ?? request()->project);

View file

@ -13,6 +13,8 @@ use Illuminate\Database\Eloquent\Builder;
/**
* Alternate planner for Dev Team
*
* TODO: Refactor this controller.
*
* @author Olivier Legat <olivier.legat@ldc.fr>
*
*/

View file

@ -402,10 +402,11 @@ class TicketController extends Controller
*/
public function reopen(Ticket $ticket)
{
$message = trans(':ticketName à réouvert le ticket n°:ticketNumber', [
$message = trans(':ticketName à réouvert le ticket n°:ticketNumber', [
'ticketName' => $ticket->user->name,
'ticketNumber' => $ticket->id,
]);
/** @var \App\Enums\TicketStatus */
$oldStatus = $ticket->status;
$ticket->status = TicketStatus::inprogress();
$ticket->saveQuietly();

View file

@ -6,7 +6,6 @@ use App\Http\Controllers\Auth\ForgotPasswordController;
use App\Models\User;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Kwaadpepper\CrudPolicies\Traits\CrudController;
class UserController extends Controller
@ -15,6 +14,9 @@ class UserController extends Controller
__construct as __CrudConstructor;
}
/**
* UserController
*/
public function __construct()
{
parent::__construct();
@ -25,8 +27,19 @@ class UserController extends Controller
/** @var User */
public static $modelClass = User::class;
/**
* Crud Layout
*
* @var string
*/
public static $layout = 'layout.app';
/**
* After store model middleware
*
* @param Model $model
* @return void
*/
public function storedModel(Model &$model)
{
/** @var \App\Models\User */
@ -34,11 +47,21 @@ class UserController extends Controller
$model->sendMailConfirm();
}
/**
* Password reset form
*
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function passwordReset()
{
return view('users.passwordReset');
}
/**
* Password reset submit
*
* @return \Illuminate\Http\RedirectResponse
*/
public function passwordResetSubmit()
{
/** @var \App\Models\User */
@ -47,12 +70,21 @@ class UserController extends Controller
return app(ForgotPasswordController::class)->sendResetLinkEmail($request);
}
/**
* Show stats
*
* TODO: refator this using carbon.
*
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
*/
public function stats()
{
$user = Auth::user();
$stats = [];
/** @var \App\Models\User */
$user = auth()->user();
$stats = [];
$curYear = date('Y');
for ($i = 2021; $i <= date('Y'); $i++) {
for ($i = 2021; $i <= $curYear; $i++) {
$start = $i . '-03-01';
$end = $i + 1 . '-02-' . $this->getLastDayFebruary($i + 1);
@ -68,7 +100,13 @@ class UserController extends Controller
return view('users.stats', ['stats' => array_reverse($stats)]);
}
private function getLastDayFebruary($year)
/**
* Get february last day date of the year
*
* @param integer $year
* @return integer 28 or 29
*/
private function getLastDayFebruary(int $year): int
{
if ((is_int($year / 4) && !is_int($year / 100)) || is_int($year / 400)) {
return 29;

View file

@ -15,7 +15,7 @@ class SetCellContentRequest extends FormRequest
*
* @return boolean
*/
public function authorize()
public function authorize(): bool
{
$this->merge([
'model' => $this->model ?? null,
@ -30,7 +30,7 @@ class SetCellContentRequest extends FormRequest
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
'id' => 'required|exists:week_plannings,id',
@ -52,7 +52,12 @@ class SetCellContentRequest extends FormRequest
];
}
public function attributes()
/**
* Get custom attributes for validator errors.
*
* @return array
*/
public function attributes(): array
{
return [
'cellModel' => 'Type d\'élément lié',

View file

@ -9,22 +9,22 @@ class UpdateMessage extends FormRequest
/**
* Determine if the user is authorized to make this request.
*
* @return bool
* @return boolean
*/
public function authorize()
public function authorize(): bool
{
/** @var \App\Models\User|null $user */
$user = auth()->user();
return auth()->check() && $user->isAdmin();
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
public function rules(): array
{
/** @var \App\Models\User */
$user = auth()->user();

View file

@ -10,12 +10,13 @@ class UserLabeledResource extends ResourceCollection
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @param mixed $request
* @return array
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClass
public function toArray($request)
{
// phpcs:enable
return $this->collection->mapWithKeys(function (User $user, $key) {
return [
$key => [

View file

@ -28,6 +28,7 @@ class AutoCloseOldTickets
})->get();
/** @var \App\Models\Ticket $ticket */
foreach ($tickets as $ticket) {
/** @var \App\Enums\TicketStatus */
$oldStatus = $ticket->status;
$ticket->status = TicketStatus::archived();
$ticket->saveQuietly();

View file

@ -24,6 +24,8 @@ class SendTicketMentionMail implements ShouldQueue
/**
* Create a new job instance.
*
* @param \App\Models\User $user
* @param \App\Mail\TicketMention $mail
* @return void
*/
public function __construct(User $user, TicketMention $mail)

View file

@ -23,6 +23,7 @@ class SendUserCreatedEmail implements ShouldQueue
/**
* Create a new job instance.
*
* @param \App\Models\User $user
* @return void
*/
public function __construct(User $user)

View file

@ -10,7 +10,7 @@ class AddStatusMessages
/**
* Handle the event.
*
* @param TicketStatusChanged $event
* @param \App\Events\TicketStatusChanged $event
* @return void
*/
public function handle(TicketStatusChanged $event)

View file

@ -13,7 +13,7 @@ class HandleLoggable
/**
* Handle the event.
*
* @param Loggable $loggable
* @param \App\Events\Loggable $loggable
* @return void
*/
public function handle(Loggable $loggable)

View file

@ -11,7 +11,7 @@ class SendNotificationMailToAdmin
/**
* Handle the event.
*
* @param NotifyTicketCreator $event
* @param \App\Events\NotifyAdmin $event
* @return void
*/
public function handle(NotifyAdmin $event)

View file

@ -11,7 +11,7 @@ class SendNotificationMailToTicketCreator
/**
* Handle the event.
*
* @param NotifyTicketCreator $event
* @param \App\Events\NotifyTicketCreator $event
* @return void
*/
public function handle(NotifyTicketCreator $event)

View file

@ -13,7 +13,7 @@ class SendSubscriptionsNotificationsMail
/**
* Handle the event.
*
* @param NotifySubscriptions $event
* @param \App\Events\NotifySubscriptions $event
* @return void
*/
public function handle(NotifySubscriptions $event)

View file

@ -2,6 +2,7 @@
namespace App\Mail;
use App\Models\Ticket;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
@ -11,14 +12,16 @@ class NewTicket extends Mailable
use Queueable;
use SerializesModels;
/** @var \App\Models\Ticket */
private $ticket;
/**
* Create a new message instance.
*
* @param \App\Models\Ticket $ticket
* @return void
*/
public function __construct($ticket)
public function __construct(Ticket $ticket)
{
$this->ticket = $ticket;
}

View file

@ -13,7 +13,7 @@ class TicketMention extends Mailable
use Queueable;
use SerializesModels;
/** @var Ticket */
/** @var \App\Models\Ticket */
private $ticket;
/** @var string */
@ -22,6 +22,8 @@ class TicketMention extends Mailable
/**
* Create a new message instance.
*
* @param \App\Models\Ticket $ticket
* @param string $corpsMaj
* @return void
*/
public function __construct(Ticket $ticket, string $corpsMaj)

View file

@ -13,7 +13,7 @@ class TicketUpdate extends Mailable
use Queueable;
use SerializesModels;
/** @var Ticket */
/** @var \App\Models\Ticket */
private $ticket;
/** @var string */
@ -22,6 +22,8 @@ class TicketUpdate extends Mailable
/**
* Create a new message instance.
*
* @param \App\Models\Ticket $ticket
* @param string $corpsMaj
* @return void
*/
public function __construct(Ticket $ticket, string $corpsMaj)

View file

@ -7,11 +7,13 @@ use Illuminate\Mail\Mailable;
class UserCreatedMail extends Mailable
{
/** @var \App\Models\User */
protected $user;
/**
* Create a new message instance.
*
* @param \App\Models\User $user
* @return void
*/
public function __construct(User $user)

View file

@ -18,18 +18,43 @@ class File extends Model
use HasFactory;
use IsCrudModel;
/**
* The attributes that should be cast to Enums.
*
* @var array
*/
protected $enumCasts = [
'category' => FileCategory::class,
'type' => FileType::class
];
/**
* Crud label column
*
* @var string
*/
protected $crudLabelColumn = 'name';
/**
* Crud value column
*
* @var string
*/
protected $crudValueColumn = 'id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['type', 'uri', 'file', 'name', 'category'];
public function __construct($attributes = [])
/**
* File
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
self::$editableProperties = [
'name' => [
@ -119,6 +144,11 @@ class File extends Model
parent::__construct($attributes);
}
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
static::created(function (File $file) {
@ -126,16 +156,33 @@ class File extends Model
});
}
// * RELATIONSHIPS
/**
* MorphTo parent object relation
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function parent()
{
return $this->morphTo();
}
/**
* MorphTo parent object site relation
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function parentSite()
{
return $this->morphTo('parent', 'site');
}
/**
* MorphTo parent object project relation
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function parentProject()
{
return $this->morphTo('parent', 'project');

View file

@ -13,13 +13,33 @@ class Log extends Model
use HasFactory;
use IsCrudModel;
/**
* Crud label column
*
* @var string
*/
protected $crudLabelColumn = 'id';
/**
* Crud value column
*
* @var string
*/
protected $crudValueColumn = 'id';
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['entry'];
public function __construct($attributes = [])
/**
* Log
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
self::$editableProperties = [
'id' => [
@ -54,6 +74,11 @@ class Log extends Model
parent::__construct($attributes);
}
/**
* Perform any actions required after the model boots.
*
* @return void
*/
protected static function booted()
{
static::creating(function (Log $log) {
@ -61,21 +86,43 @@ class Log extends Model
});
}
// * RELATIONSHIPS
/**
* BelongsTo User relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
/**
* MorphTo parent object relation
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function parent()
{
return $this->morphTo();
}
/**
* MorphTo parent object site relation
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function parentSite()
{
return $this->morphTo('parent', 'site');
}
/**
* MorphTo parent object project relation
*
* @return \Illuminate\Database\Eloquent\Relations\MorphTo
*/
public function parentProject()
{
return $this->morphTo('parent', 'project');

View file

@ -14,6 +14,11 @@ class Schedule extends Model
use HasFactory;
use CastsEnums;
/**
* The attributes that should be cast to Enums.
*
* @var array
*/
protected $enumCasts = [
'activity' => ActivityType::class,
'model_lie' => CellModel::class
@ -28,6 +33,11 @@ class Schedule extends Model
'date' => 'date',
];
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'user_id',
'date',
@ -38,28 +48,34 @@ class Schedule extends Model
'model_lie'
];
// * RELATIONSHIPS
/**
* BelongsTo User relation
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function user()
{
return $this->belongsTo(User::class);
}
// relationship to linked objet
/**
* relationship to linked objet
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function relatedModel()
{
switch ($this->model_lie) {
case 'sites':
return $this->belongsTo(Site::class, 'id_lie');
break;
case 'projects':
return $this->belongsTo(Project::class, 'id_lie');
break;
case 'tickets':
return $this->belongsTo(Ticket::class, 'id_lie');
break;
default:
// no model
return new BelongsTo($this->newQuery(), $this, '', '', '');
break;
}
}
}

View file

@ -6,5 +6,10 @@ use Illuminate\Database\Eloquent\Relations\Pivot;
class SiteUser extends Pivot
{
/**
* Indicates if the model should be timestamped.
*
* @var boolean
*/
public $timestamps = false;
}

View file

@ -15,13 +15,14 @@ class AccountPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -15,13 +15,14 @@ class BrandPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -15,10 +15,9 @@ class CreditLogPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{

View file

@ -15,13 +15,14 @@ class EstimationPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassBeforeLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -15,13 +15,14 @@ class FilePolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -15,13 +15,14 @@ class LabelPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -17,10 +17,9 @@ class LogPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{

View file

@ -15,13 +15,14 @@ class MarkerPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -15,13 +15,14 @@ class ProjectPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed, Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -15,7 +15,7 @@ abstract class EstimationStaticRules extends StaticRules
/**
* Estimation is pending
*
* @param Estimation $model
* @param \App\Models\Credit\Estimation $model
* @return boolean
*/
protected static function estimateIsPending(Estimation $model): bool

View file

@ -15,8 +15,8 @@ abstract class LogStaticRules extends StaticRules
/**
* Log Is owned by user.
*
* @param User $user
* @param Log $log
* @param \App\Models\User $user
* @param \App\Models\Log $log
* @return boolean
*/
protected static function logIsOwnedByUser(User $user, Log $log): bool

View file

@ -12,6 +12,13 @@ use Kwaadpepper\CrudPolicies\Policies\Rules\StaticRules;
*/
abstract class SiteStaticRules extends StaticRules
{
/**
* Check if a user can access a ticket
*
* @param \App\Models\User $user
* @param \App\Models\Ticket $ticket
* @return boolean
*/
protected static function userSitesHasTicket(User $user, Ticket $ticket)
{
return $user->sites->contains($ticket->site_id);

View file

@ -15,7 +15,7 @@ abstract class TicketStaticRules extends StaticRules
/**
* Ticket is not in production
*
* @param Ticket $ticket
* @param \App\Models\Ticket $ticket
* @return boolean
*/
protected static function ticketIsNotInProduction(Ticket $ticket): bool
@ -26,7 +26,7 @@ abstract class TicketStaticRules extends StaticRules
/**
* Ticket is not archived
*
* @param Ticket $ticket
* @param \App\Models\Ticket $ticket
* @return boolean
*/
protected static function ticketIsNotArchived(Ticket $ticket): bool
@ -37,7 +37,7 @@ abstract class TicketStaticRules extends StaticRules
/**
* Ticket has brand which has at least one account
*
* @param Ticket $ticket
* @param \App\Models\Ticket $ticket
* @return boolean
*/
protected static function ticketsBrandHasAnAccount(Ticket $ticket): bool
@ -52,7 +52,7 @@ abstract class TicketStaticRules extends StaticRules
/**
* Ticket does already have an estimation
*
* @param Ticket $ticket
* @param \App\Models\Ticket $ticket
* @return boolean
*/
protected static function ticketDoesHaveEstimation(Ticket $ticket): bool
@ -63,7 +63,7 @@ abstract class TicketStaticRules extends StaticRules
/**
* Ticket does not already have an estimation
*
* @param Ticket $ticket
* @param \App\Models\Ticket $ticket
* @return boolean
*/
protected static function ticketDoesntHaveEstimation(Ticket $ticket): bool
@ -74,7 +74,7 @@ abstract class TicketStaticRules extends StaticRules
/**
* Ticket is not internal
*
* @param Ticket $ticket
* @param \App\Models\Ticket $ticket
* @return boolean
*/
protected static function ticketIsNotInternal(Ticket $ticket): bool

View file

@ -15,13 +15,14 @@ class SitePolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -18,8 +18,8 @@ class TicketPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function setPolicies(User $user, Model $model = null)

View file

@ -15,13 +15,14 @@ class UserPolicy extends RootPolicy
/**
* Init policies on call
*
* @param User $user
* @param Model $model
* @param \App\Models\User $user
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
* @phpcs:disable Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
*/
// phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.FoundInExtendedClassAfterLastUsed
public function setPolicies(User $user, Model $model = null)
{
// phpcs:enable
/**
* This first rule to return true in a policy action authorises the action
*/

View file

@ -2,6 +2,7 @@
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\ServiceProvider;
@ -15,10 +16,8 @@ class TranslationServiceProvider extends ServiceProvider
*/
public function boot()
{
$translations = collect();
foreach ($this->collectLocalesStrings() as $locale) {
// suported locales
// * Suported locales
Cache::rememberForever(sprintf('translations.%s', $locale), function () use ($locale) {
$translations = [
'php' => $this->phpTranslations($locale),
@ -29,7 +28,12 @@ class TranslationServiceProvider extends ServiceProvider
}
}
private function collectLocalesStrings()
/**
* Gather provided langs checking from files
*
* @return \Illuminate\Support\Collection
*/
private function collectLocalesStrings(): Collection
{
return collect(File::allFiles(resource_path('lang/')))->flatMap(function ($file) {
if ($file->getRelativePath()) {
@ -38,23 +42,34 @@ class TranslationServiceProvider extends ServiceProvider
})->keys();
}
private function phpTranslations($locale)
/**
* Gather all php translations
*
* @param string $locale
* @return array
*/
private function phpTranslations(string $locale): array
{
$path = resource_path("lang/$locale");
return collect(File::allFiles($path))->flatMap(function ($file) use ($locale) {
$key = ($translation = $file->getBasename('.php'));
return [$key => trans($translation, [], $locale)];
});
$translation = $file->getBasename('.php');
return [$translation => trans($translation, [], $locale)];
})->all();
}
private function jsonTranslations($locale)
/**
* Gather json translations
*
* @param string $locale
* @return array
*/
private function jsonTranslations(string $locale): array
{
$path = resource_path("lang/$locale.json");
if (is_string($path) && is_readable($path)) {
return json_decode(file_get_contents($path), true);
return json_decode(file_get_contents($path), true) ?? [];
}
return [];

View file

@ -15,7 +15,7 @@ return [
'default' => env('MAIL_MAILER', 'smtp'),
// Mail admin
// * Mail admin
'MAIL_ADMIN' => env('MAIL_ADMIN'),
/*

View file

@ -15,6 +15,7 @@ return [
* of your proxy (e.g. if using ELB or similar).
*
*/
'proxies' => '*',
/*
@ -42,6 +43,10 @@ return [
*
* @link https://symfony.com/doc/current/deployment/proxies.html
*/
'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_ALL,
'headers' => Illuminate\Http\Request::HEADER_X_FORWARDED_FOR |
Illuminate\Http\Request::HEADER_X_FORWARDED_HOST |
Illuminate\Http\Request::HEADER_X_FORWARDED_PORT |
Illuminate\Http\Request::HEADER_X_FORWARDED_PROTO,
];

View file

@ -26,8 +26,8 @@ class UserFactory extends Factory
'name' => $this->faker->name,
'email' => $this->faker->unique()->safeEmail,
'email_verified_at' => now(),
// * password
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi',
// password
'remember_token' => Str::random(10),
];
}

View file

@ -13,6 +13,5 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
// \App\Models\User::factory(10)->create();
}
}

View file

@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="LDC Laravel"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<ruleset name="LDC Laravel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
<description>Created with the PHP Coding Standard Generator. http://edorian.github.com/php-coding-standard-generator/</description>
<arg name="colors" />
<arg name="extensions" value="php" />
<file>app/</file>
<file>config/</file>
<file>database/factories</file>
<file>database/seeders</file>
<file>routes/</file>
<file>tests/</file>
<rule ref="PSR1" />
<rule ref="PSR12" />