refactor code registration for static analyse

This commit is contained in:
2024-01-13 00:33:03 +03:00
parent b13b998cdd
commit 5e24ef3555
3 changed files with 63 additions and 64 deletions

View File

@@ -8,8 +8,10 @@ use App\Models\UserAttachment;
use App\Notifications\ConsultantRequestStarted;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Storage;
use Illuminate\View\View;
use Livewire\Component;
use Livewire\WithFileUploads;
use Illuminate\Support\Collection;
class RegistrationForm extends Component
{
@@ -27,15 +29,15 @@ class RegistrationForm extends Component
public string $telegramLink = '';
public bool $hasMedicalEducation = false;
public bool|int $hasMedicalEducation = false;
public $certPhotos = [];
public array|Collection $certPhotos = [];
public $tmpCertPhotos = [];
public array $tmpCertPhotos = [];
public string $legalType = 'selfemployed';
protected $rules = [
protected array $rules = [
'medicalEducations.*.title' => 'required|string|min:6',
'medicalEducations.*.date' => 'required|date',
'vkLink' => 'required|url',
@@ -46,7 +48,7 @@ class RegistrationForm extends Component
'tmpCertPhotos.*' => 'image|max:4024',
];
public function mount()
public function mount(): void
{
$this->user = Auth::user();
$consultant_request = $this->user->consultant_request;
@@ -61,17 +63,17 @@ class RegistrationForm extends Component
$photos = $this->user->attachments()->certs()->get();
if ($photos) {
$this->certPhotos = collect($photos);
}
// if ($photos) {
$this->certPhotos = collect($photos);
// }
}
public function render()
public function render(): View
{
return view('livewire.consultant.registration-form');
}
public function addEducation()
public function addEducation(): void
{
$this->validate();
$medicalEducations = $this->medicalEducations;
@@ -91,7 +93,7 @@ class RegistrationForm extends Component
$this->medicalEducations = $medicalEducations;
}
public function remove($index)
public function remove(string $index): void
{
$filteredEducations = array_filter(
$this->medicalEducations,
@@ -104,7 +106,7 @@ class RegistrationForm extends Component
$this->medicalEducations = array_values($filteredEducations);
}
public function save()
public function save(): void
{
$data = [
'user_id' => $this->user->id,
@@ -131,7 +133,7 @@ class RegistrationForm extends Component
$attachmentGroup = 'user_certs';
foreach ($this->tmpCertPhotos as $photo) {
$curCert = $photo->storePublicly('public/'.$attachmentGroup.'/'.$this->user->id);
$curCert = $photo->storePublicly('public/' . $attachmentGroup . '/' . $this->user->id);
$fileData = [
'user_id' => $this->user->id,
'group' => $attachmentGroup,
@@ -142,7 +144,7 @@ class RegistrationForm extends Component
$newFile = UserAttachment::updateOrCreate(
$fileData,
[
'path' => preg_replace("/public\//xi", '/storage/', $curCert),
'path' => preg_replace('/public\//xi', '/storage/', $curCert),
'specs' => json_encode(
[
'ext' => $photo->extension(),
@@ -158,7 +160,7 @@ class RegistrationForm extends Component
$this->user->notify(new ConsultantRequestStarted($consultantEducation));
}
public function deleteImg($id)
public function deleteImg(int $id): void
{
$file = UserAttachment::find($id);
$fileSpecs = json_decode($file->specs, true);

View File

@@ -5,87 +5,84 @@ namespace App\Livewire\Registration;
use App\Actions\Fortify\CreateNewUser;
use App\Rules\MinWords;
use Illuminate\Auth\Events\Registered;
use Illuminate\Http\RedirectResponse;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Password;
// use Laravel\Fortify\Contracts\RegisterResponse;
// use Illuminate\Contracts\Auth\StatefulGuard;
// use App\Models\User;
// use App\Models\UserDetailz;
use Illuminate\Validation\Rule;
use Illuminate\View\View;
use Livewire\Features\SupportRedirects\Redirector;
use Livewire\Component;
// use \Mcamara\LaravelLocalization\Facades\LaravelLocalization;
class Step1 extends Component
{
public $step;
public string $step;
public $first_name;
public string $first_name = '';
public $last_name;
public string $last_name = '';
public $email;
public string $email = '';
public $password;
public string $password = '';
public $password_confirmation;
public string $password_confirmation = '';
public $birthdate;
public string $birthdate;
public $gender = 'male';
public string $gender = 'male';
public $country = 'ru';
public string $country = 'ru';
public $city = 'msk';
public string $city = 'msk';
public $lang = 'ru';
public string $lang = 'ru';
public $weight;
public string $weight = '';
public $height;
public string $height = '';
public $chest_circumference;
public string $chest_circumference = '';
public $waist_circumference;
public string $waist_circumference = '';
public $hip_circumference;
public string $hip_circumference = '';
public $blood_pressure_up;
public string $blood_pressure_up = '';
public $blood_pressure_down;
public string $blood_pressure_down = '';
public $has_hypo = 0;
public int|string $has_hypo = 0;
public $has_hyper = 0;
public int|string $has_hyper = 0;
public $about_alergy;
public string $about_alergy = '';
public $about_taking_pils;
public string $about_taking_pils = '';
public $about_sport_hobbies;
public string $about_sport_hobbies = '';
public $favorite_foods;
public string $favorite_foods = '';
public $unfavorite_foods;
public string $unfavorite_foods = '';
public $additional_info;
public string $additional_info = '';
public function mount($step)
public function mount(string $step): void
{
$this->step = $step;
collect(session()->get('registrationdata', []))
->each(fn ($item, $key) => $this->{$key} = $item);
->each(fn($item, $key) => $this->{$key} = $item);
}
public function render()
public function render(): View
{
return view('livewire.registration.'.$this->step, ['step' => $this->step])
return view('livewire.registration.' . $this->step, ['step' => $this->step])
->extends('layouts.register');
}
public function nextStep()
public function nextStep(): RedirectResponse|Redirector
{
$validatedData = Validator::make(
$this->getValidateData($this->step),
@@ -106,7 +103,7 @@ class Step1 extends Component
);
}
public function skipStep()
public function skipStep(): RedirectResponse|Redirector
{
$validatedData = $this->getValidateData($this->step);
$registrationdata = session()->get('registrationdata', []);
@@ -123,9 +120,9 @@ class Step1 extends Component
);
}
public function goBack()
public function goBack(): RedirectResponse|Redirector
{
$nextStep = 'step'.(int) Str::replaceFirst('step', '', $this->step) - 1;
$nextStep = 'step' . ((int) Str::replaceFirst('step', '', $this->step) - 1);
return redirect()
->route(
@@ -136,7 +133,7 @@ class Step1 extends Component
);
}
public function finishRegistretion()
public function finishRegistretion(): RedirectResponse|Redirector
{
$validatedData = Validator::make(
$this->getValidateData($this->step),
@@ -157,7 +154,7 @@ class Step1 extends Component
return redirect()->route('profile.show', $user->id);
}
private function getValidateRules($key)
private function getValidateRules(string $key): array
{
$rules = [
'step1' => [
@@ -199,7 +196,7 @@ class Step1 extends Component
return $rules[$key];
}
private function getValidateData($key)
private function getValidateData(string $key): array
{
$data = [
'step1' => [
@@ -242,8 +239,8 @@ class Step1 extends Component
return $data[$key];
}
private function getNextStep()
private function getNextStep(): string
{
return 'step'.(int) Str::replaceFirst('step', '', $this->step) + 1;
return 'step' . ((int) Str::replaceFirst('step', '', $this->step) + 1);
}
}

View File

@@ -17,7 +17,7 @@ class RegistrationTest extends TestCase
if (! Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration support is not enabled.');
return;
// return;
}
$response = $this->get('/register');
@@ -30,7 +30,7 @@ class RegistrationTest extends TestCase
if (Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration support is enabled.');
return;
// return;
}
$response = $this->get('/register');
@@ -43,7 +43,7 @@ class RegistrationTest extends TestCase
if (! Features::enabled(Features::registration())) {
$this->markTestSkipped('Registration support is not enabled.');
return;
// return;
}
$response = $this->post('/register', [