Skip to content
This repository has been archived by the owner on Feb 4, 2024. It is now read-only.

Commit

Permalink
Improve code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
curtisdelicata committed Sep 19, 2023
1 parent 09d1b89 commit 8ab1569
Show file tree
Hide file tree
Showing 85 changed files with 315 additions and 323 deletions.
9 changes: 0 additions & 9 deletions app/Broadcasting/Notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,6 @@

class Notification
{
/**
* Create a new channel instance.
*
* @return void
*/
public function __construct()
{
}

/**
* Authenticate the user's access to the channel.
*
Expand Down
2 changes: 0 additions & 2 deletions app/Console/Commands/SyncWithGeneanum.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ class SyncWithGeneanum extends Command

/**
* Execute the console command.
*
* @return int
*/
public function handle(): int
{
Expand Down
6 changes: 2 additions & 4 deletions app/Events/MessageSent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,8 @@ public function __construct(Message $message, User $user, public $conversation)

/**
* Determine if this event should broadcast.
*
* @return bool
*/
public function broadcastWhen()
public function broadcastWhen(): bool
{
// return $this->conversation->status == 1;
return true;
Expand Down Expand Up @@ -65,7 +63,7 @@ public function broadcastOn()
return new PrivateChannel('chat');
}

public function broadcastAs()
public function broadcastAs(): string
{
return 'MessageSent';
}
Expand Down
4 changes: 1 addition & 3 deletions app/Events/ServerCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,8 @@ public function broadcastOn()

/**
* The event's broadcast name.
*
* @return string
*/
public function broadcastAs()
public function broadcastAs(): string
{
return 'TestEvent';
}
Expand Down
51 changes: 23 additions & 28 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@

class LoginController extends Controller
{
/**
* @var mixed
*/
public $maxAttempts;
use AuthenticatesUsers, Logout, Login {
Logout::logout insteadof AuthenticatesUsers;
Login::login insteadof AuthenticatesUsers;
Expand Down Expand Up @@ -196,13 +200,13 @@ public function providerLogin(Request $request, $provider)

public function confirmSubscription(Request $request)
{
$params = $request->all();
$request->all();
$user = $this->loggableUser($request);

return response()->json($user);
}

protected function attemptLogin(Request $request)
protected function attemptLogin(Request $request): bool
{
$this->user = $this->loggableUser($request);

Expand Down Expand Up @@ -296,11 +300,6 @@ private function create_company($user)
* ]);.
*/
$company_id = $company->id;
$user_id = $user->id;
$person_name = $user->person->name;
$user_email = $user->email;

$db = $company_id;
// \Log::debug('CreateDBs----------------------'.$company);
CreateDBs::dispatch($company);
// \Log::debug('Migration----------------------'.$company);
Expand Down Expand Up @@ -354,33 +353,29 @@ private function loggableUser(Request $request)
// if (($main_company == null||$tenants=='') && ! $user->isAdmin()) {
// if ($main_company == null) {
$this->create_company($user);
} else {
if ($tenants && ! $user->isAdmin()) {
// $c = DB::connection('tenantdb',$tenants->tenancy_db_name)->table('users')->count();
$company = \App\Models\Company::find($main_company->id);
// \Log::debug('Database----------------------'.$main_company->id);

tenancy()->initialize($tenants);
$tenants->run(function () use ($company, $user) {
// $company->save();
$c = User::count();
if ($c === 0) {
// \Log::debug('Run Migration----------------------');
return Migration::dispatch($company, $user->name, $user->email, $user->password);
}
// \Log::debug($company->id.-'users----------------------'.$c);
});
tenancy()->end();

return $user;
}
} elseif ($tenants && ! $user->isAdmin()) {
// $c = DB::connection('tenantdb',$tenants->tenancy_db_name)->table('users')->count();
$company = \App\Models\Company::find($main_company->id);
// \Log::debug('Database----------------------'.$main_company->id);
tenancy()->initialize($tenants);
$tenants->run(function () use ($company, $user) {
// $company->save();
$c = User::count();
if ($c === 0) {
// \Log::debug('Run Migration----------------------');
return Migration::dispatch($company, $user->name, $user->email, $user->password);
}
// \Log::debug($company->id.-'users----------------------'.$c);
});
tenancy()->end();
return $user;
}
}

return $user;
}

