1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 00:11:35 +02:00

Updated static analysis

This commit is contained in:
David Bomba 2023-08-07 15:07:52 +10:00
parent fb4939c13a
commit 01cc61b586
19 changed files with 81 additions and 49 deletions

View File

@ -226,8 +226,10 @@ class InvoiceItemSumInclusive
$amount = $this->item->line_total - ($this->item->line_total * ($this->invoice->discount / 100));
/** @var float $item_tax_rate1_total */
$item_tax_rate1_total = $this->calcInclusiveLineTax($this->item->tax_rate1, $amount);
/** @var float $item_tax */
$item_tax += $this->formatValue($item_tax_rate1_total, $this->currency->precision);
if (strlen($this->item->tax_name1) > 1) {

View File

@ -34,7 +34,7 @@ class GmailTransport extends AbstractTransport
$message = MessageConverter::toEmail($message->getOriginalMessage());
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
$token = $message->getHeaders()->get('gmailtoken')->getValue();
$message->getHeaders()->remove('gmailtoken');
@ -55,7 +55,7 @@ class GmailTransport extends AbstractTransport
$bcc_list = 'Bcc: ';
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
foreach ($bccs->getAddresses() as $address) {
$bcc_list .= $address->getAddress() .',';
}

View File

@ -157,6 +157,8 @@ class NinjaPlanController extends Controller
//create recurring invoice
$subscription_repo = new SubscriptionRepository();
/** @var \App\Models\Subscription $subscription **/
$subscription = Subscription::find(6);
$recurring_invoice = RecurringInvoiceFactory::create($subscription->company_id, $subscription->user_id);
@ -215,7 +217,7 @@ class NinjaPlanController extends Controller
$data['late_invoice'] = false;
if (MultiDB::findAndSetDbByAccountKey(Auth::guard('contact')->user()->client->custom_value2)) {
$account = Account::where('key', Auth::guard('contact')->user()->client->custom_value2)->first();
$account = Account::query()->where('key', Auth::guard('contact')->user()->client->custom_value2)->first();
if ($account) {
//offer the option to have a free trial

View File

@ -53,7 +53,7 @@ class BillingPortalPurchasev2 extends Component
/**
* Instance of subscription.
*
* @var Subscription
* @var \App\Models\Subscription
*/
public $subscription;

View File

@ -121,7 +121,7 @@ class ContactKeyLogin
}
}
} elseif ($request->has('client_hash')) {
if ($client = Client::where('client_hash', $request->input('client_hash'))->first()) {
if ($client = Client::query()->where('client_hash', $request->input('client_hash'))->first()) {
$primary_contact = $client->primary_contact()->first();
if (empty($primary_contact->email)) {
@ -134,7 +134,7 @@ class ContactKeyLogin
return redirect($this->setRedirectPath());
}
} elseif ($request->segment(3)) {
if ($client_contact = ClientContact::with('company')->where('contact_key', $request->segment(3))->first()) {
if ($client_contact = ClientContact::query()->with('company')->where('contact_key', $request->segment(3))->first()) {
if ($client_contact->company->settings->enable_client_portal_password) {
return redirect()->route('client.login', ['company_key' => $client_contact->company->company_key]);
}

View File

@ -65,7 +65,7 @@ class ContactRegister
// For self-hosted platforms with multiple companies, resolving is done using company key
// if it doesn't resolve using a domain.
if ($request->company_key && Ninja::isSelfHost() && $company = Company::where('company_key', $request->company_key)->first()) {
if ($request->company_key && Ninja::isSelfHost() && $company = Company::query()->where('company_key', $request->company_key)->first()) {
if (! (bool) $company->client_can_register) {
abort(400, 'Registration disabled');
}
@ -79,6 +79,7 @@ class ContactRegister
// As a fallback for self-hosted, it will use default company in the system
// if key isn't provided in the url.
if (! $request->route()->parameter('company_key') && Ninja::isSelfHost()) {
/** @var \App\Models\Company $company */
$company = Account::first()->default_company;
if (! $company->client_can_register) {

View File

@ -66,14 +66,15 @@ class RegisterRequest extends FormRequest
{
//this should be all we need, the rest SHOULD be redundant because of our Middleware
if ($this->key) {
return Company::where('company_key', $this->key)->first();
return Company::query()->where('company_key', $this->key)->first();
}
if ($this->company_key) {
return Company::where('company_key', $this->company_key)->firstOrFail();
return Company::query()->where('company_key', $this->company_key)->firstOrFail();
}
if (! $this->route()->parameter('company_key') && Ninja::isSelfHost()) {
/** @var \App\Models\Company $company */
$company = Account::first()->default_company;
if (! $company->client_can_register) {

View File

@ -39,7 +39,6 @@ class PaymentWebhookRequest extends Request
/**
* Resolve company gateway.
*
* @param mixed $id
* @return null|\App\Models\CompanyGateway
*/
public function getCompanyGateway()

View File

@ -31,7 +31,11 @@ class StoreRecurringInvoiceRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->can('create', RecurringInvoice::class);
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
return $user->can('create', RecurringInvoice::class);
}
public function rules()
@ -137,6 +141,7 @@ class StoreRecurringInvoiceRequest extends Request
if (isset($input['auto_bill'])) {
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} else {
/** @var \App\Models\Client $client */
if (array_key_exists('client_id', $input) && $client = Client::find($input['client_id'])) {
$input['auto_bill'] = $client->getSetting('auto_bill');
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);

View File

@ -31,11 +31,17 @@ class UpdateRecurringInvoiceRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->can('edit', $this->recurring_invoice);
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
return $user->can('edit', $this->recurring_invoice);
}
public function rules()
{
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
$rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) {
@ -51,7 +57,7 @@ class UpdateRecurringInvoiceRequest extends Request
}
if ($this->number) {
$rules['number'] = Rule::unique('recurring_invoices')->where('company_id', auth()->user()->company()->id)->ignore($this->recurring_invoice->id);
$rules['number'] = Rule::unique('recurring_invoices')->where('company_id', $user->company()->id)->ignore($this->recurring_invoice->id);
}
$rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())];

View File

@ -30,11 +30,19 @@ class StoreRecurringQuoteRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->can('create', RecurringQuote::class);
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
return $user->can('create', RecurringQuote::class);
}
public function rules()
{
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
$rules = [];
if ($this->file('documents') && is_array($this->file('documents'))) {
@ -49,7 +57,7 @@ class StoreRecurringQuoteRequest extends Request
$rules['file'] = $this->file_validation;
}
$rules['client_id'] = 'required|exists:clients,id,company_id,'.auth()->user()->company()->id;
$rules['client_id'] = 'required|exists:clients,id,company_id,'.$user->company()->id;
$rules['invitations.*.client_contact_id'] = 'distinct';
@ -71,6 +79,7 @@ class StoreRecurringQuoteRequest extends Request
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
} else {
if ($client = Client::find($input['client_id'])) {
/** @var \App\Models\Client $client */
$input['auto_bill'] = $client->getSetting('auto_bill');
$input['auto_bill_enabled'] = $this->setAutoBillFlag($input['auto_bill']);
}

View File

@ -26,6 +26,9 @@ class ShowDocumentRequest extends FormRequest
*/
public function authorize()
{
/** @var \App\Models\VendorContact auth()->guard('vendor')->user() */
return auth()->guard('vendor')->user()->client_id == $this->document->documentable_id
|| $this->document->company_id == auth()->guard('vendor')->user()->company_id;
}

View File

@ -21,7 +21,7 @@ class CanStoreClientsRule implements Rule
{
public $company_id;
public $company;
public \App\Models\Company $company;
public function __construct($company_id)
{

View File

@ -26,7 +26,10 @@ class ValidUserForCompany implements Rule
*/
public function passes($attribute, $value)
{
return MultiDB::checkUserAndCompanyCoExist($value, auth()->user()->company()->company_key, auth()->user()->company()->id);
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
return MultiDB::checkUserAndCompanyCoExist($value, $user->company()->company_key);
}
/**

View File

@ -95,7 +95,7 @@ class BaseImport
ini_set('auto_detect_line_endings', '1');
}
/** @var strin $base64_encoded_csv */
/** @var string $base64_encoded_csv */
$base64_encoded_csv = Cache::pull($this->hash.'-'.$entity_type);
if (empty($base64_encoded_csv)) {

View File

@ -189,7 +189,7 @@ class Wave extends BaseImport implements ImportInterface
$this->transformer = new ExpenseTransformer($this->company);
$expense_count = $this->ingestExpenses($data, $entity_type);
$expense_count = $this->ingestExpenses($data);
$this->entity_count['expenses'] = $expense_count;
}
@ -200,7 +200,7 @@ class Wave extends BaseImport implements ImportInterface
private function groupExpenses($csvData)
{
$grouped_expense = [];
$grouped = [];
$key = 'Transaction ID';
foreach ($csvData as $expense) {

View File

@ -176,7 +176,7 @@ class BaseTransformer
public function getClient($client_name, $client_email)
{
if (! empty($client_name)) {
$client_id_search = Client::where('company_id', $this->company->id)
$client_id_search = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->where('id_number', $client_name);
@ -184,7 +184,7 @@ class BaseTransformer
return $client_id_search->first()->id;
}
$client_name_search = Client::where('company_id', $this->company->id)
$client_name_search = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $client_name)),
@ -195,7 +195,7 @@ class BaseTransformer
}
}
if (! empty($client_email)) {
$contacts = ClientContact::whereHas('client', function ($query) {
$contacts = ClientContact::query()->whereHas('client', function ($query) {
$query->where('is_deleted', false);
})
->where('company_id', $this->company->id)
@ -238,7 +238,7 @@ class BaseTransformer
*/
public function hasClient($name)
{
return Client::where('company_id', $this->company->id)
return Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -248,7 +248,7 @@ class BaseTransformer
public function hasClientIdNumber($id_number)
{
return Client::where('company_id', $this->company->id)
return Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->where('id_number', trim($id_number))
->exists();
@ -262,7 +262,7 @@ class BaseTransformer
*/
public function hasVendor($name)
{
return Vendor::where('company_id', $this->company->id)
return Vendor::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -277,7 +277,7 @@ class BaseTransformer
*/
public function hasProject($name)
{
return Project::where('company_id', $this->company->id)
return Project::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -292,7 +292,7 @@ class BaseTransformer
*/
public function hasProduct($key)
{
return Product::where('company_id', $this->company->id)
return Product::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $key)),
@ -341,7 +341,7 @@ class BaseTransformer
*/
public function getClientId($name)
{
$client = Client::where('company_id', $this->company->id)
$client = Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -358,7 +358,7 @@ class BaseTransformer
*/
public function getProduct($key)
{
$product = Product::where('company_id', $this->company->id)
$product = Product::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`product_key`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $key)),
@ -375,7 +375,7 @@ class BaseTransformer
*/
public function getContact($email): ?ClientContact
{
$contact = ClientContact::where('company_id', $this->company->id)
$contact = ClientContact::query()->where('company_id', $this->company->id)
->whereRaw("LOWER(REPLACE(`email`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $email)),
])
@ -400,7 +400,7 @@ class BaseTransformer
return $this->getCountryIdBy2($name);
}
$country = Country::whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
$country = Country::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])->first();
@ -414,8 +414,8 @@ class BaseTransformer
*/
public function getCountryIdBy2($name)
{
return Country::where('iso_3166_2', $name)->exists()
? Country::where('iso_3166_2', $name)->first()->id
return Country::query()->where('iso_3166_2', $name)->exists()
? Country::query()->where('iso_3166_2', $name)->first()->id
: null;
}
@ -428,7 +428,7 @@ class BaseTransformer
{
$name = strtolower(trim($name));
$tax_rate = TaxRate::where('company_id', $this->company->id)
$tax_rate = TaxRate::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -447,7 +447,7 @@ class BaseTransformer
{
$name = strtolower(trim($name));
$tax_rate = TaxRate::where('company_id', $this->company->id)
$tax_rate = TaxRate::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -495,7 +495,7 @@ class BaseTransformer
*/
public function getInvoiceId($invoice_number)
{
$invoice = Invoice::where('company_id', $this->company->id)
$invoice = Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
@ -512,7 +512,7 @@ class BaseTransformer
*/
public function hasInvoice($invoice_number)
{
return Invoice::where('company_id', $this->company->id)
return Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
@ -528,7 +528,7 @@ class BaseTransformer
*/
public function hasRecurringInvoice($invoice_number)
{
return RecurringInvoice::where('company_id', $this->company->id)
return RecurringInvoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
@ -541,7 +541,7 @@ class BaseTransformer
*/
public function hasExpense($expense_number)
{
return Expense::where('company_id', $this->company->id)
return Expense::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $expense_number)),
@ -556,7 +556,7 @@ class BaseTransformer
*/
public function hasQuote($quote_number)
{
return Quote::where('company_id', $this->company->id)
return Quote::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $quote_number)),
@ -571,7 +571,7 @@ class BaseTransformer
*/
public function getInvoiceClientId($invoice_number)
{
$invoice = Invoice::where('company_id', $this->company->id)
$invoice = Invoice::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`number`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $invoice_number)),
@ -588,7 +588,7 @@ class BaseTransformer
*/
public function getVendorId($name)
{
$vendor = Vendor::where('company_id', $this->company->id)
$vendor = Vendor::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -626,7 +626,7 @@ class BaseTransformer
{
/** @var \App\Models\ExpenseCategory $ec */
$ec = ExpenseCategory::where('company_id', $this->company->id)
$ec = ExpenseCategory::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -669,7 +669,7 @@ class BaseTransformer
*/
public function getProjectId($name, $clientId = null)
{
$project = Project::where('company_id', $this->company->id)
$project = Project::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
@ -700,7 +700,7 @@ class BaseTransformer
*/
public function getPaymentTypeId($name)
{
$pt = PaymentType::whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
$pt = PaymentType::query()->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $name)),
])->first();

View File

@ -102,7 +102,7 @@ class InvoiceTransformer extends BaseTransformer
$client_name = $this->getString($invoice_data, 'Customer Name');
if(strlen($client_name) >= 2) {
$client_name_search = \App\Models\Client::where('company_id', $this->company->id)
$client_name_search = \App\Models\Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->whereRaw("LOWER(REPLACE(`name`, ' ' ,'')) = ?", [
strtolower(str_replace(' ', '', $client_name)),
@ -115,7 +115,7 @@ class InvoiceTransformer extends BaseTransformer
$customer_id = $this->getString($invoice_data, 'Customer ID');
$client_id_search = \App\Models\Client::where('company_id', $this->company->id)
$client_id_search = \App\Models\Client::query()->where('company_id', $this->company->id)
->where('is_deleted', false)
->where('id_number', trim($customer_id));

View File

@ -200,6 +200,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
* @property-read int|null $vendors_count
* @property-read \Illuminate\Database\Eloquent\Collection<int, \App\Models\Webhook> $webhooks
* @method static \Illuminate\Database\Eloquent\Builder|Company where($query)
* @method static \Illuminate\Database\Eloquent\Builder|Company find($query)
* @property-read int|null $webhooks_count
* @property int $calculate_taxes
* @property mixed $tax_data