Convert optional() to nullsafe operator

This commit is contained in:
Shift 2022-06-21 09:59:25 +00:00
parent e0a8e84108
commit 0a20889916
No known key found for this signature in database
GPG Key ID: 5A96F038425C5A1C
26 changed files with 80 additions and 80 deletions

View File

@ -64,7 +64,7 @@ class RecurringInvoiceController extends Controller
{
nlog('outside cancellation');
if (optional($recurring_invoice->subscription)->allow_cancellation) {
if ($recurring_invoice->subscription?->allow_cancellation) {
nlog('inside the cancellation');
$nmo = new NinjaMailerObject;

View File

@ -62,7 +62,7 @@ class ACH implements MethodInterface
],
]);
if ($result->success && optional($result->paymentMethod)->verified) {
if ($result->success && $result->paymentMethod?->verified) {
$account = $result->paymentMethod;
try {

View File

@ -25,7 +25,7 @@
data-token="{{ $token->token }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -247,7 +247,7 @@ class Design extends BaseDesign
['element' => 'span', 'content' => "{$this->client->shipping_state} ", 'properties' => ['ref' => 'delivery_note-client.shipping_state']],
['element' => 'span', 'content' => "{$this->client->shipping_postal_code} ", 'properties' => ['ref' => 'delivery_note-client.shipping_postal_code']],
]],
['element' => 'p', 'content' => optional($this->client->shipping_country)->name, 'show_empty' => false],
['element' => 'p', 'content' => $this->client->shipping_country?->name, 'show_empty' => false],
];
if (! is_null($this->context['contact'])) {

View File

@ -87,57 +87,57 @@ class CustomMessage
private function compose(): array
{
return [
'$company.id' => optional($this->company)->id,
'$company.name' => optional($this->company)->getSetting('name'),
'$company.website' => optional($this->company)->getSetting('website'),
'$company.id' => $this->company?->id,
'$company.name' => $this->company?->getSetting('name'),
'$company.website' => $this->company?->getSetting('website'),
'$client.id' => optional($this->client)->id,
'$client.name' => optional($this->client)->name,
'$client.website' => optional($this->client)->website,
'$client.public_notes' => optional($this->client)->public_notes,
'$client.phone' => optional($this->client)->phone,
'$client.balance' => optional($this->client)->balance,
'$client.address1' => optional(optional($this->client)->present())->address1,
'$client.address2' => optional(optional($this->client)->present())->address2,
'$client.city' => optional(optional($this->client)->present())->city,
'$client.state' => optional(optional($this->client)->present())->state,
'$client.postal_code' => optional(optional($this->client)->present())->postal_code,
'$client.country' => optional(optional(optional($this->client)->present())->country)->full_name,
'$client.address' => optional(optional($this->client)->present())->address(),
'$client.shipping_address' => optional(optional($this->client)->present())->shipping_address(),
'$client.primary_contact_name' => optional(optional($this->client)->present())->primary_contact_name(),
'$client.city_state' => optional(optional($this->client)->present())->getCityState(),
'$client.id' => $this->client?->id,
'$client.name' => $this->client?->name,
'$client.website' => $this->client?->website,
'$client.public_notes' => $this->client?->public_notes,
'$client.phone' => $this->client?->phone,
'$client.balance' => $this->client?->balance,
'$client.address1' => $this->client?->present()?->address1,
'$client.address2' => $this->client?->present()?->address2,
'$client.city' => $this->client?->present()?->city,
'$client.state' => $this->client?->present()?->state,
'$client.postal_code' => $this->client?->present()?->postal_code,
'$client.country' => $this->client?->present()?->country?->full_name,
'$client.address' => $this->client?->present()?->address(),
'$client.shipping_address' => $this->client?->present()?->shipping_address(),
'$client.primary_contact_name' => $this->client?->present()?->primary_contact_name(),
'$client.city_state' => $this->client?->present()?->getCityState(),
'$contact.first_name' => optional($this->contact)->first_name,
'$contact.last_name' => optional($this->contact)->last_name,
'$contact.phone' => optional($this->contact)->phone,
'$contact.email' => optional($this->contact)->email,
'$contact.avatar' => optional($this->contact)->avatar,
'$contact.first_name' => $this->contact?->first_name,
'$contact.last_name' => $this->contact?->last_name,
'$contact.phone' => $this->contact?->phone,
'$contact.email' => $this->contact?->email,
'$contact.avatar' => $this->contact?->avatar,
'$group.id' => optional($this->group)->id,
'$group.id' => $this->group?->id,
'$entity.id' => optional($this->entity)->hashed_id,
'$entity.number' => optional($this->entity)->number,
'$entity.discount' => optional($this->entity)->discount,
'$entity.date' => optional($this->entity)->date, // Todo: Handle formatDate
'$entity.due_date' => optional($this->entity)->due_date, // Todo: Handle formatDate
'$entity.last_sent_date' => optional($this->entity)->last_sent_date,
'$entity.public_notes' => optional($this->entity)->public_notes,
'$entity.terms' => optional($this->entity)->terms,
'$entity.amount' => optional($this->entity)->amount, // Todo: Handle moneyformat
'$entity.balance' => optional($this->entity)->balance, // Todo: Handle moneyformat
'$entity.created_at' => optional($this->entity)->created_at, // Todo: Handle formatDate
'$entity.id' => $this->entity?->hashed_id,
'$entity.number' => $this->entity?->number,
'$entity.discount' => $this->entity?->discount,
'$entity.date' => $this->entity?->date, // Todo: Handle formatDate
'$entity.due_date' => $this->entity?->due_date, // Todo: Handle formatDate
'$entity.last_sent_date' => $this->entity?->last_sent_date,
'$entity.public_notes' => $this->entity?->public_notes,
'$entity.terms' => $this->entity?->terms,
'$entity.amount' => $this->entity?->amount, // Todo: Handle moneyformat
'$entity.balance' => $this->entity?->balance, // Todo: Handle moneyformat
'$entity.created_at' => $this->entity?->created_at, // Todo: Handle formatDate
'$entity.status' => optional(optional($this->entity))->badgeForStatus(optional($this->entity)->status_id), // It would be nice if we have method that will only return status as text, not with markup.
'$entity.project' => optional(optional($this->entity)->project)->name,
'$entity.project.date' => optional(optional($this->entity)->project)->date,
'$entity.status' => optional(optional($this->entity))->badgeForStatus($this->entity?->status_id), // It would be nice if we have method that will only return status as text, not with markup.
'$entity.project' => $this->entity?->project?->name,
'$entity.project.date' => $this->entity?->project?->date,
'$invitation.id' => optional($this->invitation)->id,
'$invitation.user.first_name' => optional(optional($this->invitation)->user)->first_name,
'$invitation.user.last_name' => optional(optional($this->invitation)->user)->last_name,
'$invitation.sent_date' => optional($this->invitation)->sent_date, // Todo: Handle formatDate
'$invitation.viewed_date' => optional($this->invitation)->viewed_date, // Todo: Handle formatDate,
'$invitation.opened_date' => optional($this->invitation)->opened_date, // Todo: Handle formatDate,
'$invitation.id' => $this->invitation?->id,
'$invitation.user.first_name' => $this->invitation?->user?->first_name,
'$invitation.user.last_name' => $this->invitation?->user?->last_name,
'$invitation.sent_date' => $this->invitation?->sent_date, // Todo: Handle formatDate
'$invitation.viewed_date' => $this->invitation?->viewed_date, // Todo: Handle formatDate,
'$invitation.opened_date' => $this->invitation?->opened_date, // Todo: Handle formatDate,
];
}
}