private function loggableSocialUser($user)
private function loggableSocialUser($user): bool
{
$company = $user->person->company();
$tenant = false;
Expand Down
69 changes: 34 additions & 35 deletions app/Http/Controllers/Auth/VerificationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,46 +28,45 @@ public function __construct()
*/
public function verify_user(Request $request)
{
$token = null;
$activation = null;
$user_id = null;
$user = null;
$data = $request->all();
$this->validator($data)->validate();
try {
$token = $request->get('token');
$activation = Activation::where('token', $token)->first();
if ($activation === null) {
return response()->json(
[
'error' => [
'code' => 300,
'message' => 'Send activation code again.',
],
$token = $request->get('token');
$activation = Activation::where('token', $token)->first();
if ($activation === null) {
return response()->json(
[
'error' => [
'code' => 300,
'message' => 'Send activation code again.',
],
Response::HTTP_UNPROCESSABLE_ENTITY
);
}
$user_id = $activation->user_id;
$user = User::find($user_id);
if ($user === null) {
return response()->json(
[
'error' => [
'code' => 301,
'message' => 'There is not such user.',
],
],
Response::HTTP_UNPROCESSABLE_ENTITY
);
}
$user_id = $activation->user_id;
$user = User::find($user_id);
if ($user === null) {
return response()->json(
[
'error' => [
'code' => 301,
'message' => 'There is not such user.',
],
Response::HTTP_UNPROCESSABLE_ENTITY
);
}
$user->is_active = 1;
$user->email_verified_at = date('Y-m-d H:i:s');
$user->save();
Activation::where('user_id', $user_id)->delete();

return response()->json([
'csrfToken' => csrf_token(),
]);
} catch (\Exception $e) {
throw $e;
],
Response::HTTP_UNPROCESSABLE_ENTITY
);
}
$user->is_active = 1;
$user->email_verified_at = date('Y-m-d H:i:s');
$user->save();
Activation::where('user_id', $user_id)->delete();
return response()->json([
'csrfToken' => csrf_token(),
]);
}

protected function validator(array $data)
Expand Down
10 changes: 5 additions & 5 deletions app/Http/Controllers/Dashboard/ChartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public function pie()
$male = \DB::table('people')->where('sex', 'M')->get()->count();
$female = \DB::table('people')->where('sex', 'F')->get()->count();
$unknown = \DB::table('people')->whereNull('sex')->get()->count();
$sv = \Session::get('db', env('DB_DATABASE'));
\Session::get('db', env('DB_DATABASE'));
$user = Auth::user();
$companies = $user->person->company();
$current_db = \Session::get('companyId');
$user->person->company();
\Session::get('companyId');

// return $current_db;
// return $sv;
Expand Down Expand Up @@ -140,7 +140,7 @@ public function changedb(Request $request)
return json_encode([
'db' => config('database.connections.tenant.database'),
'connection' => $changeConn,
'changedb' => $prevConn === $changeConn ? true : false,
'changedb' => $prevConn === $changeConn,
'familiesjoined' => $familiesjoined,
'peoplesattached' => $peoplesattached,
], JSON_THROW_ON_ERROR);
Expand Down Expand Up @@ -198,7 +198,7 @@ public function changeCompany(Request $request)
return json_encode([
'db' => config('database.connections.tenant.database'),
'connection' => $changeConn,
'changedb' => $prevConn === $changeConn ? true : false,
'changedb' => $prevConn === $changeConn,
'familiesjoined' => $familiesjoined,
'peoplesattached' => $peoplesattached,
], JSON_THROW_ON_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Families/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public function __invoke(Request $request)
return $this->getDabolvilleFormat();
}

public function getDabolvilleFormat()
public function getDabolvilleFormat(): string
{
//1 Progenitor - $husband married $woman $year $location
//1.1 Child - $husband married $woman $year $location
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Gedcom/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __invoke(Request $request): Response
]);
$slug = $request->slug;
$file = $request->file('file');
\Log::info(json_encode($request->user()->company()));
\Log::info(json_encode($request->user()->company(), JSON_THROW_ON_ERROR));
$manager = Manager::fromModel($request->user()->company(), $request->user());
$path = $manager->storage()->putFile('imports', $file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function searchPerson(Request $request)
],
]);

$statusCode = $response->getStatusCode();
$content = $response->getBody();
$response->getStatusCode();
$response->getBody();
$persons = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);

