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

Commit

Permalink
Merge pull request #2378 from laravel-liberu/analysis-54Dajx
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
curtisdelicata committed Jul 12, 2023
2 parents 88e7d2f + c3be889 commit 17236af
Show file tree
Hide file tree
Showing 21 changed files with 117 additions and 123 deletions.
3 changes: 1 addition & 2 deletions app/Events/ServerCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ public function __construct(
* The user that created the server.
*/
public $message
)
{
) {
}

/**
Expand Down
19 changes: 9 additions & 10 deletions app/Http/Controllers/Auth/LoginController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function redirectToProvider($provider)
/**
* Obtain the user information from Provider.
*
* @param $provider
* @param $provider
* @return JsonResponse
*/
public function handleProviderCallback($provider)
Expand Down Expand Up @@ -264,7 +264,7 @@ protected function validateLogin(Request $request)
}

/**
* @param $provider
* @param $provider
* @return JsonResponse
*/
protected function validateProvider($provider)
Expand Down Expand Up @@ -344,17 +344,16 @@ private function loggableUser(Request $request)
if ($main_company !== null && ! $user->isAdmin()) {
$c_id = $main_company->id;
}
if(! $user->isAdmin()){

$tenants = Tenant::find($main_company->id);
}
if ($user->isAdmin()) {
$tenants = null;
}
if (! $user->isAdmin()) {
$tenants = Tenant::find($main_company->id);
}
if ($user->isAdmin()) {
$tenants = null;
}
if ($main_company === null && ! $user->isAdmin()) {
// if (($main_company == null||$tenants=='') && ! $user->isAdmin()) {
// if ($main_company == null) {
$this->create_company($user);
$this->create_company($user);
} else {
if ($tenants && ! $user->isAdmin()) {
// $c = DB::connection('tenantdb',$tenants->tenancy_db_name)->table('users')->count();
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ protected function create(Request $request)
}

/** protected function getSubscriptionPlan(Request $request)
{
return (new GetPlans())($request);
}
**/
* {
* return (new GetPlans())($request);
* }.
**/
}
8 changes: 4 additions & 4 deletions app/Http/Controllers/Dna/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ public function __invoke(Request $request)
$user_id = \Auth::user()->id;
$dna = Dna::where('user_id', '=', $user_id)->count();
if (in_array($role, [1, 2, 9, 10])) {
$allowed = TRUE;
$allowed = true;
}
if (in_array($role, [4, 5, 6]) && $dna < 1) {
$allowed = TRUE;
$allowed = true;
}

