Skip to content

Commit

Permalink
Code refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Sam Poyigi <[email protected]>
  • Loading branch information
sampoyigi committed May 19, 2024
1 parent 02e0f0e commit a625cdf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 39 deletions.
30 changes: 15 additions & 15 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,17 @@ public function boot()
$this->defineRoutes();
$this->configureRateLimiting();

Event::listen('igniter.user.register', function (Customer $customer, array $data) {
Event::listen('igniter.user.register', function(Customer $customer, array $data) {
Notifications\CustomerRegisteredNotification::make()->subject($customer)->broadcast();
});

$this->registerAdminUserPanel();

Location::extend(function ($model) {
Location::extend(function($model) {
$model->relation['morphedByMany']['users'] = [User::class, 'name' => 'locationable'];
});

Template::registerHook('endBody', function () {
Template::registerHook('endBody', function() {
return view('igniter.user::_partials.impersonate_banner');
});
}
Expand Down Expand Up @@ -135,7 +135,7 @@ public function registerNavigation(): array
'system' => [
'child' => [
'users' => [
'priority' => 0,
'priority' => 1,
'class' => 'users',
'href' => admin_url('users'),
'title' => lang('igniter.user::default.text_side_menu_user'),
Expand All @@ -148,7 +148,7 @@ public function registerNavigation(): array

public function registerSystemSettings()
{
Settings::registerCallback(function (Settings $manager) {
Settings::registerCallback(function(Settings $manager) {
$manager->registerSettingItems('core', [
'user' => [
'label' => 'lang:igniter.user::default.text_tab_user',
Expand Down Expand Up @@ -211,7 +211,7 @@ public function registerFormWidgets(): array
protected function registerEventGlobalParams()
{
if (class_exists(\Igniter\Automation\Classes\EventManager::class)) {
resolve(\Igniter\Automation\Classes\EventManager::class)->registerCallback(function ($manager) {
resolve(\Igniter\Automation\Classes\EventManager::class)->registerCallback(function($manager) {
$manager->registerGlobalParams([
'customer' => Auth::customer(),
]);
Expand All @@ -221,8 +221,8 @@ protected function registerEventGlobalParams()

protected function registerRequestRebindHandler()
{
$this->app->rebinding('request', function ($app, $request) {
$request->setUserResolver(function () use ($app) {
$this->app->rebinding('request', function($app, $request) {
$request->setUserResolver(function() use ($app) {
if (!Igniter::runningInAdmin()) {
return $app['admin.auth']->getUser();
}
Expand All @@ -234,7 +234,7 @@ protected function registerRequestRebindHandler()

protected function configureRateLimiting()
{
RateLimiter::for('web', function (\Illuminate\Http\Request $request) {
RateLimiter::for('web', function(\Illuminate\Http\Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->getKey() ?: $request->ip());
});

Expand All @@ -245,7 +245,7 @@ protected function configureRateLimiting()
$this->app->make(\Illuminate\Contracts\Http\Kernel::class)
->appendMiddlewareToGroup('web', \Igniter\User\Http\Middleware\ThrottleRequests::class);

Event::listen('igniter.user.beforeThrottleRequest', function ($request, $params) {
Event::listen('igniter.user.beforeThrottleRequest', function($request, $params) {
$handler = str_after($request->header('x-igniter-request-handler'), '::');
if (in_array($handler, [
'onLogin',
Expand All @@ -264,18 +264,18 @@ protected function configureRateLimiting()

protected function registerBladeDirectives()
{
$this->callAfterResolving('blade.compiler', function ($compiler, $app) {
$this->callAfterResolving('blade.compiler', function($compiler, $app) {
(new BladeExtension())->register();
});
}

protected function registerGuards(): void
{
$this->app->singleton('main.auth', function () {
$this->app->singleton('main.auth', function() {
return resolve('auth')->guard(config('igniter-auth.guards.web', 'web'));
});

$this->app->singleton('admin.auth', function () {
$this->app->singleton('admin.auth', function() {
return resolve('auth')->guard(config('igniter-auth.guards.admin', 'web'));
});
}
Expand All @@ -286,7 +286,7 @@ protected function registerAdminUserPanel()
return;
}

AdminMenu::registerCallback(function (Navigation $manager) {
AdminMenu::registerCallback(function(Navigation $manager) {
$manager->registerMainItems([
MainMenuItem::widget('notifications', \Igniter\User\MainMenuWidgets\NotificationList::class)
->priority(15)
Expand Down Expand Up @@ -320,7 +320,7 @@ protected function defineRoutes()
return;
}

Route::group([], function ($router) {
Route::group([], function($router) {
(new Classes\RouteRegistrar($router))->all();
});
}
Expand Down
40 changes: 16 additions & 24 deletions src/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getCustomerName()

public function listAddresses()
{
return $this->addresses()->get()->groupBy(function ($address) {
return $this->addresses()->get()->groupBy(function($address) {
return $address->getKey();
});
}
Expand Down Expand Up @@ -228,32 +228,24 @@ public function deleteCustomerAddress(string|int $addressId)
*/
public function saveCustomerGuestOrder()
{
$query = false;

if (is_numeric($this->customer_id) && !empty($this->email)) {
$customer_id = $this->customer_id;
$customer_email = $this->email;
$update = ['customer_id' => $customer_id];

Order::where('email', $customer_email)->update($update);
if ($orders = Order::where('email', $customer_email)->get()) {
foreach ($orders as $row) {
if (empty($row['order_id'])) {
continue;
}

if ($row['order_type'] == '1' && !empty($row['address_id'])) {
Address::where('address_id', $row['address_id'])->update($update);
}
}
}
$update = ['customer_id' => $this->customer_id];

Reservation::where('email', $customer_email)->update($update);
Reservation::where('email', $this->email)
->whereNull('customer_id')
->orWhere('customer_id', 0)
->update($update);

$query = true;
}
Order::where('email', $this->email)
->whereNull('customer_id')
->orWhere('customer_id', 0)
->update($update);

Address::whereIn('address_id', Order::where('email', $this->email)

Check failure on line 243 in src/Models/Customer.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Access to an undefined property Igniter\User\Models\Customer::$email.

Check failure on line 243 in src/Models/Customer.php

View workflow job for this annotation

GitHub Actions / PHP 8.2 - Static Analysis

Call to an undefined static method Igniter\User\Models\Address::whereIn().

Check failure on line 243 in src/Models/Customer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Access to an undefined property Igniter\User\Models\Customer::$email.

Check failure on line 243 in src/Models/Customer.php

View workflow job for this annotation

GitHub Actions / PHP 8.3 - Static Analysis

Call to an undefined static method Igniter\User\Models\Address::whereIn().
->whereNotNull('address_id')
->pluck('address_id')->all()
)->update($update);

return $query;
return true;
}

protected function sendInviteGetTemplateCode(): string
Expand Down

0 comments on commit a625cdf

Please sign in to comment.