Fixes for static analysis

This commit is contained in:
David Bomba 2023-04-26 19:25:33 +10:00
parent 6225db9bd9
commit df49ab9aec
10 changed files with 64 additions and 73 deletions

View File

@ -110,7 +110,7 @@ class InvoiceItemSum
public function process()
{
if (! $this->invoice->line_items || ! isset($this->invoice->line_items) || ! is_array($this->invoice->line_items) || count($this->invoice->line_items) == 0) {
if (! $this->invoice->line_items || ! is_array($this->invoice->line_items) || count($this->invoice->line_items) == 0) {
$this->items = [];
return $this;
@ -159,7 +159,7 @@ class InvoiceItemSum
return $this;
}
private function push()
private function push(): self
{
$this->sub_total += $this->getLineTotal();

View File

@ -11,9 +11,14 @@
namespace App\Helpers\Invoice;
use App\Models\Quote;
use App\Utils\Number;
use App\Models\Credit;
use App\Models\Invoice;
use App\Utils\Traits\NumberFormatter;
use App\Models\PurchaseOrder;
use App\Models\RecurringInvoice;
use Illuminate\Support\Collection;
use App\Utils\Traits\NumberFormatter;
class InvoiceSum
{
@ -22,7 +27,7 @@ class InvoiceSum
use Discounter;
use NumberFormatter;
protected $invoice;
protected RecurringInvoice | Invoice | Quote | Credit | PurchaseOrder $invoice;
public $tax_map;
@ -78,7 +83,7 @@ class InvoiceSum
return $this;
}
private function calculateLineItems()
private function calculateLineItems(): self
{
$this->invoice_items = new InvoiceItemSum($this->invoice);
$this->invoice_items->process();
@ -90,7 +95,7 @@ class InvoiceSum
return $this;
}
private function calculateDiscount()
private function calculateDiscount(): self
{
$this->total_discount = $this->discount($this->invoice_items->getSubTotal());
@ -99,7 +104,7 @@ class InvoiceSum
return $this;
}
private function calculateCustomValues()
private function calculateCustomValues(): self
{
$this->total_custom_values += $this->valuer($this->invoice->custom_surcharge1);
@ -114,7 +119,7 @@ class InvoiceSum
return $this;
}
private function calculateInvoiceTaxes()
private function calculateInvoiceTaxes(): self
{
if (is_string($this->invoice->tax_name1) && strlen($this->invoice->tax_name1) > 1) {
$tax = $this->taxer($this->total, $this->invoice->tax_rate1);
@ -148,23 +153,24 @@ class InvoiceSum
*
* @return self The balance.
*/
private function calculateBalance()
private function calculateBalance(): self
{
$this->setCalculatedAttributes();
return $this;
}
private function calculatePartial()
private function calculatePartial(): self
{
if (! isset($this->invoice->id) && isset($this->invoice->partial)) {
$this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
$this->invoice->partial = max(0, min(Number::roundValue($this->invoice->partial, 2), $this->invoice->balance));
// $this->invoice->partial = max(0, min($this->formatValue($this->invoice->partial, 2), $this->invoice->balance));
}
return $this;
}
private function calculateTotals()
private function calculateTotals(): self
{
$this->total += $this->total_taxes;
@ -230,7 +236,7 @@ class InvoiceSum
* Build $this->invoice variables after
* calculations have been performed.
*/
private function setCalculatedAttributes()
private function setCalculatedAttributes(): self
{
/* If amount != balance then some money has been paid on the invoice, need to subtract this difference from the total to set the new balance */
@ -238,9 +244,9 @@ class InvoiceSum
if ($this->invoice->amount != $this->invoice->balance) {
$paid_to_date = $this->invoice->amount - $this->invoice->balance;
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision) - $paid_to_date;
$this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision) - $paid_to_date;
} else {
$this->invoice->balance = $this->formatValue($this->getTotal(), $this->precision);
$this->invoice->balance = Number::roundValue($this->getTotal(), $this->precision);
}
}
/* Set new calculated total */
@ -268,7 +274,7 @@ class InvoiceSum
return $this->gross_sub_total;
}
public function setGrossSubTotal($value)
public function setGrossSubTotal($value): self
{
$this->gross_sub_total = $value;
@ -300,7 +306,7 @@ class InvoiceSum
return $this->total_custom_values;
}
public function setTaxMap()
public function setTaxMap(): self
{
if ($this->invoice->is_amount_discount == true) {
$this->invoice_items->calcTaxesWithAmountDiscount();
@ -369,18 +375,18 @@ class InvoiceSum
return $this->getTotalTaxes();
}
public function purgeTaxes()
public function purgeTaxes(): self
{
$this->tax_rate1 = 0;
$this->tax_name1 = '';
// $this->tax_rate1 = 0;
// $this->tax_name1 = '';
$this->tax_rate2 = 0;
$this->tax_name2 = '';
// $this->tax_rate2 = 0;
// $this->tax_name2 = '';
$this->tax_rate3 = 0;
$this->tax_name3 = '';
// $this->tax_rate3 = 0;
// $this->tax_name3 = '';
$this->discount = 0;
// $this->discount = 0;
$line_items = collect($this->invoice->line_items);

View File

@ -42,7 +42,7 @@ class InvoiceSumInclusive
private $precision;
private InvoiceItemSumInclusive $invoice_items;
public InvoiceItemSumInclusive $invoice_items;
/**
* Constructs the object with Invoice and Settings object.
*

View File

@ -49,7 +49,7 @@ use Laracasts\Presenter\PresentableTrait;
* @property string|null $last_sent_date
* @property string|null $due_date
* @property int $is_deleted
* @property object|null $line_items
* @property array|null $line_items
* @property object|null $backup
* @property string|null $footer
* @property string|null $public_notes
@ -76,10 +76,10 @@ use Laracasts\Presenter\PresentableTrait;
* @property int $custom_surcharge_tax2
* @property int $custom_surcharge_tax3
* @property int $custom_surcharge_tax4
* @property string $exchange_rate
* @property string $amount
* @property string $balance
* @property string|null $partial
* @property float $exchange_rate
* @property float $amount
* @property float $balance
* @property float|null $partial
* @property string|null $partial_due_date
* @property string|null $last_viewed
* @property int|null $created_at
@ -450,7 +450,7 @@ class Credit extends BaseModel
/**
* Access the invoice calculator object.
*
* @return stdClass The invoice calculator object getters
* @return \stdClass The invoice calculator object getters
*/
public function calc()
{
@ -524,6 +524,8 @@ class Credit extends BaseModel
return Storage::disk(config('filesystems.default'))->{$type}($file_path);
}
$file_exists = false;
try {
$file_exists = Storage::disk(config('filesystems.default'))->exists($file_path);
} catch (\Exception $e) {
@ -576,19 +578,14 @@ class Credit extends BaseModel
switch ($status) {
case self::STATUS_DRAFT:
return ctrans('texts.draft');
break;
case self::STATUS_SENT:
return ctrans('texts.sent');
break;
case self::STATUS_PARTIAL:
return ctrans('texts.partial');
break;
case self::STATUS_APPLIED:
return ctrans('texts.applied');
break;
default:
return '';
break;
return ctrans('texts.sent');
}
}
}

View File

@ -78,10 +78,10 @@ use Laracasts\Presenter\PresentableTrait;
* @property int $custom_surcharge_tax2
* @property int $custom_surcharge_tax3
* @property int $custom_surcharge_tax4
* @property string $exchange_rate
* @property string $amount
* @property string $balance
* @property string|null $partial
* @property float $exchange_rate
* @property float $amount
* @property float $balance
* @property float|null $partial
* @property string|null $partial_due_date
* @property string|null $last_viewed
* @property int|null $created_at

View File

@ -76,7 +76,7 @@ use Illuminate\Support\Facades\Storage;
* @property int $custom_surcharge_tax4
* @property string $exchange_rate
* @property string $balance
* @property string|null $partial
* @property float|null $partial
* @property string $amount
* @property string $paid_to_date
* @property string|null $partial_due_date
@ -335,18 +335,15 @@ class PurchaseOrder extends BaseModel
switch ($status) {
case self::STATUS_DRAFT:
return ctrans('texts.draft');
break;
case self::STATUS_SENT:
return ctrans('texts.sent');
break;
case self::STATUS_ACCEPTED:
return ctrans('texts.accepted');
break;
case self::STATUS_CANCELLED:
return ctrans('texts.cancelled');
break;
// code...
break;
default:
return ctrans('texts.sent');
}
}

View File

@ -75,10 +75,10 @@ use Laracasts\Presenter\PresentableTrait;
* @property int $custom_surcharge_tax2
* @property int $custom_surcharge_tax3
* @property int $custom_surcharge_tax4
* @property string $exchange_rate
* @property string $amount
* @property string $balance
* @property string|null $partial
* @property float $exchange_rate
* @property float $amount
* @property float $balance
* @property float|null $partial
* @property string|null $partial_due_date
* @property string|null $last_viewed
* @property int|null $created_at
@ -393,7 +393,7 @@ class Quote extends BaseModel
/**
* Access the quote calculator object.
*
* @return stdClass The quote calculator object getters
* @return \stdClass The quote calculator object getters
*/
public function calc()
{
@ -450,6 +450,8 @@ class Quote extends BaseModel
return Storage::disk(config('filesystems.default'))->{$type}($file_path);
}
$file_exists = false;
try {
$file_exists = Storage::disk(config('filesystems.default'))->exists($file_path);
} catch (\Exception $e) {
@ -473,51 +475,40 @@ class Quote extends BaseModel
* @param int $status
* @return string
*/
public static function badgeForStatus(int $status)
public static function badgeForStatus(int $status): string
{
switch ($status) {
case self::STATUS_DRAFT:
return '<h5><span class="badge badge-light">'.ctrans('texts.draft').'</span></h5>';
break;
case self::STATUS_SENT:
return '<h5><span class="badge badge-primary">'.ctrans('texts.pending').'</span></h5>';
break;
case self::STATUS_APPROVED:
return '<h5><span class="badge badge-success">'.ctrans('texts.approved').'</span></h5>';
break;
case self::STATUS_EXPIRED:
return '<h5><span class="badge badge-danger">'.ctrans('texts.expired').'</span></h5>';
break;
case self::STATUS_CONVERTED:
return '<h5><span class="badge badge-light">'.ctrans('texts.converted').'</span></h5>';
break;
default:
// code...
break;
return '<h5><span class="badge badge-light">'.ctrans('texts.draft').'</span></h5>';
}
}
public static function stringStatus(int $status)
public static function stringStatus(int $status): string
{
switch ($status) {
case self::STATUS_DRAFT:
return ctrans('texts.draft');
break;
case self::STATUS_SENT:
return ctrans('texts.pending');
break;
case self::STATUS_APPROVED:
return ctrans('texts.approved');
break;
case self::STATUS_EXPIRED:
return ctrans('texts.expired');
break;
case self::STATUS_CONVERTED:
return ctrans('texts.converted');
break;
default:
// code...
break;
return ctrans('texts.draft');
}
}

View File

@ -59,7 +59,7 @@ use Laracasts\Presenter\PresentableTrait;
* @property string|null $custom_value4
* @property string $amount
* @property string $balance
* @property string|null $partial
* @property float|null $partial
* @property string|null $last_viewed
* @property int $frequency_id
* @property string|null $last_sent_date

View File

@ -80,7 +80,7 @@ use Laracasts\Presenter\PresentableTrait;
* @property int $custom_surcharge_tax4
* @property string|null $due_date_days
* @property string $exchange_rate
* @property string|null $partial
* @property float|null $partial
* @property string|null $partial_due_date
* @property int|null $subscription_id
* @property int $uses_inclusive_taxes

View File

@ -129,7 +129,7 @@ class Number
/**
* Formats a given value based on the clients currency AND country.
*
* @param floatval $value The number to be formatted
* @param $value The number to be formatted
* @param $entity
* @return string The formatted value
*/