1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Static analysis cleanup

This commit is contained in:
David Bomba 2023-04-27 08:05:57 +10:00
parent 2a926c419b
commit 32c30b195b
7 changed files with 66 additions and 22 deletions

View File

@ -928,7 +928,7 @@ class BaseController extends Controller
/**
* List response
*
* @param Builder $query
* @param Builder $query
*/
protected function listResponse(Builder $query)
{
@ -1011,7 +1011,11 @@ class BaseController extends Controller
}
if (request()->include_static) {
$response['static'] = Statics::company(auth()->user()->getCompany()->getLocale());
/** @var \App\Models\User $user */
$user = auth()->user();
$response['static'] = Statics::company($user->getCompany()->getLocale());
}
}
@ -1042,8 +1046,11 @@ class BaseController extends Controller
$resource = new Item($item, $transformer, $this->entity_type);
if (auth()->user() && request()->include_static) {
$data['static'] = Statics::company(auth()->user()->getCompany()->getLocale());
/** @var \App\Models\User $user */
$user = auth()->user();
if ($user && request()->include_static) {
$data['static'] = Statics::company($user->getCompany()->getLocale());
}
return $this->response($this->manager->createData($resource)->toArray());
@ -1075,7 +1082,11 @@ class BaseController extends Controller
* Thresholds for displaying large account on first load
*/
if (request()->has('first_load') && request()->input('first_load') == 'true') {
if (auth()->user()->getCompany()->is_large && request()->missing('updated_at')) {
/** @var \App\Models\User $user */
$user = auth()->user();
if ($user->getCompany()->is_large && request()->missing('updated_at')) {
$data = $this->mini_load;
} else {
$data = $this->first_load;
@ -1103,7 +1114,11 @@ class BaseController extends Controller
*/
public function flutterRoute()
{
if ((bool) $this->checkAppSetup() !== false && $account = Account::first()) {
/** @var \App\Models\Account $account */
//always redirect invoicing.co to invoicing.co
if (Ninja::isHosted() && !in_array(request()->getSchemeAndHttpHost(), ['https://staging.invoicing.co', 'https://invoicing.co', 'https://demo.invoicing.co', 'https://invoiceninja.net'])) {
return redirect()->secure('https://invoicing.co');

View File

@ -129,10 +129,9 @@ class PreviewController extends BaseController
}
/** @var App\Models\User auth()->user() */
/** @var \App\Models\User $user */
$user = auth()->user();
/** @var \App\Models\Company $company */
$company = $user->company();
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
@ -158,8 +157,11 @@ class PreviewController extends BaseController
public function design(DesignPreviewRequest $request)
{
/** @var \App\Models\User $user */
$user = auth()->user();
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
$company = $user->company();
$pdf = (new PdfMock($request->all(), $company))->build()->getPdf();
@ -175,8 +177,10 @@ class PreviewController extends BaseController
return response()->json(['message' => 'This server cannot handle this request.'], 400);
}
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
/** @var \App\Models\User $user */
$user = auth()->user();
$company = $user->company();
MultiDB::setDb($company->db);
@ -202,6 +206,8 @@ class PreviewController extends BaseController
DB::connection(config('database.default'))->beginTransaction();
if ($request->has('entity_id')) {
/** @var \App\Models\BaseModel $class */
$entity_obj = $class::on(config('database.default'))
->with('client.company')
->where('id', $this->decodePrimaryKey($request->input('entity_id')))
@ -288,8 +294,11 @@ class PreviewController extends BaseController
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));
}
/** @var \App\Models\User $user */
$user = auth()->user();
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
$company = $user->company();
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
@ -320,8 +329,11 @@ class PreviewController extends BaseController
private function blankEntity()
{
/** @var \App\Models\User $user */
$user = auth()->user();
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
$company = $user->company();
App::forgetInstance('translator');
$t = app('translator');
@ -369,8 +381,11 @@ class PreviewController extends BaseController
return (new Phantom)->convertHtmlToPdf($maker->getCompiledHTML(true));
}
/** @var \App\Models\User $user */
$user = auth()->user();
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
$company = $user->company();
if (config('ninja.invoiceninja_hosted_pdf_generation') || config('ninja.pdf_generator') == 'hosted_ninja') {
$pdf = (new NinjaPdf())->build($maker->getCompiledHTML(true));
@ -394,8 +409,12 @@ class PreviewController extends BaseController
private function mockEntity()
{
/** @var \App\Models\User $user */
$user = auth()->user();
/** @var \App\Models\Company $company */
$company = auth()->user()->company();
$company = $user->company();
DB::connection($company->db)->beginTransaction();

View File

@ -580,10 +580,10 @@ class NinjaMailerJob implements ShouldQueue
/**
* Attempts to refresh the Microsoft refreshToken
*
* @param App\Models\User
* @return string | boool
* @param \App\Models\User $user
* @return mixed
*/
private function refreshOfficeToken($user)
private function refreshOfficeToken(User $user)
{
$expiry = $user->oauth_user_token_expiry ?: now()->subDay();

View File

@ -130,6 +130,7 @@ use Laracasts\Presenter\PresentableTrait;
* @method static \Illuminate\Database\Eloquent\Builder|Account whereUtmMedium($value)
* @method static \Illuminate\Database\Eloquent\Builder|Account whereUtmSource($value)
* @method static \Illuminate\Database\Eloquent\Builder|Account whereUtmTerm($value)
* @method static \Illuminate\Database\Eloquent\Builder|Account first()
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\BankIntegration> $bank_integrations
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Company> $companies
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\CompanyUser> $company_users

View File

@ -100,7 +100,10 @@ class BaseModel extends Model
*/
public function scopeCompany($query)
{
$query->where('company_id', auth()->user()->companyId());
/** @var \App\Models\User $user */
$user = auth()->user();
$query->where('company_id', $user->companyId());
return $query;
}
@ -110,7 +113,10 @@ class BaseModel extends Model
*/
public function scopeScope($query)
{
$query->where($this->getTable().'.company_id', '=', auth()->user()->company()->id);
/** @var \App\Models\User $user */
$user = auth()->user();
$query->where($this->getTable().'.company_id', '=', $user->company()->id);
return $query;
}

View File

@ -11,6 +11,8 @@
namespace App\Models\Traits;
use Illuminate\Support\Facades\Schema;
/**
* @template TModelClass of \Illuminate\Database\Eloquent\Model
* @extends \Illuminate\Database\Eloquent\Builder<TModelClass>
@ -25,7 +27,7 @@ trait Excludable
*/
private function getTableColumns()
{
/** @var \Illuminate\Database\Eloquent\Builder|\App\Models\BaseModel $this */
/** @var Schema|\App\Models\BaseModel $this */
return $this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable());
}
@ -34,11 +36,11 @@ trait Excludable
* @param Builder $query
* @param array $columns
*
* @return \Illuminate\Database\Eloquent\Builder|static
* @return Builder<BaseModel>
*/
public function scopeExclude($query, $columns): \Illuminate\Database\Eloquent\Builder
{
/** @var Builder|static $query */
/** @var \Illuminate\Database\Eloquent\Builder|static $query */
return $query->select(array_diff($this->getTableColumns(), (array) $columns));
}
}

View File

@ -53,6 +53,7 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @method static \Illuminate\Database\Eloquent\Builder|Webhook whereUserId($value)
* @method static \Illuminate\Database\Eloquent\Builder|Webhook withTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Webhook withoutTrashed()
* @method static \Illuminate\Database\Eloquent\Builder|Webhook where()
* @mixin \Eloquent
*/
class Webhook extends BaseModel