if (in_array($role, [7, 8]) && $dna < 5) {
$allowed = TRUE;
$allowed = true;
}
if ($allowed === TRUE) {
if ($allowed === true) {
if ($request->hasFile('file')) {
if ($request->file('file')->isValid()) {
try {
Expand Down
17 changes: 9 additions & 8 deletions app/Http/Controllers/Gedcom/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use App\Http\Controllers\Controller;
use App\Jobs\ExportGedCom;
use FamilyTree365\LaravelGedcom\Utils\GedcomGenerator;
use Illuminate\Http\Request;
use App\Models\Person;
use Illuminate\Support\Facades\Log;
use App\Models\Family;
use App\Models\Person;
use App\Tenant\Manager;
use FamilyTree365\LaravelGedcom\Utils\GedcomGenerator;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Log;

class Export extends Controller
{
public function __invoke(Request $request)
Expand All @@ -19,15 +20,15 @@ public function __invoke(Request $request)
$file = env('APP_NAME').date('_Ymd_').$ts.'.ged';
$file = str_replace(' ', '', $file);
$file = str_replace("'", '', $file);
$filePath = 'public/' . $file;
$filePath = 'public/'.$file;
$manager = Manager::fromModel($request->user()->company(), $request->user());
ExportGedCom::dispatchSync($filePath, $request->user());

$filePath = $manager->storage()->path($filePath);
Log::info("Read gedfile from ". $manager->storage()->path($filePath));
$filePath = $manager->storage()->path($filePath);
Log::info('Read gedfile from '.$manager->storage()->path($filePath));
// var_dump($filePath);
return json_encode([
// 'file' => $manager->storage()->path($filePath) ,
// 'file' => $manager->storage()->path($filePath) ,
'file' => file_get_contents($filePath, true),
'name' => $file,
], JSON_THROW_ON_ERROR);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Person/PeopleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function searchPerson(Request $request)

return response()->json([
'response' => [
'docs' => $people->map(fn($person) => [
'docs' => $people->map(fn ($person) => [
'id' => $person->id,
'name' => $person->name,
'user_name' => $person->systemPerson?->name,
Expand Down
10 changes: 4 additions & 6 deletions app/Http/Controllers/Stripe/GetCurrentSubscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __invoke(Request $request)
$data['has_payment_method'] = $user->hasDefaultPaymentMethod();
if ($user->subscribed('default')) {
$subscription = $user->subscription();

$data['subscribed'] = $subscription->stripe_status != 'canceled' ? true : false;

$data['plan_id'] = $subscription->stripe_price;
Expand All @@ -37,22 +37,20 @@ public function __invoke(Request $request)
try {
$coupon = $stripeSub->discount->coupon;
// check the type of coupon - it can be 'fixed_amount' or 'percent_off'
if($coupon->amount_off) {
if ($coupon->amount_off) {
$discountAmount = $coupon->amount_off;
$finalPrice = $price - $discountAmount;
} else if($coupon->percent_off) {
$discountAmount = ($price * $coupon->percent_off/100);
} elseif ($coupon->percent_off) {
$discountAmount = ($price * $coupon->percent_off / 100);
$finalPrice = $price - $discountAmount;
}
} catch (\Exception $e) {

}

$data['final_price'] = $finalPrice;
$data['discount_amount'] = $discountAmount;
} catch (Exception $e) {
}

} else {
$data['subscribed'] = false;
}
Expand Down
59 changes: 29 additions & 30 deletions app/Http/Controllers/Stripe/GetPlans.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,66 +17,65 @@ class GetPlans extends Controller
public function __invoke(Request $request)
{
// $role = Role::where("name", "free")->first();
Stripe\Stripe::setApiKey(\Config::get("services.stripe.secret"));
Stripe\Stripe::setApiKey(\Config::get('services.stripe.secret'));

$plans = Stripe\Plan::all();

$result = [];
foreach ($plans as $k => $plan) {
if (!$plan->active || $plan->amount == 0) {
if (! $plan->active || $plan->amount == 0) {
continue;
}

/*
* FREE PLAN
*/

/**
if ($k === 0) {
$row1 = [];
$row1["id"] = $role->id;
$row1["amount"] = 0;
$row1["nickname"] = $role->name;
$row1["title"] = $role->display_name;
$row1["subscribed"] = false;
$result[] = $row1;
}
**/
/**
* if ($k === 0) {
* $row1 = [];
* $row1["id"] = $role->id;
* $row1["amount"] = 0;
* $row1["nickname"] = $role->name;
* $row1["title"] = $role->display_name;
* $row1["subscribed"] = false;
* $result[] = $row1;
* }.
**/
if (empty($plan->nickname)) {
continue;
}
$row = [];

$row["id"] = $plan->id;
$row["amount"] = $plan->amount;
$row["title"] = $plan->nickname;
$row["nickname"] = $plan->title;
$row["interval"] = $plan->interval;
$row["trial_end"] = null;
$row['id'] = $plan->id;
$row['amount'] = $plan->amount;
$row['title'] = $plan->nickname;
$row['nickname'] = $plan->title;
$row['interval'] = $plan->interval;
$row['trial_end'] = null;

$row["features"] = [];
$row["features_missing"] = [];
$row["metadata"] = [
"featured" => false,
"description" => "Missing description!!!",
$row['features'] = [];
$row['features_missing'] = [];
$row['metadata'] = [
'featured' => false,
'description' => 'Missing description!!!',
];

foreach ($plan->metadata->toArray() as $key => $value) {
if (preg_match('/^feature-missing[0-9]*$/', $key)) {
$row["features_missing"][] = $value;
$row['features_missing'][] = $value;
}
if (preg_match('/^feature[0-9]*$/', $key)) {
$row["features"][] = $value;
$row['features'][] = $value;
}
if ($key == "featured" && ($value == 1 || $value == "true")) {
$row["metadata"]["featured"] = true;
if ($key == 'featured' && ($value == 1 || $value == 'true')) {
$row['metadata']['featured'] = true;
}
}
$row["subscribed"] = false;
$row['subscribed'] = false;
$result[] = $row;
}

return $result;
}
}

8 changes: 4 additions & 4 deletions app/Http/Controllers/Stripe/VerifyCoupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function __invoke(Request $request)
$user = auth()->user();

try {
$user->createAsStripeCustomer();
$user->createAsStripeCustomer();
} catch(\Exception $e) {
}

Expand All @@ -32,14 +32,14 @@ public function __invoke(Request $request)
if (strtolower($coupon->name) == strtolower($couponCode) && $coupon->valid) {
return [
'success' => true,
'coupon' => $coupon
'coupon' => $coupon,
];
}
};

}
} catch (\Stripe\Exception\InvalidRequestException $e) {
return ['success' => false, 'message' => 'There was an error when checking your coupon.'];
}

return ['success' => false, 'message' => 'Coupon code is not valid'];
}
}
25 changes: 13 additions & 12 deletions app/Http/Controllers/Stripe/Webhook.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php

namespace App\Http\Controllers\Stripe;
use LaravelEnso\Roles\Models\Role;

use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\Request;
use Stripe;
use Illuminate\Support\Facades\Log;
use LaravelEnso\Roles\Models\Role;
use Stripe;

class Webhook extends Controller
{
Expand All @@ -23,42 +24,42 @@ public function __invoke(Request $request)

if ($data) {
switch ($data['type']) {
case "customer.subscription.deleted":
case 'customer.subscription.deleted':
$user = User::where('stripe_id', $data['data']['object']['customer'])->first();
if ($user) {
$user->role_id = 4;
$user->save();
}
break;
case "customer.subscription.created":
case "customer.subscription.updated":

case 'customer.subscription.created':
case 'customer.subscription.updated':
$user = User::where('stripe_id', $data['data']['object']['customer'])->first();
if ($user) {
$plan_nickname = $data['data']['object']['plan']['nickname'];
$roles= Role::where('name', strtolower($plan_nickname))->first();
$roles = Role::where('name', strtolower($plan_nickname))->first();
if ($roles) {
$user->role_id = $roles->id;
$user->save();
}
}
break;
case "invoice.payment_succeeded":

case 'invoice.payment_succeeded':
$user = User::where('stripe_id', $data['data']['object']['customer'])->first();
if ($user) {
$plan_nickname = $data['data']['object']['lines']['data'][0]['plan']['nickname'];
$roles= Role::where('name', strtolower($plan_nickname))->first();
$roles = Role::where('name', strtolower($plan_nickname))->first();
if ($roles) {
$user->role_id = $roles->id;
$user->save();
}
}
break;
case "invoice.payment_failed" :
case 'invoice.payment_failed':
$user = User::where('stripe_id', $data['data']['object']['customer'])->first();
if ($user) {
$roles= Role::where('name', strtolower("free"))->first();
$roles = Role::where('name', strtolower('free'))->first();
if ($roles) {
$user->role_id = $roles->id;
$user->save();
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Trees/Ancestors.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function getGraphData($start_id, $nest = 1)

return true;
}
$own_unions = $families->pluck('id')->map(fn($id) => 'u'.$id)->toArray();
$own_unions = $families->pluck('id')->map(fn ($id) => 'u'.$id)->toArray();
$person->setAttribute('own_unions', $own_unions);
$person['generation'] = $nest;
$this->persons[$start_id] = $person;
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Trees/Show.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ private function getGraphData($start_id, $nest = 1)

return true;
}
$own_unions = $families->pluck('id')->map(fn($id) => 'u'.$id)->toArray();
$own_unions = $families->pluck('id')->map(fn ($id) => 'u'.$id)->toArray();
$person->setAttribute('own_unions', $own_unions);
$person->setAttribute('generation', $nest);

Expand Down

0 comments on commit 17236af

Please sign in to comment.