Fixes for static analysis

This commit is contained in:
David Bomba 2023-04-27 00:11:31 +10:00
parent caa7c30620
commit 482e74ac5e
5 changed files with 61 additions and 44 deletions

View File

@ -128,10 +128,15 @@ class PreviewController extends BaseController
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));
}
/** @var \App\Models\Company $company */
/** @var App\Models\User auth()->user() */
$company = auth()->user()->company();
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
$numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company());
$numbered_pdf = $this->pageNumbering($pdf, $company);
if ($numbered_pdf) {
$pdf = $numbered_pdf;
@ -140,9 +145,8 @@ class PreviewController extends BaseController
return $pdf;
}
//else
$file_path = (new PreviewPdf($maker->getCompiledHTML(true), $company))->handle();
$file_path = (new PreviewPdf($maker->getCompiledHTML(true), auth()->user()->company()))->handle();
return response()->download($file_path, basename($file_path), ['Cache-Control:' => 'no-cache'])->deleteFileAfterSend(true);
}
@ -281,13 +285,13 @@ class PreviewController extends BaseController
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));
}
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
$numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company());
$numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company());
$numbered_pdf = $this->pageNumbering($pdf, $company);
if ($numbered_pdf) {
$pdf = $numbered_pdf;
@ -312,11 +316,15 @@ class PreviewController extends BaseController
private function blankEntity()
{
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
App::forgetInstance('translator');
$t = app('translator');
$t->replace(Ninja::transformTranslations(auth()->user()->company()->settings));
$t->replace(Ninja::transformTranslations($company->settings));
$invitation = InvoiceInvitation::where('company_id', auth()->user()->company()->id)->orderBy('id', 'desc')->first();
$invitation = InvoiceInvitation::where('company_id', $company->id)->orderBy('id', 'desc')->first();
/* If we don't have a valid invitation in the system - create a mock using transactions */
if (! $invitation) {
@ -358,10 +366,13 @@ class PreviewController extends BaseController
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));
}
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
$numbered_pdf = $this->pageNumbering($pdf, auth()->user()->company());
$numbered_pdf = $this->pageNumbering($pdf, $company);
if ($numbered_pdf) {
$pdf = $numbered_pdf;
@ -370,7 +381,7 @@ class PreviewController extends BaseController
return $pdf;
}
$file_path = (new PreviewPdf($maker->getCompiledHTML(true), auth()->user()->company()))->handle();
$file_path = (new PreviewPdf($maker->getCompiledHTML(true), $company))->handle();
$response = Response::make($file_path, 200);
$response->header('Content-Type', 'application/pdf');

View File

@ -188,14 +188,12 @@ class Account extends BaseModel
private $free_plan_email_quota = 20;
private $paid_plan_email_quota = 500;
/**
* @var string
*/
protected $presenter = AccountPresenter::class;
/**
* @var array
*/
protected $fillable = [
'plan',
'plan_term',
@ -454,6 +452,8 @@ class Account extends BaseModel
}
$trial_active = false;
$trial_expires = false;
$trial_started = false;
//14 day trial
$duration = 60*60*24*14;
@ -468,10 +468,11 @@ class Account extends BaseModel
}
$plan_active = false;
$plan_expires = false;
if ($plan) {
if ($this->plan_expires == null) {
$plan_active = true;
$plan_expires = false;
} else {
$plan_expires = Carbon::parse($this->plan_expires);
if ($plan_expires->greaterThan(now())) {
@ -484,7 +485,6 @@ class Account extends BaseModel
return null;
}
// Should we show plan details or trial details?
if (($plan && ! $trial_plan) || ! $include_trial) {
$use_plan = true;
@ -666,10 +666,10 @@ class Account extends BaseModel
$plan_expires = Carbon::parse($this->plan_expires);
if (!$this->payment_id && $plan_expires->gt(now())) {
if ($plan_expires->gt(now())) {
$diff = $plan_expires->diffInDays();
if ($diff > 14);
if ($diff > 14)
return 0;
return $diff;

View File

@ -28,11 +28,16 @@ use Illuminate\Support\Str;
* @method scope() static
* @package App\Models
* @property-read mixed $hashed_id
* @property string $number
* @property int $company_id
* @property \App\Models\Company $company
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel company()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude($columns)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel newModelQuery()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel newQuery()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel query()
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel exclude(array $excludeable)
* @method static \Illuminate\Database\Eloquent\Builder|BaseModel withTrashed()
* @mixin \Eloquent
*/
class BaseModel extends Model
@ -132,39 +137,39 @@ class BaseModel extends Model
// }
// }
public function setSettingsByEntity($entity, $settings)
{
switch ($entity) {
case Client::class:
// public function setSettingsByEntity($entity, $settings)
// {
// switch ($entity) {
// case Client::class:
$this->settings = $settings;
$this->save();
$this->fresh();
break;
case Company::class:
// $this->settings = $settings;
// $this->save();
// $this->fresh();
// break;
// case Company::class:
$this->company->settings = $settings;
$this->company->save();
break;
//todo check that saving any other entity (Invoice:: RecurringInvoice::) settings is valid using the default:
default:
$this->client->settings = $settings;
$this->client->save();
break;
}
}
// $this->company->settings = $settings;
// $this->company->save();
// break;
// //todo check that saving any other entity (Invoice:: RecurringInvoice::) settings is valid using the default:
// default:
// $this->client->settings = $settings;
// $this->client->save();
// break;
// }
// }
/**
* Gets the settings.
*
* Generic getter for client settings
*
* @return ClientSettings The settings.
* @return ClientSettings.
*/
public function getSettings()
{
return new ClientSettings($this->settings);
}
// public function getSettings()
// {
// return new ClientSettings($this->settings);
// }
/**
* Retrieve the model for a bound value.
@ -181,7 +186,6 @@ class BaseModel extends Model
return $this
->withTrashed()
// ->company()
->where('id', $this->decodePrimaryKey($value))->firstOrFail();
}

View File

@ -29,6 +29,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property bool $is_system
* @property-read \App\Models\Account $account
* @property-read \App\Models\Company $company
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Company> $company
* @property-read \App\Models\CompanyUser|null $company_user
* @property-read \App\Models\CompanyUser|null $cu
* @property-read mixed $hashed_id

View File

@ -149,6 +149,7 @@ use Laracasts\Presenter\PresentableTrait;
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyToken> $tokens
* @method bool hasPermissionTo(string $permission)
* @method \App\Models\Company getCompany()
* @method \App\Models\Company company()
* @method bool hasExcludedPermissions(array $matched_permission, array $excluded_permissions)
* @method bool isAdmin()
* @method bool isSuperUser()