View File

@ -372,7 +372,7 @@ class HtmlEngine
$data['$client.currency'] = ['value' => $this->client->currency()->code, 'label' => ''];
$data['$client.lang_2'] = ['value' => optional($this->client->language())->locale, 'label' => ''];
$data['$client.lang_2'] = ['value' => $this->client->language()?->locale, 'label' => ''];
$data['$client.balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];
$data['$client_balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];
@ -520,8 +520,8 @@ class HtmlEngine
$data['$payment_url'] = &$data['$payment_link'];
$data['$portalButton'] = &$data['$paymentLink'];
$data['$dir'] = ['value' => optional($this->client->language())->locale === 'ar' ? 'rtl' : 'ltr', 'label' => ''];
$data['$dir_text_align'] = ['value' => optional($this->client->language())->locale === 'ar' ? 'right' : 'left', 'label' => ''];
$data['$dir'] = ['value' => $this->client->language()?->locale === 'ar' ? 'rtl' : 'ltr', 'label' => ''];
$data['$dir_text_align'] = ['value' => $this->client->language()?->locale === 'ar' ? 'right' : 'left', 'label' => ''];
$data['$payment.date'] = ['value' => '&nbsp;', 'label' => ctrans('texts.payment_date')];
$data['$method'] = ['value' => '&nbsp;', 'label' => ctrans('texts.method')];

View File

@ -290,9 +290,9 @@ trait MakesInvoiceValues
$helpers = new Helpers();
$_table_type = ltrim($table_type, '$'); // From $product -> product.
$data[$key][$table_type.'.product_key'] = is_null(optional($item)->product_key) ? $item->item : $item->product_key;
$data[$key][$table_type.'.item'] = is_null(optional($item)->item) ? $item->product_key : $item->item;
$data[$key][$table_type.'.service'] = is_null(optional($item)->service) ? $item->product_key : $item->service;
$data[$key][$table_type.'.product_key'] = is_null($item?->product_key) ? $item->item : $item->product_key;
$data[$key][$table_type.'.item'] = is_null($item?->item) ? $item->product_key : $item->item;
$data[$key][$table_type.'.service'] = is_null($item?->service) ? $item->product_key : $item->service;
$data[$key][$table_type.'.notes'] = Helpers::processReservedKeywords($item->notes, $entity);
$data[$key][$table_type.'.description'] = Helpers::processReservedKeywords($item->notes, $entity);
@ -354,7 +354,7 @@ trait MakesInvoiceValues
$data[$key][$table_type.'.tax3'] = &$data[$key][$table_type.'.tax_rate3'];
}
$data[$key]['task_id'] = optional($item)->task_id;
$data[$key]['task_id'] = $item?->task_id;
}
return $data;