return response()->json($persons);
Expand Down
15 changes: 6 additions & 9 deletions app/Http/Controllers/Geneanum/GeneanumController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class GeneanumController extends Controller
{
public function burials(Request $request)
{
$authCode = $request->authcode;
$client = new \GuzzleHttp\Client();

$URI = 'https://static.geneanum.com/libs/grid/malte_sepulture.php';
Expand All @@ -24,16 +23,15 @@ public function burials(Request $request)
],
]);

$statusCode = $response->getStatusCode();
$content = $response->getBody();
$response->getStatusCode();
$response->getBody();
$persons = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);

return response()->json($persons);
}

public function baptism(Request $request)
{
$authCode = $request->authcode;
$client = new \GuzzleHttp\Client();
$URI = 'https://static.geneanum.com/libs/grid/malte_bapteme.php';

Expand All @@ -47,16 +45,15 @@ public function baptism(Request $request)
],
]);

$statusCode = $response->getStatusCode();
$content = $response->getBody();
$response->getStatusCode();
$response->getBody();
$persons = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);

return response()->json($persons);
}

public function mariage(Request $request)
{
$authCode = $request->authcode;
$client = new \GuzzleHttp\Client();

$URI = 'https://static.geneanum.com/libs/grid/malte_mariage.php';
Expand All @@ -73,8 +70,8 @@ public function mariage(Request $request)
],
]);

$statusCode = $response->getStatusCode();
$content = $response->getBody();
$response->getStatusCode();
$response->getBody();
$persons = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);

return response()->json($persons);
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/GrampsXml/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ public function export(Request $request)

foreach ($children as $child) {
$per = $this->getPersonDetail($child);
array_push($childrenArr, $per);
$childrenArr[] = $per;
}

array_push($data, [
$data[] = [
'id' => $familyId,
'description' => $description,
'husband' => $husband,
'wife' => $wife,
'child' => $childrenArr,
]);
];
}

return XML::export(['family' => $data])->rootTag('database')
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/GrampsXml/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function import(Request $request)
// remove temp file after importing
Storage::delete('files/temp/'.$fileName);

if (count($errors) > 0) {
if ($errors !== []) {
return ['errors' => $errors];
}

Expand All @@ -78,7 +78,7 @@ protected function fileToJson($request)
{
$fileName = 'temp'.uniqid().'.xml';

$file = $request->file('file')->storeAs('/files/temp', $fileName);
$request->file('file')->storeAs('/files/temp', $fileName);

$xmlDataString = file_get_contents(storage_path('app/files/temp/'.$fileName));
$xmlObject = simplexml_load_string($xmlDataString);
Expand Down
4 changes: 2 additions & 2 deletions app/Http/Controllers/NationalArch/NationalArchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ public function searchPerson(Request $request)
],
]);

$statusCode = $response->getStatusCode();
$content = $response->getBody();
$response->getStatusCode();
$response->getBody();
$persons = json_decode($response->getBody(), true, 512, JSON_THROW_ON_ERROR);

return response()->json($persons);
Expand Down
Loading

0 comments on commit 8ab1569

Please sign in to comment.