From 5a8dfd85ebc8188530cb9d330f0a96a257f3e953 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Mon, 21 Dec 2020 11:46:46 +0100 Subject: [PATCH] Apply php-cs-fixer --- app/Helpers/Invoice/InvoiceItemSum.php | 4 +- .../Requests/Invoice/StoreInvoiceRequest.php | 1 - app/Import/Definitions/PaymentMap.php | 1 - app/Import/Transformers/BaseTransformer.php | 25 ++++---- .../Transformers/InvoiceItemTransformer.php | 4 +- .../Transformers/InvoiceTransformer.php | 4 +- .../Transformers/PaymentTransformer.php | 4 +- .../Transformers/ProductTransformer.php | 2 - app/Jobs/Import/CSVImport.php | 58 ++++++++----------- app/PaymentDrivers/Stripe/CreditCard.php | 1 - app/PaymentDrivers/StripePaymentDriver.php | 1 - app/Services/Invoice/HandleRestore.php | 3 +- config/ninja.php | 2 +- ..._change_products_table_cost_resolution.php | 3 - database/seeders/CountriesSeeder.php | 2 +- tests/Feature/Import/ImportCsvTest.php | 1 - 16 files changed, 45 insertions(+), 71 deletions(-) diff --git a/app/Helpers/Invoice/InvoiceItemSum.php b/app/Helpers/Invoice/InvoiceItemSum.php index 3aa197474147..405e5c1ccf4a 100644 --- a/app/Helpers/Invoice/InvoiceItemSum.php +++ b/app/Helpers/Invoice/InvoiceItemSum.php @@ -112,8 +112,8 @@ class InvoiceItemSum { $item_tax = 0; -// info(print_r($this->item,1)); -// info(print_r($this->invoice,1)); + // info(print_r($this->item,1)); + // info(print_r($this->invoice,1)); $amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100)); $item_tax_rate1_total = $this->calcAmountLineTax($this->item->tax_rate1, $amount); diff --git a/app/Http/Requests/Invoice/StoreInvoiceRequest.php b/app/Http/Requests/Invoice/StoreInvoiceRequest.php index 9163f2fb9d1f..99bcca814ca8 100644 --- a/app/Http/Requests/Invoice/StoreInvoiceRequest.php +++ b/app/Http/Requests/Invoice/StoreInvoiceRequest.php @@ -12,7 +12,6 @@ namespace App\Http\Requests\Invoice; use App\Http\Requests\Request; -use App\Http\ValidationRules\Invoice\UniqueInvoiceNumberRule; use App\Http\ValidationRules\Project\ValidProjectForClient; use App\Models\Invoice; use App\Utils\Traits\CleanLineItems; diff --git a/app/Import/Definitions/PaymentMap.php b/app/Import/Definitions/PaymentMap.php index c9567e50e044..7ff554be0096 100644 --- a/app/Import/Definitions/PaymentMap.php +++ b/app/Import/Definitions/PaymentMap.php @@ -55,4 +55,3 @@ class PaymentMap ]; } } - diff --git a/app/Import/Transformers/BaseTransformer.php b/app/Import/Transformers/BaseTransformer.php index 404fad114a32..9371d802281a 100644 --- a/app/Import/Transformers/BaseTransformer.php +++ b/app/Import/Transformers/BaseTransformer.php @@ -50,7 +50,7 @@ class BaseTransformer public function getInvoiceTypeId($data, $field) { - return (isset($data[$field]) && $data[$field]) ? $data[$field] : '1'; + return (isset($data[$field]) && $data[$field]) ? $data[$field] : '1'; } public function getCurrencyByCode($data) @@ -60,8 +60,9 @@ class BaseTransformer if ($code) { $currency = $this->maps['currencies']->where('code', $code)->first(); - if($currency_id) + if ($currency_id) { return $currency->id; + } } return $this->maps['company']->settings->currency_id; @@ -69,28 +70,28 @@ class BaseTransformer public function getClient($client_name, $client_email) { - $clients = $this->maps['company']->clients; $clients = $clients->where('name', $client_name); - if($clients->count() >= 1) + if ($clients->count() >= 1) { return $clients->first()->id; + } $contacts = ClientContact::where('company_id', $this->maps['company']->id) ->where('email', $client_email); - if($contacts->count() >=1) + if ($contacts->count() >=1) { return $contacts->first()->client_id; + } - return NULL; - + return null; } -/////////////////////////////////////////////////////////////////////////////////// + /////////////////////////////////////////////////////////////////////////////////// /** * @param $name * @@ -147,12 +148,12 @@ class BaseTransformer * @return float */ public function getFloat($data, $field) - { - - if(array_key_exists($field, $data)) + { + if (array_key_exists($field, $data)) { $number = preg_replace('/[^0-9-.]+/', '', $data[$field]); - else + } else { $number = 0; + } return Number::parseStringFloat($number); } diff --git a/app/Import/Transformers/InvoiceItemTransformer.php b/app/Import/Transformers/InvoiceItemTransformer.php index 5ddcca8df3c7..ff93281dc476 100644 --- a/app/Import/Transformers/InvoiceItemTransformer.php +++ b/app/Import/Transformers/InvoiceItemTransformer.php @@ -11,8 +11,6 @@ namespace App\Import\Transformers; -use Illuminate\Support\Str; - /** * Class InvoiceItemTransformer. */ @@ -45,4 +43,4 @@ class InvoiceItemTransformer extends BaseTransformer 'type_id' => $this->getInvoiceTypeId($data, 'item.type_id'), ]; } -} \ No newline at end of file +} diff --git a/app/Import/Transformers/InvoiceTransformer.php b/app/Import/Transformers/InvoiceTransformer.php index 5ed42f8a07c0..d640d00536a2 100644 --- a/app/Import/Transformers/InvoiceTransformer.php +++ b/app/Import/Transformers/InvoiceTransformer.php @@ -11,8 +11,6 @@ namespace App\Import\Transformers; -use Illuminate\Support\Str; - /** * Class InvoiceTransformer. */ @@ -60,4 +58,4 @@ class InvoiceTransformer extends BaseTransformer 'exchange_rate' => $this->getString($data, 'invoice.exchange_rate'), ]; } -} \ No newline at end of file +} diff --git a/app/Import/Transformers/PaymentTransformer.php b/app/Import/Transformers/PaymentTransformer.php index 5ce5042f5b99..b3070da1f053 100644 --- a/app/Import/Transformers/PaymentTransformer.php +++ b/app/Import/Transformers/PaymentTransformer.php @@ -11,8 +11,6 @@ namespace App\Import\Transformers; -use Illuminate\Support\Str; - /** * Class PaymentTransformer. */ @@ -45,4 +43,4 @@ class PaymentTransformer extends BaseTransformer 'method' => $this ]; } -} \ No newline at end of file +} diff --git a/app/Import/Transformers/ProductTransformer.php b/app/Import/Transformers/ProductTransformer.php index c932823d6651..05a8e6a887bb 100644 --- a/app/Import/Transformers/ProductTransformer.php +++ b/app/Import/Transformers/ProductTransformer.php @@ -11,8 +11,6 @@ namespace App\Import\Transformers; -use Illuminate\Support\Str; - /** * Class ProductTransformer. */ diff --git a/app/Jobs/Import/CSVImport.php b/app/Jobs/Import/CSVImport.php index 0381830b23bb..9ee272d5deb2 100644 --- a/app/Jobs/Import/CSVImport.php +++ b/app/Jobs/Import/CSVImport.php @@ -102,8 +102,7 @@ class CSVImport implements ShouldQueue info("errors"); - info(print_r($this->error_array,1)); - + info(print_r($this->error_array, 1)); } public function failed($exception) @@ -116,17 +115,17 @@ class CSVImport implements ShouldQueue private function importInvoice() { - $invoice_transformer = new InvoiceTransformer($this->maps); $records = $this->getCsvData(); $invoice_number_key = array_search('Invoice Number', reset($records)); - if ($this->skip_header) + if ($this->skip_header) { array_shift($records); + } - if(!$invoice_number_key){ + if (!$invoice_number_key) { info("no invoice number to use as key - returning"); return; } @@ -134,15 +133,12 @@ class CSVImport implements ShouldQueue $unique_invoices = []; //get an array of unique invoice numbers - foreach($records as $key => $value) - { + foreach ($records as $key => $value) { $unique_invoices[] = $value[$invoice_number_key]; } - foreach($unique_invoices as $unique) - { - - $invoices = array_filter($records, function($value) use($invoice_number_key, $unique){ + foreach ($unique_invoices as $unique) { + $invoices = array_filter($records, function ($value) use ($invoice_number_key, $unique) { return $value[$invoice_number_key] == $unique; }); @@ -153,9 +149,7 @@ class CSVImport implements ShouldQueue $invoice = $invoice_transformer->transform($invoice_data); $this->processInvoice($invoices, $invoice); - } - } private function processInvoice($invoices, $invoice) @@ -164,36 +158,31 @@ class CSVImport implements ShouldQueue $item_transformer = new InvoiceItemTransformer($this->maps); $items = []; - foreach($invoices as $record) - { - + foreach ($invoices as $record) { $keys = $this->column_map; $values = array_intersect_key($record, $this->column_map); $invoice_data = array_combine($keys, $values); $items[] = $item_transformer->transform($invoice_data); - } $invoice['line_items'] = $this->cleanItems($items); - $validator = Validator::make($invoice, (new StoreInvoiceRequest())->rules()); + $validator = Validator::make($invoice, (new StoreInvoiceRequest())->rules()); - if ($validator->fails()) { - $this->error_array[] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())]; - } else { + if ($validator->fails()) { + $this->error_array[] = ['invoice' => $invoice, 'error' => json_encode($validator->errors())]; + } else { + $invoice = $invoice_repository->save($invoice, InvoiceFactory::create($this->company->id, $this->setUser($record))); - $invoice = $invoice_repository->save($invoice, InvoiceFactory::create($this->company->id, $this->setUser($record))); + $this->maps['invoices'][] = $invoice->id; - $this->maps['invoices'][] = $invoice->id; - - $this->performInvoiceActions($invoice, $record, $invoice_repository); - } + $this->performInvoiceActions($invoice, $record, $invoice_repository); + } } private function performInvoiceActions($invoice, $record, $invoice_repository) { - $invoice = $this->actionInvoiceStatus($invoice, $record, $invoice_repository); } @@ -207,7 +196,7 @@ class CSVImport implements ShouldQueue case 'Sent': $invoice = $invoice->service()->markSent()->save(); break; - case 'Viewed'; + case 'Viewed': $invoice = $invoice->service()->markSent()->save(); break; default: @@ -215,7 +204,7 @@ class CSVImport implements ShouldQueue break; } - if($invoice->balance < $invoice->amount && $invoice->status_id <= Invoice::STATUS_SENT){ + if ($invoice->balance < $invoice->amount && $invoice->status_id <= Invoice::STATUS_SENT) { $invoice->status_id = Invoice::STATUS_PARTIAL; $invoice->save(); } @@ -233,11 +222,11 @@ class CSVImport implements ShouldQueue $client_repository = new ClientRepository($contact_repository); $client_transformer = new ClientTransformer($this->maps); - if ($this->skip_header) + if ($this->skip_header) { array_shift($records); + } foreach ($records as $record) { - $keys = $this->column_map; $values = array_intersect_key($record, $this->column_map); @@ -270,17 +259,16 @@ class CSVImport implements ShouldQueue private function importProduct() { - $product_repository = new ProductRepository(); $product_transformer = new ProductTransformer($this->maps); $records = $this->getCsvData(); - if ($this->skip_header) + if ($this->skip_header) { array_shift($records); + } - foreach ($records as $record) - { + foreach ($records as $record) { $keys = $this->column_map; $values = array_intersect_key($record, $this->column_map); diff --git a/app/PaymentDrivers/Stripe/CreditCard.php b/app/PaymentDrivers/Stripe/CreditCard.php index d4d10bded743..d3a06c7d3f79 100644 --- a/app/PaymentDrivers/Stripe/CreditCard.php +++ b/app/PaymentDrivers/Stripe/CreditCard.php @@ -16,7 +16,6 @@ use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; -use App\Models\ClientGatewayToken; use App\Models\GatewayType; use App\Models\Payment; use App\Models\PaymentType; diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index 9585a0670b72..10cc679c9109 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -29,7 +29,6 @@ use App\PaymentDrivers\Stripe\Utilities; use App\Utils\Traits\MakesHash; use Exception; use Illuminate\Support\Carbon; -use Illuminate\View\View; use Stripe\Customer; use Stripe\Exception\ApiErrorException; use Stripe\PaymentIntent; diff --git a/app/Services/Invoice/HandleRestore.php b/app/Services/Invoice/HandleRestore.php index f3d7eff21a75..7ca3ede349aa 100644 --- a/app/Services/Invoice/HandleRestore.php +++ b/app/Services/Invoice/HandleRestore.php @@ -94,8 +94,9 @@ class HandleRestore extends AbstractService $new_invoice_number = substr($this->invoice->number, 0, $pos); - if(strlen($new_invoice_number) == 0) + if (strlen($new_invoice_number) == 0) { $new_invoice_number = null; + } try { $this->invoice->number = $new_invoice_number; diff --git a/config/ninja.php b/config/ninja.php index 3d66a5fd15b9..5ce7fc883912 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -7,7 +7,7 @@ return [ 'production' => env('NINJA_PROD', false), 'license' => env('NINJA_LICENSE', ''), 'version_url' => 'https://raw.githubusercontent.com/invoiceninja/invoiceninja/v5-stable/VERSION.txt', - 'app_name' => env('APP_NAME','Invoice Ninja'), + 'app_name' => env('APP_NAME', 'Invoice Ninja'), 'app_env' => env('APP_ENV', 'selfhosted'), 'require_https' => env('REQUIRE_HTTPS', true), 'app_url' => rtrim(env('APP_URL', ''), '/'), diff --git a/database/migrations/2020_12_20_005609_change_products_table_cost_resolution.php b/database/migrations/2020_12_20_005609_change_products_table_cost_resolution.php index 96cd7a95a3d4..c7682c5f2ac7 100644 --- a/database/migrations/2020_12_20_005609_change_products_table_cost_resolution.php +++ b/database/migrations/2020_12_20_005609_change_products_table_cost_resolution.php @@ -30,6 +30,3 @@ class ChangeProductsTableCostResolution extends Migration // } } - - - \ No newline at end of file diff --git a/database/seeders/CountriesSeeder.php b/database/seeders/CountriesSeeder.php index 399ccd4fb377..326facdfe095 100644 --- a/database/seeders/CountriesSeeder.php +++ b/database/seeders/CountriesSeeder.php @@ -51,7 +51,7 @@ class CountriesSeeder extends Seeder 'sub_region_code' => $country['sub-region-code'], 'eea' => (bool) $country['eea'], 'thousand_separator' => '', - 'decimal_separator' => '', + 'decimal_separator' => '', ]); } } diff --git a/tests/Feature/Import/ImportCsvTest.php b/tests/Feature/Import/ImportCsvTest.php index f0d7aeb5b792..8e409f28ed06 100644 --- a/tests/Feature/Import/ImportCsvTest.php +++ b/tests/Feature/Import/ImportCsvTest.php @@ -150,7 +150,6 @@ class ImportCsvTest extends TestCase CSVImport::dispatchNow($data, $this->company); $this->assertGreaterThan($pre_import, Product::count()); - } private function getCsvData($csvfile)