From 71ab4dc3d876657372708fb1a6730e801a345c75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Lo=CC=88sken?= Date: Thu, 14 Jul 2016 22:37:04 +0200 Subject: [PATCH] Refactor docblocks, unused vars, unused uses --- app/Commands/Command.php | 7 +- .../Commands/ChargeRenewalInvoices.php | 5 +- app/Console/Commands/CheckData.php | 25 +- app/Console/Commands/CreateTestData.php | 14 +- app/Console/Commands/GenerateResources.php | 4 +- app/Console/Commands/Inspire.php | 50 ++-- app/Console/Commands/PruneData.php | 4 +- .../Commands/RemoveOrphanedDocuments.php | 4 +- app/Console/Commands/ResetData.php | 4 +- .../Commands/SendRecurringInvoices.php | 4 +- app/Console/Commands/SendReminders.php | 4 +- app/Console/Commands/SendRenewalInvoices.php | 4 +- app/Console/Commands/TestOFX.php | 4 +- app/Exceptions/Handler.php | 58 ++-- app/Handlers/InvoiceEventHandler.php | 104 ++++--- .../Datatables/AccountGatewayDatatable.php | 13 +- app/Ninja/Datatables/ActivityDatatable.php | 10 +- app/Ninja/Datatables/BankAccountDatatable.php | 17 +- app/Ninja/Datatables/ClientDatatable.php | 27 +- app/Ninja/Datatables/CreditDatatable.php | 15 +- app/Ninja/Datatables/EntityDatatable.php | 27 +- .../Datatables/ExpenseCategoryDatatable.php | 14 +- app/Ninja/Datatables/ExpenseDatatable.php | 22 +- app/Ninja/Datatables/InvoiceDatatable.php | 21 +- app/Ninja/Datatables/PaymentDatatable.php | 25 +- app/Ninja/Datatables/ProductDatatable.php | 14 +- .../Datatables/RecurringInvoiceDatatable.php | 14 +- app/Ninja/Datatables/TaskDatatable.php | 18 +- app/Ninja/Datatables/TaxRateDatatable.php | 13 +- app/Ninja/Datatables/TokenDatatable.php | 13 +- app/Ninja/Datatables/UserDatatable.php | 18 +- app/Ninja/Datatables/VendorDatatable.php | 15 +- app/Ninja/Mailers/ContactMailer.php | 5 +- app/Ninja/Mailers/Mailer.php | 6 +- app/Ninja/Mailers/UserMailer.php | 6 +- .../AuthorizeNetAIMPaymentDriver.php | 10 +- .../PaymentDrivers/BasePaymentDriver.php | 272 +++++++++++++++--- .../PaymentDrivers/BitPayPaymentDriver.php | 11 +- .../PaymentDrivers/BraintreePaymentDriver.php | 87 +++++- .../CheckoutComPaymentDriver.php | 19 +- .../CybersourcePaymentDriver.php | 18 +- .../PaymentDrivers/DwollaPaymentDriver.php | 13 +- .../EwayRapidSharedPaymentDriver.php | 10 +- .../GoCardlessPaymentDriver.php | 10 +- .../PaymentDrivers/MolliePaymentDriver.php | 12 +- .../PaymentDrivers/PayFastPaymentDriver.php | 12 +- .../PayPalExpressPaymentDriver.php | 27 +- .../PaymentDrivers/PayPalProPaymentDriver.php | 19 +- .../PaymentDrivers/StripePaymentDriver.php | 98 ++++++- .../TwoCheckoutPaymentDriver.php | 19 +- .../PaymentDrivers/WePayPaymentDriver.php | 91 +++--- .../Repositories/AccountGatewayRepository.php | 15 +- app/Ninja/Repositories/AccountRepository.php | 31 +- app/Ninja/Repositories/ActivityRepository.php | 26 +- .../Repositories/BankAccountRepository.php | 20 +- app/Ninja/Repositories/ClientRepository.php | 34 ++- app/Ninja/Repositories/ContactRepository.php | 12 +- app/Ninja/Repositories/CreditRepository.php | 24 +- app/Ninja/Repositories/DocumentRepository.php | 31 +- .../ExpenseCategoryRepository.php | 23 +- app/Ninja/Repositories/ExpenseRepository.php | 48 +++- app/Ninja/Repositories/InvoiceRepository.php | 2 + app/Ninja/Repositories/NinjaRepository.php | 15 +- app/Ninja/Repositories/PaymentRepository.php | 45 ++- .../Repositories/PaymentTermRepository.php | 13 +- app/Ninja/Repositories/ProductRepository.php | 26 +- app/Ninja/Repositories/ReferralRepository.php | 12 +- app/Ninja/Repositories/TaskRepository.php | 28 +- app/Ninja/Repositories/TaxRateRepository.php | 61 ++-- app/Ninja/Repositories/TokenRepository.php | 15 +- app/Ninja/Repositories/UserRepository.php | 25 +- .../Repositories/VendorContactRepository.php | 17 +- app/Ninja/Repositories/VendorRepository.php | 37 ++- app/Policies/ClientPolicy.php | 8 +- app/Policies/CreditPolicy.php | 8 +- app/Policies/DocumentPolicy.php | 5 +- app/Policies/ExpensePolicy.php | 3 + 77 files changed, 1526 insertions(+), 394 deletions(-) diff --git a/app/Commands/Command.php b/app/Commands/Command.php index d6a8d61150..e0be769799 100644 --- a/app/Commands/Command.php +++ b/app/Commands/Command.php @@ -1,5 +1,10 @@ -info("=== Client:{$client->id} Balance:{$client->balance} Actual Balance:{$client->actual_balance} ==="); - $foundProblem = false; $lastBalance = 0; $lastAdjustment = 0; $lastCreatedAt = null; @@ -182,8 +183,16 @@ class CheckData extends Command { $activities = DB::table('activities') ->where('client_id', '=', $client->id) ->orderBy('activities.id') - ->get(['activities.id', 'activities.created_at', 'activities.activity_type_id', 'activities.adjustment', 'activities.balance', 'activities.invoice_id']); - //$this->info(var_dump($activities)); + ->get( + [ + 'activities.id', + 'activities.created_at', + 'activities.activity_type_id', + 'activities.adjustment', + 'activities.balance', + 'activities.invoice_id' + ] + ); foreach ($activities as $activity) { @@ -231,13 +240,11 @@ class CheckData extends Command { // **Fix for allowing converting a recurring invoice to a normal one without updating the balance** if ($noAdjustment && $invoice->invoice_type_id == INVOICE_TYPE_STANDARD && !$invoice->is_recurring) { $this->info("No adjustment for new invoice:{$activity->invoice_id} amount:{$invoice->amount} invoiceTypeId:{$invoice->invoice_type_id} isRecurring:{$invoice->is_recurring}"); - $foundProblem = true; $clientFix += $invoice->amount; $activityFix = $invoice->amount; // **Fix for updating balance when creating a quote or recurring invoice** } elseif ($activity->adjustment != 0 && ($invoice->invoice_type_id == INVOICE_TYPE_QUOTE || $invoice->is_recurring)) { $this->info("Incorrect adjustment for new invoice:{$activity->invoice_id} adjustment:{$activity->adjustment} invoiceTypeId:{$invoice->invoice_type_id} isRecurring:{$invoice->is_recurring}"); - $foundProblem = true; $clientFix -= $activity->adjustment; $activityFix = 0; } @@ -245,7 +252,6 @@ class CheckData extends Command { // **Fix for updating balance when deleting a recurring invoice** if ($activity->adjustment != 0 && $invoice->is_recurring) { $this->info("Incorrect adjustment for deleted invoice adjustment:{$activity->adjustment}"); - $foundProblem = true; if ($activity->balance != $lastBalance) { $clientFix -= $activity->adjustment; } @@ -255,7 +261,6 @@ class CheckData extends Command { // **Fix for updating balance when archiving an invoice** if ($activity->adjustment != 0 && !$invoice->is_recurring) { $this->info("Incorrect adjustment for archiving invoice adjustment:{$activity->adjustment}"); - $foundProblem = true; $activityFix = 0; $clientFix += $activity->adjustment; } @@ -263,12 +268,10 @@ class CheckData extends Command { // **Fix for updating balance when updating recurring invoice** if ($activity->adjustment != 0 && $invoice->is_recurring) { $this->info("Incorrect adjustment for updated recurring invoice adjustment:{$activity->adjustment}"); - $foundProblem = true; $clientFix -= $activity->adjustment; $activityFix = 0; } else if ((strtotime($activity->created_at) - strtotime($lastCreatedAt) <= 1) && $activity->adjustment > 0 && $activity->adjustment == $lastAdjustment) { $this->info("Duplicate adjustment for updated invoice adjustment:{$activity->adjustment}"); - $foundProblem = true; $clientFix -= $activity->adjustment; $activityFix = 0; } @@ -276,7 +279,6 @@ class CheckData extends Command { // **Fix for updating balance when updating a quote** if ($activity->balance != $lastBalance) { $this->info("Incorrect adjustment for updated quote adjustment:{$activity->adjustment}"); - $foundProblem = true; $clientFix += $lastBalance - $activity->balance; $activityFix = 0; } @@ -284,7 +286,6 @@ class CheckData extends Command { // **Fix for deleting payment after deleting invoice** if ($activity->adjustment != 0 && $invoice->is_deleted && $activity->created_at > $invoice->deleted_at) { $this->info("Incorrect adjustment for deleted payment adjustment:{$activity->adjustment}"); - $foundProblem = true; $activityFix = 0; $clientFix -= $activity->adjustment; } diff --git a/app/Console/Commands/CreateTestData.php b/app/Console/Commands/CreateTestData.php index a75922635f..f4364e5d06 100644 --- a/app/Console/Commands/CreateTestData.php +++ b/app/Console/Commands/CreateTestData.php @@ -1,5 +1,8 @@ - $invoice->id, @@ -167,9 +171,9 @@ class CreateTestData extends Command } /** - * @param $vendor + * @param Vendor $vendor */ - private function createExpense($vendor) + private function createExpense(Vendor $vendor) { for ($i=0; $i<$this->count; $i++) { $data = [ diff --git a/app/Console/Commands/GenerateResources.php b/app/Console/Commands/GenerateResources.php index 9826f3c70b..2766a906c1 100644 --- a/app/Console/Commands/GenerateResources.php +++ b/app/Console/Commands/GenerateResources.php @@ -1,4 +1,6 @@ -comment(PHP_EOL.Inspiring::quote().PHP_EOL); - } + /** + * Execute the console command. + * + * @return mixed + */ + public function handle() + { + $this->comment(PHP_EOL . Inspiring::quote() . PHP_EOL); + } } diff --git a/app/Console/Commands/PruneData.php b/app/Console/Commands/PruneData.php index 1c04e1ab5f..c7e3f83470 100644 --- a/app/Console/Commands/PruneData.php +++ b/app/Console/Commands/PruneData.php @@ -1,4 +1,6 @@ -path() != 'get_started') { // https://gist.github.com/jrmadsen67/bd0f9ad0ef1ed6bb594e return redirect() - ->back() - ->withInput($request->except('password', '_token')) - ->with([ - 'warning' => trans('texts.token_expired') - ]); + ->back() + ->withInput($request->except('password', '_token')) + ->with([ + 'warning' => trans('texts.token_expired') + ]); } } // In production, except for maintenance mode, we'll show a custom error screen if (Utils::isNinjaProd() && !Utils::isDownForMaintenance() - && !($e instanceof HttpResponseException)) { + && !($e instanceof HttpResponseException) + ) { $data = [ 'error' => get_class($e), 'hideHeader' => true, ]; - + return response()->view('error', $data); } else { return parent::render($request, $e); } - } + } } diff --git a/app/Handlers/InvoiceEventHandler.php b/app/Handlers/InvoiceEventHandler.php index 924a9590ee..986cac7a08 100644 --- a/app/Handlers/InvoiceEventHandler.php +++ b/app/Handlers/InvoiceEventHandler.php @@ -1,51 +1,83 @@ -userMailer = $userMailer; - $this->contactMailer = $contactMailer; - } + /** + * @var ContactMailer + */ + protected $contactMailer; - public function subscribe($events) - { - $events->listen('invoice.sent', 'InvoiceEventHandler@onSent'); - $events->listen('invoice.viewed', 'InvoiceEventHandler@onViewed'); - $events->listen('invoice.paid', 'InvoiceEventHandler@onPaid'); - } + /** + * InvoiceEventHandler constructor. + * + * @param UserMailer $userMailer + * @param ContactMailer $contactMailer + */ + public function __construct(UserMailer $userMailer, ContactMailer $contactMailer) + { + $this->userMailer = $userMailer; + $this->contactMailer = $contactMailer; + } - public function onSent($invoice) - { - $this->sendNotifications($invoice, 'sent'); - } + /** + * @param $events + */ + public function subscribe($events) + { + $events->listen('invoice.sent', 'InvoiceEventHandler@onSent'); + $events->listen('invoice.viewed', 'InvoiceEventHandler@onViewed'); + $events->listen('invoice.paid', 'InvoiceEventHandler@onPaid'); + } - public function onViewed($invoice) - { - $this->sendNotifications($invoice, 'viewed'); - } + /** + * @param Invoice $invoice + */ + public function onSent(Invoice $invoice) + { + $this->sendNotifications($invoice, 'sent'); + } - public function onPaid($payment) - { - $this->contactMailer->sendPaymentConfirmation($payment); + /** + * @param Invoice $invoice + */ + public function onViewed(Invoice $invoice) + { + $this->sendNotifications($invoice, 'viewed'); + } - $this->sendNotifications($payment->invoice, 'paid', $payment); - } + /** + * @param Payment $payment + */ + public function onPaid(Payment $payment) + { + $this->contactMailer->sendPaymentConfirmation($payment); - private function sendNotifications($invoice, $type, $payment = null) - { - foreach ($invoice->account->users as $user) - { - if ($user->{'notify_' . $type}) - { + $this->sendNotifications($payment->invoice, 'paid', $payment); + } + + /** + * @param Invoice $invoice + * @param $type + * @param null $payment + */ + private function sendNotifications(Invoice $invoice, $type, $payment = null) + { + foreach ($invoice->account->users as $user) { + if ($user->{'notify_' . $type}) { $this->userMailer->sendNotification($user, $invoice, $type, $payment); - } - } - } + } + } + } } \ No newline at end of file diff --git a/app/Ninja/Datatables/AccountGatewayDatatable.php b/app/Ninja/Datatables/AccountGatewayDatatable.php index 5c7a84d3ea..8551d5fb32 100644 --- a/app/Ninja/Datatables/AccountGatewayDatatable.php +++ b/app/Ninja/Datatables/AccountGatewayDatatable.php @@ -1,12 +1,20 @@ -public_id}"); }, - function ($model) { + function () { return Auth::user()->can('create', ENTITY_TASK); } ], @@ -83,7 +94,7 @@ class ClientDatatable extends EntityDatatable function ($model) { return URL::to("invoices/create/{$model->public_id}"); }, - function ($model) { + function () { return Auth::user()->can('create', ENTITY_INVOICE); } ], @@ -92,13 +103,13 @@ class ClientDatatable extends EntityDatatable function ($model) { return URL::to("quotes/create/{$model->public_id}"); }, - function ($model) { + function () { return Auth::user()->hasFeature(FEATURE_QUOTES) && Auth::user()->can('create', ENTITY_INVOICE); } ], [ '--divider--', function(){return false;}, - function ($model) { + function () { $user = Auth::user(); return ($user->can('create', ENTITY_TASK) || $user->can('create', ENTITY_INVOICE)) && ($user->can('create', ENTITY_PAYMENT) || $user->can('create', ENTITY_CREDIT) || $user->can('create', ENTITY_EXPENSE)); } @@ -108,7 +119,7 @@ class ClientDatatable extends EntityDatatable function ($model) { return URL::to("payments/create/{$model->public_id}"); }, - function ($model) { + function () { return Auth::user()->can('create', ENTITY_PAYMENT); } ], @@ -117,7 +128,7 @@ class ClientDatatable extends EntityDatatable function ($model) { return URL::to("credits/create/{$model->public_id}"); }, - function ($model) { + function () { return Auth::user()->can('create', ENTITY_CREDIT); } ], @@ -126,7 +137,7 @@ class ClientDatatable extends EntityDatatable function ($model) { return URL::to("expenses/create/0/{$model->public_id}"); }, - function ($model) { + function () { return Auth::user()->can('create', ENTITY_EXPENSE); } ] diff --git a/app/Ninja/Datatables/CreditDatatable.php b/app/Ninja/Datatables/CreditDatatable.php index 7f258e377d..931dfd23fd 100644 --- a/app/Ninja/Datatables/CreditDatatable.php +++ b/app/Ninja/Datatables/CreditDatatable.php @@ -1,13 +1,21 @@ -client_public_id}") . '?paymentTypeId=1'; }, - function ($model) { + function () { return Auth::user()->can('create', ENTITY_PAYMENT); } ] diff --git a/app/Ninja/Datatables/EntityDatatable.php b/app/Ninja/Datatables/EntityDatatable.php index 085645ff20..d5dabbff95 100644 --- a/app/Ninja/Datatables/EntityDatatable.php +++ b/app/Ninja/Datatables/EntityDatatable.php @@ -1,22 +1,47 @@ -isBulkEdit = $isBulkEdit; $this->hideClient = $hideClient; } + /** + * @return array + */ public function columns() { return []; } + /** + * @return array + */ public function actions() { return []; diff --git a/app/Ninja/Datatables/ExpenseCategoryDatatable.php b/app/Ninja/Datatables/ExpenseCategoryDatatable.php index 7ef850b0a4..55a37cbb18 100644 --- a/app/Ninja/Datatables/ExpenseCategoryDatatable.php +++ b/app/Ninja/Datatables/ExpenseCategoryDatatable.php @@ -1,13 +1,20 @@ -
$label
"; } - } diff --git a/app/Ninja/Datatables/InvoiceDatatable.php b/app/Ninja/Datatables/InvoiceDatatable.php index b9fa70aa0a..01428f29e2 100644 --- a/app/Ninja/Datatables/InvoiceDatatable.php +++ b/app/Ninja/Datatables/InvoiceDatatable.php @@ -1,13 +1,21 @@ -entityType; @@ -72,6 +80,9 @@ class InvoiceDatatable extends EntityDatatable ]; } + /** + * @return array + */ public function actions() { $entityType = $this->entityType; @@ -91,7 +102,7 @@ class InvoiceDatatable extends EntityDatatable function ($model) use ($entityType) { return URL::to("{$entityType}s/{$model->public_id}/clone"); }, - function ($model) { + function () { return Auth::user()->can('create', ENTITY_INVOICE); } ], @@ -155,6 +166,11 @@ class InvoiceDatatable extends EntityDatatable ]; } + /** + * @param $model + * + * @return string + */ private function getStatusLabel($model) { $entityType = $this->entityType; @@ -189,5 +205,4 @@ class InvoiceDatatable extends EntityDatatable return "

$label

"; } - } diff --git a/app/Ninja/Datatables/PaymentDatatable.php b/app/Ninja/Datatables/PaymentDatatable.php index 20f2cd0258..c8175e4a92 100644 --- a/app/Ninja/Datatables/PaymentDatatable.php +++ b/app/Ninja/Datatables/PaymentDatatable.php @@ -1,20 +1,32 @@ -payment_status_name)); $class = 'default'; diff --git a/app/Ninja/Datatables/ProductDatatable.php b/app/Ninja/Datatables/ProductDatatable.php index a5b3cbfc21..f412e84788 100644 --- a/app/Ninja/Datatables/ProductDatatable.php +++ b/app/Ninja/Datatables/ProductDatatable.php @@ -1,14 +1,22 @@ -invoice_number) { diff --git a/app/Ninja/Datatables/TaxRateDatatable.php b/app/Ninja/Datatables/TaxRateDatatable.php index 3e16aba9ee..88fe2e0dd1 100644 --- a/app/Ninja/Datatables/TaxRateDatatable.php +++ b/app/Ninja/Datatables/TaxRateDatatable.php @@ -1,11 +1,19 @@ -accountGateway = $accountGateway; $this->invitation = $invitation; @@ -54,6 +91,9 @@ class BasePaymentDriver } } + /** + * @return array + */ public function gatewayTypes() { return [ @@ -66,44 +106,74 @@ class BasePaymentDriver return in_array($type, $this->gatewayTypes()); } - // when set to true we won't pass the card details with the form + /** + * When set to true we won't pass the card details with the form + * + * @return bool + */ public function tokenize() { return false; } - // set payment method as pending until confirmed + /** + * Set payment method as pending until confirmed + * + * @return bool + */ public function isTwoStep() { return false; } + /** + * @return string + */ public function providerName() { return strtolower($this->accountGateway->gateway->provider); } + /** + * @return mixed + */ protected function invoice() { return $this->invitation->invoice; } + /** + * @return mixed + */ protected function contact() { return $this->invitation->contact; } + /** + * @return mixed + */ protected function client() { return $this->invoice()->client; } + /** + * @return mixed + */ protected function account() { return $this->client()->account; } - public function startPurchase($input = false, $sourceId = false) + /** + * @param array $input + * @param bool $sourceId + * + * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\RedirectResponse|\Illuminate\View\View + * @throws Exception + */ + public function startPurchase(array $input = false, $sourceId = false) { $this->input = $input; $this->sourceId = $sourceId; @@ -150,7 +220,11 @@ class BasePaymentDriver return view($this->paymentView(), $data); } - // check if a custom view exists for this provider + /** + * Check if a custom view exists for this provider + * + * @return mixed + */ protected function paymentView() { $file = sprintf('%s/views/payments/%s/%s.blade.php', resource_path(), $this->providerName(), $this->gatewayType); @@ -162,7 +236,11 @@ class BasePaymentDriver } } - // check if a custom partial exists for this provider + /** + * Check if a custom partial exists for this provider + * + * @return bool + */ public function partialView() { $file = sprintf('%s/views/payments/%s/partial.blade.php', resource_path(), $this->providerName()); @@ -174,6 +252,9 @@ class BasePaymentDriver } } + /** + * @return array + */ public function rules() { $rules = []; @@ -209,6 +290,9 @@ class BasePaymentDriver return $rules; } + /** + * @return mixed + */ protected function gateway() { if ($this->gateway) { @@ -221,7 +305,14 @@ class BasePaymentDriver return $this->gateway; } - public function completeOnsitePurchase($input = false, $paymentMethod = false) + /** + * @param bool $input + * @param PaymentMethod $paymentMethod + * + * @return Payment|mixed|void + * @throws Exception + */ + public function completeOnsitePurchase($input = false, PaymentMethod $paymentMethod = false) { $this->input = count($input) ? $input : false; $gateway = $this->gateway(); @@ -315,7 +406,12 @@ class BasePaymentDriver $client->save(); } - protected function paymentDetails($paymentMethod = false) + /** + * @param PaymentMethod $paymentMethod + * + * @return array + */ + protected function paymentDetails(PaymentMethod $paymentMethod = false) { $invoice = $this->invoice(); $completeUrl = url('complete/' . $this->invitation->invitation_key . '/' . $this->gatewayType); @@ -345,9 +441,13 @@ class BasePaymentDriver return $data; } - private function paymentDetailsFromInput($input) + /** + * @param array $input + * + * @return array + */ + private function paymentDetailsFromInput(array $input) { - $invoice = $this->invoice(); $client = $this->client(); $data = [ @@ -388,9 +488,11 @@ class BasePaymentDriver return $data; } + /** + * @return array + */ public function paymentDetailsFromClient() { - $invoice = $this->invoice(); $client = $this->client(); $contact = $this->invitation->contact ?: $client->contacts()->first(); @@ -416,6 +518,9 @@ class BasePaymentDriver ]; } + /** + * @return bool + */ protected function shouldCreateToken() { if ($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER)) { @@ -433,19 +538,11 @@ class BasePaymentDriver return boolval(array_get($this->input, 'token_billing')); } - /* - protected function tokenDetails() - { - $details = []; - - if ($customer = $this->customer()) { - $details['customerReference'] = $customer->token; - } - - return $details; - } - */ - + /** + * @param bool $clientId + * + * @return null + */ public function customer($clientId = false) { if ($this->customer) { @@ -467,27 +564,51 @@ class BasePaymentDriver return $this->customer; } + /** + * @param $customer + * + * @return bool + */ protected function checkCustomerExists($customer) { return true; } + /** + * @param $client + * @param $publicId + * @param $amount1 + * @param $amount2 + * + * @throws Exception + */ public function verifyBankAccount($client, $publicId, $amount1, $amount2) { throw new Exception('verifyBankAccount not implemented'); } - public function removePaymentMethod($paymentMethod) + /** + * @param PaymentMethod $paymentMethod + * @throws Exception + */ + public function removePaymentMethod(PaymentMethod $paymentMethod) { $paymentMethod->delete(); } - // Some gateways (ie, Checkout.com and Braintree) require generating a token before paying for the invoice + /** + * Some gateways (ie, Checkout.com and Braintree) require generating a token before paying for the invoice + * + * @return null + */ public function createTransactionToken() { return null; } + /** + * @return PaymentMethod + */ public function createToken() { $account = $this->account(); @@ -502,17 +623,6 @@ class BasePaymentDriver $customer->save(); } - /* - // archive the old payment method - $paymentMethod = PaymentMethod::clientId($this->client()->id) - ->isBankAccount($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER)) - ->first(); - - if ($paymentMethod) { - $paymentMethod->delete(); - } - */ - $paymentMethod = $this->createPaymentMethod($customer); if ($paymentMethod && ! $customer->default_payment_method_id) { @@ -523,13 +633,24 @@ class BasePaymentDriver return $paymentMethod; } + /** + * @param $customer + * + * @return mixed + */ protected function creatingCustomer($customer) { return $customer; } + /** + * @param $customer + * + * @return PaymentMethod + */ public function createPaymentMethod($customer) { + /** @var PaymentMethod $paymentMethod */ $paymentMethod = PaymentMethod::createNew($this->invitation); $paymentMethod->ip = Request::ip(); $paymentMethod->account_gateway_token_id = $customer->id; @@ -543,7 +664,12 @@ class BasePaymentDriver return $paymentMethod; } - protected function creatingPaymentMethod($paymentMethod) + /** + * @param PaymentMethod $paymentMethod + * + * @return PaymentMethod + */ + protected function creatingPaymentMethod(PaymentMethod $paymentMethod) { return $paymentMethod; } @@ -553,7 +679,13 @@ class BasePaymentDriver } - public function createPayment($ref = false, $paymentMethod = null) + /** + * @param bool $ref + * @param PaymentMethod|null $paymentMethod + * + * @return Payment|mixed + */ + public function createPayment($ref = false, PaymentMethod $paymentMethod = null) { $invitation = $this->invitation; $invoice = $this->invoice(); @@ -640,12 +772,24 @@ class BasePaymentDriver return $payment; } - protected function creatingPayment($payment, $paymentMethod) + /** + * @param Payment $payment + * @param $paymentMethod + * + * @return Payment + */ + protected function creatingPayment(Payment $payment, $paymentMethod) { return $payment; } - public function refundPayment($payment, $amount = 0) + /** + * @param Payment $payment + * @param int $amount + * + * @return bool + */ + public function refundPayment(Payment $payment, $amount = 0) { if ($amount) { $amount = min($amount, $payment->getCompletedAmount()); @@ -677,7 +821,13 @@ class BasePaymentDriver return false; } - protected function refundDetails($payment, $amount) + /** + * @param Payment $payment + * @param $amount + * + * @return array + */ + protected function refundDetails(Payment $payment, $amount) { return [ 'amount' => $amount, @@ -685,7 +835,14 @@ class BasePaymentDriver ]; } - protected function attemptVoidPayment($response, $payment, $amount) + /** + * @param $response + * @param Payment $payment + * @param $amount + * + * @return bool + */ + protected function attemptVoidPayment($response, Payment $payment, $amount) { // Partial refund not allowed for unsettled transactions return $amount == $payment->amount; @@ -696,6 +853,12 @@ class BasePaymentDriver return $payment; } + /** + * @param $input + * + * @return bool|mixed + * @throws Exception + */ public function completeOffsitePurchase($input) { $this->input = $input; @@ -717,6 +880,9 @@ class BasePaymentDriver return $this->createPayment($ref); } + /** + * @return array + */ public function tokenLinks() { if ( ! $this->customer()) { @@ -754,6 +920,9 @@ class BasePaymentDriver return $links; } + /** + * @return array + */ public function paymentLinks() { $links = []; @@ -772,6 +941,11 @@ class BasePaymentDriver return $links; } + /** + * @param $gatewayType + * + * @return string + */ protected function paymentUrl($gatewayType) { $account = $this->account(); @@ -789,6 +963,11 @@ class BasePaymentDriver return $url; } + /** + * @param $cardName + * + * @return mixed + */ protected function parseCardType($cardName) { $cardTypes = [ 'visa' => PAYMENT_TYPE_VISA, @@ -821,6 +1000,11 @@ class BasePaymentDriver } } + /** + * @param $input + * + * @throws Exception + */ public function handleWebHook($input) { throw new Exception('Unsupported gateway'); diff --git a/app/Ninja/PaymentDrivers/BitPayPaymentDriver.php b/app/Ninja/PaymentDrivers/BitPayPaymentDriver.php index df1821acdb..97fbde3948 100644 --- a/app/Ninja/PaymentDrivers/BitPayPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/BitPayPaymentDriver.php @@ -1,12 +1,19 @@ -isGatewayType(GATEWAY_TYPE_PAYPAL)) { - /* - if ( ! $sourceId || empty($input['device_data'])) { - throw new Exception(); - } - - Session::put($this->invitation->id . 'device_data', $input['device_data']); - */ - $data['details'] = ! empty($input['device_data']) ? json_decode($input['device_data']) : false; } return $data; } + /** + * @param $customer + * + * @return bool + */ protected function checkCustomerExists($customer) { if ( ! parent::checkCustomerExists($customer)) { @@ -60,7 +82,12 @@ class BraintreePaymentDriver extends BasePaymentDriver return ($customer instanceof Customer); } - protected function paymentDetails($paymentMethod = false) + /** + * @param PaymentMethod $paymentMethod + * + * @return array + */ + protected function paymentDetails(PaymentMethod $paymentMethod = false) { $data = parent::paymentDetails($paymentMethod); @@ -81,6 +108,9 @@ class BraintreePaymentDriver extends BasePaymentDriver return $data; } + /** + * @return PaymentMethod|bool + */ public function createToken() { if ($customer = $this->customer()) { @@ -113,6 +143,9 @@ class BraintreePaymentDriver extends BasePaymentDriver return parent::createToken(); } + /** + * @return array + */ private function customerData() { return [ @@ -125,6 +158,11 @@ class BraintreePaymentDriver extends BasePaymentDriver ]; } + /** + * @param $customer + * + * @return mixed + */ public function creatingCustomer($customer) { $customer->token = $this->tokenResponse->customerId; @@ -132,7 +170,12 @@ class BraintreePaymentDriver extends BasePaymentDriver return $customer; } - protected function creatingPaymentMethod($paymentMethod) + /** + * @param PaymentMethod $paymentMethod + * + * @return PaymentMethod|null + */ + protected function creatingPaymentMethod(PaymentMethod $paymentMethod) { $response = $this->tokenResponse; @@ -152,7 +195,13 @@ class BraintreePaymentDriver extends BasePaymentDriver return $paymentMethod; } - public function removePaymentMethod($paymentMethod) + /** + * @param PaymentMethod $paymentMethod + * + * @return bool + * @throws Exception + */ + public function removePaymentMethod(PaymentMethod $paymentMethod) { parent::removePaymentMethod($paymentMethod); @@ -167,7 +216,14 @@ class BraintreePaymentDriver extends BasePaymentDriver } } - protected function attemptVoidPayment($response, $payment, $amount) + /** + * @param $response + * @param Payment $payment + * @param $amount + * + * @return bool + */ + protected function attemptVoidPayment($response, Payment $payment, $amount) { if ( ! parent::attemptVoidPayment($response, $payment, $amount)) { return false; @@ -185,6 +241,9 @@ class BraintreePaymentDriver extends BasePaymentDriver return false; } + /** + * @return mixed + */ public function createTransactionToken() { return $this->gateway() diff --git a/app/Ninja/PaymentDrivers/CheckoutComPaymentDriver.php b/app/Ninja/PaymentDrivers/CheckoutComPaymentDriver.php index ede0b67823..b292507d7f 100644 --- a/app/Ninja/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/CheckoutComPaymentDriver.php @@ -1,7 +1,17 @@ -gateway()->purchase([ @@ -21,7 +31,12 @@ class CheckoutComPaymentDriver extends BasePaymentDriver return false; } - protected function paymentDetails($paymentMethod = false) + /** + * @param PaymentMethod $paymentMethod + * + * @return array + */ + protected function paymentDetails(PaymentMethod $paymentMethod = false) { $data = parent::paymentDetails(); diff --git a/app/Ninja/PaymentDrivers/CybersourcePaymentDriver.php b/app/Ninja/PaymentDrivers/CybersourcePaymentDriver.php index 29299eb94f..64e49ae74c 100644 --- a/app/Ninja/PaymentDrivers/CybersourcePaymentDriver.php +++ b/app/Ninja/PaymentDrivers/CybersourcePaymentDriver.php @@ -1,10 +1,24 @@ -createPayment($input['bill_trans_ref_no']); diff --git a/app/Ninja/PaymentDrivers/DwollaPaymentDriver.php b/app/Ninja/PaymentDrivers/DwollaPaymentDriver.php index 26f5626c8c..d372d159cc 100644 --- a/app/Ninja/PaymentDrivers/DwollaPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/DwollaPaymentDriver.php @@ -1,12 +1,23 @@ -paymentDetails(); diff --git a/app/Ninja/PaymentDrivers/PayFastPaymentDriver.php b/app/Ninja/PaymentDrivers/PayFastPaymentDriver.php index 79b49b2349..08c54432a1 100644 --- a/app/Ninja/PaymentDrivers/PayFastPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/PayFastPaymentDriver.php @@ -1,9 +1,17 @@ -isGateway(GATEWAY_PAYFAST) && Request::has('pt')) { diff --git a/app/Ninja/PaymentDrivers/PayPalExpressPaymentDriver.php b/app/Ninja/PaymentDrivers/PayPalExpressPaymentDriver.php index ad11a8c128..9ac25cf214 100644 --- a/app/Ninja/PaymentDrivers/PayPalExpressPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/PayPalExpressPaymentDriver.php @@ -1,8 +1,18 @@ -payer_id = $this->input['PayerID']; diff --git a/app/Ninja/PaymentDrivers/PayPalProPaymentDriver.php b/app/Ninja/PaymentDrivers/PayPalProPaymentDriver.php index 0c8344cb57..840ac556f9 100644 --- a/app/Ninja/PaymentDrivers/PayPalProPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/PayPalProPaymentDriver.php @@ -1,7 +1,17 @@ -accountGateway->getPublishableStripeKey(); } + /** + * @return array + */ public function rules() { $rules = parent::rules(); @@ -39,6 +56,11 @@ class StripePaymentDriver extends BasePaymentDriver return $rules; } + /** + * @param $customer + * + * @return bool + */ protected function checkCustomerExists($customer) { $response = $this->gateway() @@ -63,12 +85,20 @@ class StripePaymentDriver extends BasePaymentDriver return true; } + /** + * @return bool + */ public function isTwoStep() { return $this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER) && empty($this->input['plaidPublicToken']); } - protected function paymentDetails($paymentMethod = false) + /** + * @param PaymentMethod $paymentMethod + * + * @return array + */ + protected function paymentDetails(PaymentMethod $paymentMethod = false) { $data = parent::paymentDetails($paymentMethod); @@ -93,6 +123,10 @@ class StripePaymentDriver extends BasePaymentDriver return $data; } + /** + * @return PaymentMethod + * @throws Exception + */ public function createToken() { $invoice = $this->invitation->invoice; @@ -126,6 +160,11 @@ class StripePaymentDriver extends BasePaymentDriver } } + /** + * @param $customer + * + * @return mixed + */ public function creatingCustomer($customer) { $customer->token = $this->tokenResponse['id']; @@ -133,7 +172,12 @@ class StripePaymentDriver extends BasePaymentDriver return $customer; } - protected function creatingPaymentMethod($paymentMethod) + /** + * @param PaymentMethod $paymentMethod + * + * @return PaymentMethod|bool + */ + protected function creatingPaymentMethod(PaymentMethod $paymentMethod) { $data = $this->tokenResponse; @@ -175,16 +219,30 @@ class StripePaymentDriver extends BasePaymentDriver return $paymentMethod; } - protected function creatingPayment($payment, $paymentMethod) + /** + * @param Payment $payment + * @param PaymentMethod $paymentMethod + * + * @return Payment + */ + protected function creatingPayment(Payment $payment, PaymentMethod $paymentMethod) { if ($this->isGatewayType(GATEWAY_TYPE_BANK_TRANSFER, $paymentMethod)) { - $payment->payment_status_id = $this->purchaseResponse['status'] == 'succeeded' ? PAYMENT_STATUS_COMPLETED : PAYMENT_STATUS_PENDING; + $payment->payment_status_id = $this->purchaseResponse['status'] == 'succeeded' + ? PAYMENT_STATUS_COMPLETED + : PAYMENT_STATUS_PENDING; } return $payment; } - public function removePaymentMethod($paymentMethod) + /** + * @param PaymentMethod $paymentMethod + * + * @return bool + * @throws Exception + */ + public function removePaymentMethod(PaymentMethod $paymentMethod) { parent::removePaymentMethod($paymentMethod); @@ -204,6 +262,13 @@ class StripePaymentDriver extends BasePaymentDriver } } + /** + * @param $publicToken + * @param $accountId + * + * @return mixed + * @throws Exception + */ private function getPlaidToken($publicToken, $accountId) { $clientId = $this->accountGateway->getPlaidClientId(); @@ -246,6 +311,14 @@ class StripePaymentDriver extends BasePaymentDriver } } + /** + * @param $client + * @param $publicId + * @param $amount1 + * @param $amount2 + * + * @return bool|mixed|string + */ public function verifyBankAccount($client, $publicId, $amount1, $amount2) { $customer = $this->customer($client->id); @@ -276,6 +349,13 @@ class StripePaymentDriver extends BasePaymentDriver return true; } + /** + * @param $method + * @param $url + * @param null $body + * + * @return mixed|string + */ public function makeStripeCall($method, $url, $body = null) { $apiKey = $this->accountGateway->getConfig()->apiKey; @@ -312,6 +392,12 @@ class StripePaymentDriver extends BasePaymentDriver } } + /** + * @param $input + * + * @return array|string + * @throws Exception + */ public function handleWebHook($input) { $eventId = array_get($input, 'id'); diff --git a/app/Ninja/PaymentDrivers/TwoCheckoutPaymentDriver.php b/app/Ninja/PaymentDrivers/TwoCheckoutPaymentDriver.php index 005611d4a0..f94df7f044 100644 --- a/app/Ninja/PaymentDrivers/TwoCheckoutPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/TwoCheckoutPaymentDriver.php @@ -1,11 +1,24 @@ -createPayment($input['order_number']); } diff --git a/app/Ninja/PaymentDrivers/WePayPaymentDriver.php b/app/Ninja/PaymentDrivers/WePayPaymentDriver.php index a88cc1ac51..530a0eaffa 100644 --- a/app/Ninja/PaymentDrivers/WePayPaymentDriver.php +++ b/app/Ninja/PaymentDrivers/WePayPaymentDriver.php @@ -1,12 +1,21 @@ -accountGateway); @@ -77,22 +105,6 @@ class WePayPaymentDriver extends BasePaymentDriver 'payment_bank_id' => $token, ]); } else { - // Authorize credit card - $tokenResponse = $wepay->request('credit_card/authorize', [ - 'client_id' => WEPAY_CLIENT_ID, - 'client_secret' => WEPAY_CLIENT_SECRET, - 'credit_card_id' => $token, - ]); - - // Update the callback uri and get the card details - $tokenResponse = $wepay->request('credit_card/modify', [ - 'client_id' => WEPAY_CLIENT_ID, - 'client_secret' => WEPAY_CLIENT_SECRET, - 'credit_card_id' => $token, - 'auto_update' => WEPAY_AUTO_UPDATE, - 'callback_uri' => $this->accountGateway->getWebhookUrl(), - ]); - $this->tokenResponse = $wepay->request('credit_card', [ 'client_id' => WEPAY_CLIENT_ID, 'client_secret' => WEPAY_CLIENT_SECRET, @@ -103,23 +115,12 @@ class WePayPaymentDriver extends BasePaymentDriver return parent::createToken(); } - /* - public function creatingCustomer($customer) - { - if ($gatewayResponse instanceof \Omnipay\WePay\Message\CustomCheckoutResponse) { - $wepay = \Utils::setupWePay($accountGateway); - $paymentMethodType = $gatewayResponse->getData()['payment_method']['type']; - - $gatewayResponse = $wepay->request($paymentMethodType, array( - 'client_id' => WEPAY_CLIENT_ID, - 'client_secret' => WEPAY_CLIENT_SECRET, - $paymentMethodType.'_id' => $gatewayResponse->getData()['payment_method'][$paymentMethodType]['id'], - )); - } - } - */ - - protected function creatingPaymentMethod($paymentMethod) + /** + * @param PaymentMethod $paymentMethod + * + * @return PaymentMethod + */ + protected function creatingPaymentMethod(PaymentMethod $paymentMethod) { $source = $this->tokenResponse; @@ -148,7 +149,13 @@ class WePayPaymentDriver extends BasePaymentDriver return $paymentMethod; } - public function removePaymentMethod($paymentMethod) + /** + * @param PaymentMethod $paymentMethod + * + * @return bool + * @throws Exception + */ + public function removePaymentMethod(PaymentMethod $paymentMethod) { parent::removePaymentMethod($paymentMethod); @@ -166,7 +173,13 @@ class WePayPaymentDriver extends BasePaymentDriver } } - protected function refundDetails($payment, $amount) + /** + * @param Payment $payment + * @param $amount + * + * @return array + */ + protected function refundDetails(Payment $payment, $amount) { $data = parent::refundDetails($payment, $amount); @@ -182,7 +195,7 @@ class WePayPaymentDriver extends BasePaymentDriver return $data; } - protected function attemptVoidPayment($response, $payment, $amount) + protected function attemptVoidPayment($response, Payment $payment, $amount) { if ( ! parent::attemptVoidPayment($response, $payment, $amount)) { return false; @@ -231,8 +244,6 @@ class WePayPaymentDriver extends BasePaymentDriver if ($source->state == 'deleted') { $paymentMethod->delete(); - } else { - //$this->paymentService->convertPaymentMethodFromWePay($source, null, $paymentMethod)->save(); } return 'Processed successfully'; diff --git a/app/Ninja/Repositories/AccountGatewayRepository.php b/app/Ninja/Repositories/AccountGatewayRepository.php index c59b0d77ab..91f7b5c021 100644 --- a/app/Ninja/Repositories/AccountGatewayRepository.php +++ b/app/Ninja/Repositories/AccountGatewayRepository.php @@ -1,14 +1,27 @@ -users as $user) { if ($userAccount = self::findUserAccounts($user->id)) { $userAccount->removeUserId($user->id); @@ -662,7 +670,11 @@ class AccountRepository return $code; } - public function createTokens($user, $name) + /** + * @param User $user + * @param $name + */ + public function createTokens(User $user, $name) { $name = trim($name) ?: 'TOKEN'; $users = $this->findUsers($user); @@ -679,7 +691,12 @@ class AccountRepository } } - public function getUserAccountId($account) + /** + * @param Account $account + * + * @return bool|mixed + */ + public function getUserAccountId(Account $account) { $user = $account->users()->first(); $userAccount = $this->findUserAccounts($user->id); @@ -687,7 +704,11 @@ class AccountRepository return $userAccount ? $userAccount->id : false; } - public function save($data, $account) + /** + * @param $data + * @param Account $account + */ + public function save($data, Account $account) { $account->fill($data); $account->save(); diff --git a/app/Ninja/Repositories/ActivityRepository.php b/app/Ninja/Repositories/ActivityRepository.php index f36812546d..65a26f4b3a 100644 --- a/app/Ninja/Repositories/ActivityRepository.php +++ b/app/Ninja/Repositories/ActivityRepository.php @@ -1,4 +1,6 @@ -get(); } + /** + * @param null $filter + * @param bool $userId + * + * @return $this + */ public function find($filter = null, $userId = false) { $query = DB::table('clients') @@ -68,7 +84,13 @@ class ClientRepository extends BaseRepository return $query; } - public function save($data, $client = null) + /** + * @param $data + * @param Client|null $client + * + * @return Client|mixed + */ + public function save($data, Client $client = null) { $publicId = isset($data['public_id']) ? $data['public_id'] : false; @@ -95,12 +117,6 @@ class ClientRepository extends BaseRepository $client->fill($data); $client->save(); - /* - if ( ! isset($data['contact']) && ! isset($data['contacts'])) { - return $client; - } - */ - $first = true; $contacts = isset($data['contact']) ? [$data['contact']] : $data['contacts']; $contactIds = []; diff --git a/app/Ninja/Repositories/ContactRepository.php b/app/Ninja/Repositories/ContactRepository.php index 6f157c1c40..2b26485cbd 100644 --- a/app/Ninja/Repositories/ContactRepository.php +++ b/app/Ninja/Repositories/ContactRepository.php @@ -1,9 +1,19 @@ -get(); } + /** + * @return $this + */ public function find() { $accountid = \Auth::user()->account_id; @@ -50,6 +63,12 @@ class DocumentRepository extends BaseRepository return $query; } + /** + * @param $data + * @param null $doc_array + * + * @return mixed + */ public function upload($data, &$doc_array=null) { $uploaded = $data['file']; @@ -177,6 +196,14 @@ class DocumentRepository extends BaseRepository return $document; } + /** + * @param $contactId + * @param $entityType + * @param $search + * + * @return \Illuminate\Http\JsonResponse + * @throws \Exception + */ public function getClientDatatable($contactId, $entityType, $search) { diff --git a/app/Ninja/Repositories/ExpenseCategoryRepository.php b/app/Ninja/Repositories/ExpenseCategoryRepository.php index 90edbd2d74..c2ceebdab7 100644 --- a/app/Ninja/Repositories/ExpenseCategoryRepository.php +++ b/app/Ninja/Repositories/ExpenseCategoryRepository.php @@ -1,17 +1,26 @@ -documentRepo = $documentRepo; } + /** + * @return mixed + */ public function all() { return Expense::scope() @@ -31,6 +49,11 @@ class ExpenseRepository extends BaseRepository ->get(); } + /** + * @param $vendorPublicId + * + * @return mixed + */ public function findVendor($vendorPublicId) { $vendorId = Vendor::getPrivateId($vendorPublicId); @@ -40,6 +63,11 @@ class ExpenseRepository extends BaseRepository return $query; } + /** + * @param null $filter + * + * @return $this + */ public function find($filter = null) { $accountid = \Auth::user()->account_id; @@ -110,7 +138,13 @@ class ExpenseRepository extends BaseRepository return $query; } - public function save($input, $expense = null) + /** + * @param array $input + * @param Expense|null $expense + * + * @return Expense|mixed + */ + public function save(array $input, Expense $expense = null) { $publicId = isset($input['public_id']) ? $input['public_id'] : false; @@ -174,6 +208,12 @@ class ExpenseRepository extends BaseRepository return $expense; } + /** + * @param $ids + * @param $action + * + * @return int + */ public function bulk($ids, $action) { $expenses = Expense::withTrashed()->scope($ids)->get(); @@ -194,6 +234,6 @@ class ExpenseRepository extends BaseRepository } } - return count($tasks); + return $expenses->count(); } } diff --git a/app/Ninja/Repositories/InvoiceRepository.php b/app/Ninja/Repositories/InvoiceRepository.php index 0249f764b6..bfc3e270c4 100644 --- a/app/Ninja/Repositories/InvoiceRepository.php +++ b/app/Ninja/Repositories/InvoiceRepository.php @@ -748,6 +748,7 @@ class InvoiceRepository extends BaseRepository /** * @param Invoice $recurInvoice + * * @return mixed */ public function createRecurringInvoice(Invoice $recurInvoice) @@ -839,6 +840,7 @@ class InvoiceRepository extends BaseRepository /** * @param Account $account + * * @return mixed */ public function findNeedingReminding(Account $account) diff --git a/app/Ninja/Repositories/NinjaRepository.php b/app/Ninja/Repositories/NinjaRepository.php index d1dc7abede..e16e20a80c 100644 --- a/app/Ninja/Repositories/NinjaRepository.php +++ b/app/Ninja/Repositories/NinjaRepository.php @@ -1,10 +1,20 @@ -first(); @@ -12,6 +22,7 @@ class NinjaRepository return; } + /** @var Company $company */ $company = $account->company; $company->plan = !empty($data['plan']) && $data['plan'] != PLAN_FREE?$data['plan']:null; $company->plan_term = !empty($data['plan_term'])?$data['plan_term']:null; diff --git a/app/Ninja/Repositories/PaymentRepository.php b/app/Ninja/Repositories/PaymentRepository.php index f75f9a1867..13b8e847b0 100644 --- a/app/Ninja/Repositories/PaymentRepository.php +++ b/app/Ninja/Repositories/PaymentRepository.php @@ -1,18 +1,31 @@ -invoice->is_deleted) { return false; @@ -210,7 +240,12 @@ class PaymentRepository extends BaseRepository parent::delete($payment); } - public function restore($payment) + /** + * @param Payment $payment + * + * @return bool + */ + public function restore(Payment $payment) { if ($payment->invoice->is_deleted) { return false; diff --git a/app/Ninja/Repositories/PaymentTermRepository.php b/app/Ninja/Repositories/PaymentTermRepository.php index bde31c20a8..3eea4b3b77 100644 --- a/app/Ninja/Repositories/PaymentTermRepository.php +++ b/app/Ninja/Repositories/PaymentTermRepository.php @@ -1,18 +1,27 @@ -where('payment_terms.account_id', '=', $accountId) ->where('payment_terms.deleted_at', '=', null) ->select('payment_terms.public_id', 'payment_terms.name', 'payment_terms.num_days', 'payment_terms.deleted_at'); } diff --git a/app/Ninja/Repositories/ProductRepository.php b/app/Ninja/Repositories/ProductRepository.php index 61cee1eec7..3f2053f960 100644 --- a/app/Ninja/Repositories/ProductRepository.php +++ b/app/Ninja/Repositories/ProductRepository.php @@ -1,15 +1,26 @@ -get(); } + /** + * @param $accountId + * + * @return $this + */ public function find($accountId) { return DB::table('products') @@ -37,7 +53,13 @@ class ProductRepository extends BaseRepository ); } - public function save($data, $product = null) + /** + * @param array $data + * @param Product|null $product + * + * @return Product|mixed + */ + public function save(array $data, Product $product = null) { $publicId = isset($data['public_id']) ? $data['public_id'] : false; diff --git a/app/Ninja/Repositories/ReferralRepository.php b/app/Ninja/Repositories/ReferralRepository.php index ca12f960fd..813059840f 100644 --- a/app/Ninja/Repositories/ReferralRepository.php +++ b/app/Ninja/Repositories/ReferralRepository.php @@ -1,9 +1,19 @@ -get(); diff --git a/app/Ninja/Repositories/TaskRepository.php b/app/Ninja/Repositories/TaskRepository.php index db78cba3bf..4ac8bad94d 100644 --- a/app/Ninja/Repositories/TaskRepository.php +++ b/app/Ninja/Repositories/TaskRepository.php @@ -1,12 +1,23 @@ -scope($ids)->get(); diff --git a/app/Ninja/Repositories/TaxRateRepository.php b/app/Ninja/Repositories/TaxRateRepository.php index f737256e85..b28a66d35d 100644 --- a/app/Ninja/Repositories/TaxRateRepository.php +++ b/app/Ninja/Repositories/TaxRateRepository.php @@ -1,16 +1,28 @@ -select('tax_rates.public_id', 'tax_rates.name', 'tax_rates.rate', 'tax_rates.deleted_at'); } - public function save($data, $taxRate = null) + /** + * @param array $data + * @param TaxRate|null $taxRate + * + * @return TaxRate|mixed + */ + public function save(array $data, TaxRate $taxRate = null) { if ($taxRate) { // do nothing @@ -35,41 +53,4 @@ class TaxRateRepository extends BaseRepository return $taxRate; } - - /* - public function save($taxRates) - { - $taxRateIds = []; - - foreach ($taxRates as $record) { - if (!isset($record->rate) || (isset($record->is_deleted) && $record->is_deleted)) { - continue; - } - - if (!isset($record->name) || !trim($record->name)) { - continue; - } - - if ($record->public_id) { - $taxRate = TaxRate::scope($record->public_id)->firstOrFail(); - } else { - $taxRate = TaxRate::createNew(); - } - - $taxRate->rate = Utils::parseFloat($record->rate); - $taxRate->name = trim($record->name); - $taxRate->save(); - - $taxRateIds[] = $taxRate->public_id; - } - - $taxRates = TaxRate::scope()->get(); - - foreach ($taxRates as $taxRate) { - if (!in_array($taxRate->public_id, $taxRateIds)) { - $taxRate->delete(); - } - } - } - */ } diff --git a/app/Ninja/Repositories/TokenRepository.php b/app/Ninja/Repositories/TokenRepository.php index 16fa02f800..083deef2a0 100644 --- a/app/Ninja/Repositories/TokenRepository.php +++ b/app/Ninja/Repositories/TokenRepository.php @@ -1,16 +1,29 @@ -fill($data); $user->save(); diff --git a/app/Ninja/Repositories/VendorContactRepository.php b/app/Ninja/Repositories/VendorContactRepository.php index a348f05977..6d6d9100ee 100644 --- a/app/Ninja/Repositories/VendorContactRepository.php +++ b/app/Ninja/Repositories/VendorContactRepository.php @@ -1,18 +1,25 @@ -send_invoice = true; $contact->vendor_id = $data['vendor_id']; $contact->is_primary = VendorContact::scope()->where('vendor_id', '=', $contact->vendor_id)->count() == 0; } else { diff --git a/app/Ninja/Repositories/VendorRepository.php b/app/Ninja/Repositories/VendorRepository.php index 1f848e0a0b..5668b48de7 100644 --- a/app/Ninja/Repositories/VendorRepository.php +++ b/app/Ninja/Repositories/VendorRepository.php @@ -1,16 +1,26 @@ -get(); } + /** + * @param null $filter + * + * @return $this + */ public function find($filter = null) { $query = DB::table('vendors') @@ -60,7 +75,13 @@ class VendorRepository extends BaseRepository return $query; } - public function save($data, $vendor = null) + /** + * @param array $data + * @param Vendor|null $vendor + * + * @return Vendor|mixed + */ + public function save(array $data, Vendor $vendor = null) { $publicId = isset($data['public_id']) ? $data['public_id'] : false; @@ -75,15 +96,7 @@ class VendorRepository extends BaseRepository $vendor->fill($data); $vendor->save(); - - $first = true; - $vendorcontacts = isset($data['vendor_contact']) ? [$data['vendor_contact']] : $data['vendor_contacts']; - - foreach ($vendorcontacts as $vendorcontact) { - $vendorcontact = $vendor->addVendorContact($vendorcontact, $first); - $first = false; - } - + return $vendor; } } diff --git a/app/Policies/ClientPolicy.php b/app/Policies/ClientPolicy.php index 4610c139fb..81e64a73e0 100644 --- a/app/Policies/ClientPolicy.php +++ b/app/Policies/ClientPolicy.php @@ -2,4 +2,10 @@ namespace App\Policies; -class ClientPolicy extends EntityPolicy {} \ No newline at end of file +/** + * Class ClientPolicy + */ +class ClientPolicy extends EntityPolicy +{ + +} \ No newline at end of file diff --git a/app/Policies/CreditPolicy.php b/app/Policies/CreditPolicy.php index 539bc7e518..c0d1ca2660 100644 --- a/app/Policies/CreditPolicy.php +++ b/app/Policies/CreditPolicy.php @@ -2,4 +2,10 @@ namespace App\Policies; -class CreditPolicy extends EntityPolicy {} \ No newline at end of file +/** + * Class CreditPolicy + */ +class CreditPolicy extends EntityPolicy +{ + +} \ No newline at end of file diff --git a/app/Policies/DocumentPolicy.php b/app/Policies/DocumentPolicy.php index 0af6e80a2a..98160ba4e9 100644 --- a/app/Policies/DocumentPolicy.php +++ b/app/Policies/DocumentPolicy.php @@ -2,6 +2,7 @@ namespace App\Policies; +use App\Models\Document; use App\Models\User; /** @@ -11,6 +12,7 @@ class DocumentPolicy extends EntityPolicy { /** * @param User $user + * * @return bool */ public static function create(User $user) @@ -21,9 +23,10 @@ class DocumentPolicy extends EntityPolicy /** * @param User $user * @param Document $document + * * @return bool */ - public static function view(User $user, $document) + public static function view(User $user, Document $document) { if ($user->hasPermission('view_all')) { return true; diff --git a/app/Policies/ExpensePolicy.php b/app/Policies/ExpensePolicy.php index d281d2f407..97dce5cad3 100644 --- a/app/Policies/ExpensePolicy.php +++ b/app/Policies/ExpensePolicy.php @@ -4,6 +4,9 @@ namespace App\Policies; use App\Models\User; +/** + * Class ExpensePolicy + */ class ExpensePolicy extends EntityPolicy { /**