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

Updated static analysis

This commit is contained in:
David Bomba 2023-08-07 14:50:08 +10:00
parent 2d8fc80779
commit fb4939c13a
16 changed files with 77 additions and 28 deletions

View File

@ -187,6 +187,7 @@ class ProductSalesExport extends BaseExport
$product = $this->getProduct($entity['product_key']);
$entity['cost'] = $product->cost ?? 0;
/** @var float $unit_cost */
$unit_cost = $entity['cost'] == 0 ? 1 : $entity['cost'];
$entity['client'] = $invoice->client->present()->name();

View File

@ -530,10 +530,9 @@ class BaseController extends Controller
$paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */
$query = $paginator->getCollection(); /** @phpstan-ignore-line */
/** @phpstan-ignore-line */
/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
@ -636,7 +635,7 @@ class BaseController extends Controller
$paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type);
$resource->setPaginator(new IlluminatePaginatorAdapter($paginator));
@ -885,7 +884,7 @@ class BaseController extends Controller
$paginator = $query->paginate($limit);
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
$query = $paginator->getCollection();
$resource = new Collection($query, $transformer, $this->entity_type);

View File

@ -125,7 +125,6 @@ class EmailController extends BaseController
$this->entity_transformer = PurchaseOrderTransformer::class;
}
// @phpstan-ignore-next-line
return $this->itemResponse($entity_obj->fresh());
}

View File