View File

@ -383,8 +383,8 @@ class VendorHtmlEngine
$data['$autoBill'] = ['value' => ctrans('texts.auto_bill_notification_placeholder'), 'label' => ''];
$data['$auto_bill'] = &$data['$autoBill'];
$data['$dir'] = ['value' => optional($this->company->language())->locale === 'ar' ? 'rtl' : 'ltr', 'label' => ''];
$data['$dir_text_align'] = ['value' => optional($this->company->language())->locale === 'ar' ? 'right' : 'left', 'label' => ''];
$data['$dir'] = ['value' => $this->company->language()?->locale === 'ar' ? 'rtl' : 'ltr', 'label' => ''];
$data['$dir_text_align'] = ['value' => $this->company->language()?->locale === 'ar' ? 'right' : 'left', 'label' => ''];
$data['$payment.date'] = ['value' => '&nbsp;', 'label' => ctrans('texts.payment_date')];
$data['$method'] = ['value' => '&nbsp;', 'label' => ctrans('texts.method')];

View File

@ -70,7 +70,7 @@
{{ App\Models\GatewayType::getAlias($payment_method->gateway_type_id) }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm leading-5 text-gray-500">
{{ ucfirst(optional($payment_method->meta)->brand) }}
{{ ucfirst($payment_method->meta?->brand) }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm leading-5 text-gray-500">
@if(isset($payment_method->meta->exp_month) && isset($payment_method->meta->exp_year))

View File

@ -44,10 +44,10 @@
{{ \Illuminate\Support\Str::limit($task->description, 80) }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm leading-5 text-gray-500">
{{ optional($task->project)->name }}
{{ $task->project?->name }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm leading-5 text-gray-500">
{{ optional($task->status)->name }}
{{ $task->status?->name }}
</td>
<td class="px-6 py-4 whitespace-nowrap text-sm leading-5 text-gray-500">
{{ \Carbon\CarbonInterval::seconds($task->calcDuration())->cascade()->forHumans() }}

View File

@ -1,6 +1,6 @@
<style>
:root {
--primary-color: {{ isset($settings) ? optional($settings)->primary_color : '#1c64f2' }};
--primary-color: {{ isset($settings) ? $settings?->primary_color : '#1c64f2' }};
}
.bg-primary {

View File

@ -41,7 +41,7 @@
data-token="{{ $token->hashed_id }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -43,7 +43,7 @@
data-token="{{ $token->token }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -39,7 +39,7 @@
data-token="{{ $token->token }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">{{ optional($token->meta)->email }}</span>
<span class="ml-1 cursor-pointer">{{ $token->meta?->email }}</span>
</label>
@endforeach
@endisset

View File

@ -43,7 +43,7 @@
data-token="{{ $token->hashed_id }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -35,7 +35,7 @@ ctrans('texts.credit_card')])
<label class="mr-4">
<input type="radio" data-token="{{ $token->token }}" name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token" />
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -38,7 +38,7 @@ ctrans('texts.credit_card')])
<label class="mr-4">
<input type="radio" data-token="{{ $token->token }}" name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token" />
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endif

View File

@ -36,7 +36,7 @@
data-token="{{ $token->token }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -35,7 +35,7 @@
<label class="mr-4">
<input type="radio" data-token="{{ $token->hashed_id }}" name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token" />
<span class="ml-1 cursor-pointer">{{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">{{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -40,7 +40,7 @@
<label class="mr-4">
<input type="radio" data-token="{{ $token->token }}" name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token" />
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -57,7 +57,7 @@
data-token="{{ $token->token }}"
name="payment-type"
class="form-check-input text-indigo-600 rounded-full cursor-pointer toggle-payment-with-token toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
</li>
@endforeach

View File

@ -45,7 +45,7 @@
<label class="mr-4">
<input type="radio" data-token="{{ $token->token }}" name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token" />
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -47,7 +47,7 @@
data-token="{{ $token->token }}"
name="payment-type"
class="form-radio cursor-pointer toggle-payment-with-token"/>
<span class="ml-1 cursor-pointer">**** {{ optional($token->meta)->last4 }}</span>
<span class="ml-1 cursor-pointer">**** {{ $token->meta?->last4 }}</span>
</label>
@endforeach
@endisset

View File

@ -31,8 +31,8 @@
{{ ctrans('texts.type') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ optional($payment_method->meta)->brand }}
{{ optional($payment_method->meta)->scheme }}
{{ $payment_method->meta?->brand }}
{{ $payment_method->meta?->scheme }}
</dd>
</div>
@endif
@ -84,7 +84,7 @@
</div>
</div>
@if((optional($payment_method->meta)->state === 'unauthorized' || optional($payment_method->meta)->state === 'pending') && $payment_method->gateway_type_id === \App\Models\GatewayType::BANK_TRANSFER)
@if(($payment_method->meta?->state === 'unauthorized' || $payment_method->meta?->state === 'pending') && $payment_method->gateway_type_id === \App\Models\GatewayType::BANK_TRANSFER)
<div class="mt-4 mb-4 bg-white shadow sm:rounded-lg">
<div class="px-4 py-5 sm:p-6">
<div class="sm:flex sm:items-start sm:justify-between">

View File

@ -49,13 +49,13 @@
</div>
@endif
@if(!empty(optional($payment->type)->name) && !is_null(optional($payment->type)->name))
@if(!empty($payment->type?->name) && !is_null($payment->type?->name))
<div class="px-4 py-5 bg-white sm:grid sm:grid-cols-3 sm:gap-4 sm:px-6">
<dt class="text-sm font-medium leading-5 text-gray-500">
{{ ctrans('texts.method') }}
</dt>
<dd class="mt-1 text-sm leading-5 text-gray-900 sm:mt-0 sm:col-span-2">
{{ optional($payment->type)->name }}
{{ $payment->type?->name }}
</dd>
</div>
@endif

View File

@ -76,7 +76,7 @@
</div>
@endif
@if($invoice->subscription && optional($invoice->subscription)->allow_cancellation)
@if($invoice->subscription && $invoice->subscription?->allow_cancellation)
{{-- INV2-591 --}}
{{-- @if(false) --}}
<div class="bg-white shadow sm:rounded-lg mt-4">