@ -199,7 +199,7 @@ class WepaySignup extends Component
if ($confirmation_required) {
/** @phpstan-ignore-next-line */
/** @phpstan-ignore-next-line **/
request()->session()->flash('message', trans('texts.created_wepay_confirmation_required'));
} else {
$update_uri = $wepay->request('/account/get_update_uri', [

View File

@ -50,7 +50,7 @@ class ContactRegister
'portal_mode' => 'domain',
];
if ($company = Company::where($query)->first()) {
if ($company = Company::query()->where($query)->first()) {
if (! $company->client_can_register) {
abort(400, 'Registration disabled');
}

View File

@ -37,8 +37,9 @@ class PasswordProtection
'errors' => new stdClass,
];
/** @var \App\Models\User auth()->user() */
$timeout = auth()->user()->company()->default_password_timeout;
/** @var \App\Models\User auth()->user() */
$user = auth()->user();
$timeout = $user->company()->default_password_timeout;
if ($timeout == 0) {
$timeout = 30*60*1000*1000;

View File

@ -49,7 +49,7 @@ class VendorContactKeyLogin
$contact_email = $payload['email'];
if ($vendor_contact = VendorContact::where('email', $contact_email)->where('company_id', $payload['company_id'])->first()) {
if ($vendor_contact = VendorContact::query()->where('email', $contact_email)->where('company_id', $payload['company_id'])->first()) {
if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(15).'@example.com';
}
@ -65,7 +65,7 @@ class VendorContactKeyLogin
}
} elseif ($request->segment(3) && config('ninja.db.multi_db_enabled')) {
if (MultiDB::findAndSetDbByVendorContactKey($request->segment(3))) {
if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) {
if ($vendor_contact = VendorContact::query()->where('contact_key', $request->segment(3))->first()) {
if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(6).'@example.com';
}
@ -81,7 +81,7 @@ class VendorContactKeyLogin
}
}
} elseif ($request->segment(2) && $request->segment(2) == 'key_login' && $request->segment(3)) {
if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) {
if ($vendor_contact = VendorContact::query()->where('contact_key', $request->segment(3))->first()) {
if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(6).'@example.com';
$vendor_contact->save();
@ -97,7 +97,7 @@ class VendorContactKeyLogin
}
} elseif ($request->has('vendor_hash') && config('ninja.db.multi_db_enabled')) {
if (MultiDB::findAndSetDbByClientHash($request->input('vendor_hash'))) {
if ($client = Vendor::where('vendor_hash', $request->input('vendor_hash'))->first()) {
if ($client = Vendor::query()->where('vendor_hash', $request->input('vendor_hash'))->first()) {
$primary_contact = $client->primary_contact()->first();
if (empty($primary_contact->email)) {
@ -111,7 +111,7 @@ class VendorContactKeyLogin
}
}
} elseif ($request->has('vendor_hash')) {
if ($client = Vendor::where('vendor_hash', $request->input('vendor_hash'))->first()) {
if ($client = Vendor::query()->where('vendor_hash', $request->input('vendor_hash'))->first()) {
$primary_contact = $client->primary_contact()->first();
if (empty($primary_contact->email)) {
@ -124,7 +124,7 @@ class VendorContactKeyLogin
return redirect($this->setRedirectPath());
}
} elseif ($request->segment(3)) {
if ($vendor_contact = VendorContact::where('contact_key', $request->segment(3))->first()) {
if ($vendor_contact = VendorContact::query()->where('contact_key', $request->segment(3))->first()) {
if (empty($vendor_contact->email)) {
$vendor_contact->email = Str::random(6).'@example.com';
$vendor_contact->save();

View File

@ -18,7 +18,7 @@ class VerifyHash
public function handle($request, Closure $next)
{
if ($request->has('payment_hash')) {
$ph = PaymentHash::with('fee_invoice')->where('hash', $request->payment_hash)->first();
$ph = PaymentHash::query()->with('fee_invoice')->where('hash', $request->payment_hash)->first();
if ($ph) {
auth()->guard('contact')->loginUsingId($ph->fee_invoice->invitations->first()->contact->id, true);

View File

@ -12,7 +12,6 @@
namespace App\Http\Requests\ClientPortal;
use App\Http\Requests\Request;
use Zend\Diactoros\Response\JsonResponse;
class StoreDocumentRequest extends Request
{
@ -35,6 +34,6 @@ class StoreDocumentRequest extends Request
public function response(array $errors)
{
return new JsonResponse(['error' => $errors], 400);
return response()->json(['error' => $errors], 400);
}
}

View File

@ -30,7 +30,9 @@ class StoreCompanyRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->can('create', Company::class);
/** @var \App\Models\User auth()->user */
$user = auth()->user();
return $user->can('create', Company::class);
}
public function rules()
@ -47,7 +49,7 @@ class StoreCompanyRequest extends Request
$rules['portal_domain'] = 'sometimes|url';
} else {
if (Ninja::isHosted()) {
$rules['subdomain'] = ['nullable', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9.-]+[a-zA-Z0-9]$/', new ValidSubdomain($this->all())];
$rules['subdomain'] = ['nullable', 'regex:/^[a-zA-Z0-9][a-zA-Z0-9.-]+[a-zA-Z0-9]$/', new ValidSubdomain()];
} else {
$rules['subdomain'] = 'nullable|alpha_num';
}

View File

@ -52,7 +52,6 @@ class PaymentWebhookRequest extends Request
/**
* Resolve payment hash.
*
* @param string $hash
* @return null|\App\Models\PaymentHash
*/
public function getPaymentHash()

View File

@ -138,7 +138,7 @@ class UpdateRecurringInvoiceRequest extends Request
* off / optin / optout will reset the status of this field to off to allow
* the client to choose whether to auto_bill or not.
*
* @param enum $auto_bill off/always/optin/optout
* @param string $auto_bill off/always/optin/optout
*
* @return bool
*/

View File

@ -106,6 +106,7 @@ use Illuminate\Contracts\Translation\HasLocalePreference;
* @method static \Database\Factories\ClientFactory factory($count = null, $state = [])
* @method static \Illuminate\Database\Eloquent\Builder|Client filter(\App\Filters\QueryFilters $filters)
* @method static \Illuminate\Database\Eloquent\Builder|Client without()
* @method static \Illuminate\Database\Eloquent\Builder|Client find()
* @method static \Illuminate\Database\Eloquent\Builder|Client select()
* @property string $payment_balance
* @property mixed $tax_data

View File

@ -709,9 +709,9 @@ class Invoice extends BaseModel
return ctrans('texts.invoice');
}
public function taxTypeString($id)
public function taxTypeString($id): string
{
$tax_type = false;
$tax_type = '';
match(intval($id)){
Product::PRODUCT_TYPE_PHYSICAL => $tax_type = ctrans('texts.physical_goods'),

View File

@ -38,27 +38,37 @@ class PaymentHash extends Model
'data' => 'object',
];
/**
* @return array
*/
public function invoices()
{
return $this->data->invoices;
}
/**
* @return float|null
*/
public function amount_with_fee()
{
return $this->data->amount_with_fee;
}
/**
* @return float
*/
public function credits_total()
{
return isset($this->data->credits) ? $this->data->credits : 0;
}
public function payment()
public function payment(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Payment::class)->withTrashed();
}
public function fee_invoice()
public function fee_invoice(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Invoice::class, 'fee_invoice_id', 'id')->withTrashed();
}

View File

@ -370,4 +370,42 @@ class PurchaseOrder extends BaseModel
{
return ctrans('texts.purchase_order');
}
public function typeIdString($id): string
{
$type = '';
match($id) {
'1' => $type = ctrans('texts.product'),
'2' => $type = ctrans('texts.service'),
'3' => $type = ctrans('texts.gateway_fees'),
'4' => $type = ctrans('texts.gateway_fees'),
'5' => $type = ctrans('texts.late_fees'),
'6' => $type = ctrans('texts.expense'),
default => $type = ctrans('texts.product'),
};
return $type;
}
public function taxTypeString($id): string
{
$tax_type = '';
match(intval($id)){
Product::PRODUCT_TYPE_PHYSICAL => $tax_type = ctrans('texts.physical_goods'),
Product::PRODUCT_TYPE_SERVICE => $tax_type = ctrans('texts.services'),
Product::PRODUCT_TYPE_DIGITAL => $tax_type = ctrans('texts.digital_products'),
Product::PRODUCT_TYPE_SHIPPING => $tax_type = ctrans('texts.shipping'),
Product::PRODUCT_TYPE_EXEMPT => $tax_type = ctrans('texts.tax_exempt'),
Product::PRODUCT_TYPE_REDUCED_TAX => $tax_type = ctrans('texts.reduced_tax'),
Product::PRODUCT_TYPE_OVERRIDE_TAX => $tax_type = ctrans('texts.override_tax'),
Product::PRODUCT_TYPE_ZERO_RATED => $tax_type = ctrans('texts.zero_rated'),
Product::PRODUCT_TYPE_REVERSE_TAX => $tax_type = ctrans('texts.reverse_tax'),
default => $tax_type = ctrans('texts.physical_goods'),
};
return $tax_type;
}
}