1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

PHP 7.2 issues: count(): Parameter must be an array or an object that implements Countable #1767

This commit is contained in:
Hillel Coren 2018-01-16 15:48:56 +02:00
parent c40cf27af9
commit 6ab5ae0df3
21 changed files with 56 additions and 85 deletions

View File

@ -73,7 +73,7 @@ class ChargeRenewalInvoices extends Command
->orderBy('id')
->get();
$this->info(count($invoices).' invoices found');
$this->info($invoices->count() . ' invoices found');
foreach ($invoices as $invoice) {

View File

@ -122,9 +122,9 @@ class CheckData extends Command
->withTrashed()
->get();
$this->logMessage(count($invoices) . ' draft sent invoices');
$this->logMessage($invoices->count() . ' draft sent invoices');
if (count($invoices) > 0) {
if ($invoices->count() > 0) {
$this->isValid = false;
}
@ -190,9 +190,9 @@ class CheckData extends Command
->havingRaw('count(users.id) > 1')
->get(['users.oauth_user_id']);
$this->logMessage(count($users) . ' users with duplicate oauth ids');
$this->logMessage($users->count() . ' users with duplicate oauth ids');
if (count($users) > 0) {
if ($users->count() > 0) {
$this->isValid = false;
}
@ -308,9 +308,9 @@ class CheckData extends Command
->whereNull('contact_key')
->orderBy('id')
->get(['id']);
$this->logMessage(count($contacts) . ' contacts without a contact_key');
$this->logMessage($contacts->count() . ' contacts without a contact_key');
if (count($contacts) > 0) {
if ($contacts->count() > 0) {
$this->isValid = false;
}
@ -339,9 +339,9 @@ class CheckData extends Command
}
$clients = $clients->get(['clients.id', 'clients.user_id', 'clients.account_id']);
$this->logMessage(count($clients) . ' clients without any contacts');
$this->logMessage($clients->count() . ' clients without any contacts');
if (count($clients) > 0) {
if ($clients->count() > 0) {
$this->isValid = false;
}
@ -374,9 +374,9 @@ class CheckData extends Command
}
$clients = $clients->get(['clients.id', DB::raw('count(contacts.id)')]);
$this->logMessage(count($clients) . ' clients without a single primary contact');
$this->logMessage($clients->count() . ' clients without a single primary contact');
if (count($clients) > 0) {
if ($clients->count() > 0) {
$this->isValid = false;
}
}
@ -423,9 +423,9 @@ class CheckData extends Command
->havingRaw('count(invitations.id) = 0')
->get(['invoices.id', 'invoices.user_id', 'invoices.account_id', 'invoices.client_id']);
$this->logMessage(count($invoices) . ' invoices without any invitations');
$this->logMessage($invoices->count() . ' invoices without any invitations');
if (count($invoices) > 0) {
if ($invoices->count() > 0) {
$this->isValid = false;
}
@ -512,9 +512,9 @@ class CheckData extends Command
->where("{$table}.{$accountId}", '!=', DB::raw("{$tableName}.account_id"))
->get(["{$table}.id"]);
if (count($records)) {
if ($records->count()) {
$this->isValid = false;
$this->logMessage(count($records) . " {$table} records with incorrect {$entityType} account id");
$this->logMessage($records->count() . " {$table} records with incorrect {$entityType} account id");
if ($this->option('fix') == 'true') {
foreach ($records as $record) {
@ -549,9 +549,9 @@ class CheckData extends Command
->groupBy('clients.id')
->havingRaw('clients.paid_to_date != sum(coalesce(payments.amount - payments.refunded, 0)) and clients.paid_to_date != 999999999.9999')
->get(['clients.id', 'clients.paid_to_date', DB::raw('sum(coalesce(payments.amount - payments.refunded, 0)) as amount')]);
$this->logMessage(count($clients) . ' clients with incorrect paid to date');
$this->logMessage($clients->count() . ' clients with incorrect paid to date');
if (count($clients) > 0) {
if ($clients->count() > 0) {
$this->isValid = false;
}
@ -580,9 +580,9 @@ class CheckData extends Command
->havingRaw('(invoices.amount - invoices.balance) != coalesce(sum(payments.amount - payments.refunded), 0)')
->get(['invoices.id', 'invoices.amount', 'invoices.balance', DB::raw('coalesce(sum(payments.amount - payments.refunded), 0)')]);
$this->logMessage(count($invoices) . ' invoices with incorrect balances');
$this->logMessage($invoices->count() . ' invoices with incorrect balances');
if (count($invoices) > 0) {
if ($invoices->count() > 0) {
$this->isValid = false;
}
}
@ -608,9 +608,9 @@ class CheckData extends Command
$clients = $clients->groupBy('clients.id', 'clients.balance')
->orderBy('accounts.company_id', 'DESC')
->get(['accounts.company_id', 'clients.account_id', 'clients.id', 'clients.balance', 'clients.paid_to_date', DB::raw('sum(invoices.balance) actual_balance')]);
$this->logMessage(count($clients) . ' clients with incorrect balance/activities');
$this->logMessage($clients->count() . ' clients with incorrect balance/activities');
if (count($clients) > 0) {
if ($clients->count() > 0) {
$this->isValid = false;
}

View File

@ -32,7 +32,7 @@ class RemoveOrphanedDocuments extends Command
$documents = Document::whereRaw('invoice_id IS NULL AND expense_id IS NULL AND updated_at <= ?', [new DateTime('-1 hour')])
->get();
$this->info(count($documents).' orphaned document(s) found');
$this->info($documents->count() . ' orphaned document(s) found');
foreach ($documents as $document) {
$document->delete();

View File

@ -98,7 +98,7 @@ class SendRecurringInvoices extends Command
->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND is_recurring IS TRUE AND is_public IS TRUE AND frequency_id > 0 AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', [$today, $today])
->orderBy('id', 'asc')
->get();
$this->info(count($invoices).' recurring invoice(s) found');
$this->info($invoices->count() . ' recurring invoice(s) found');
foreach ($invoices as $recurInvoice) {
$shouldSendToday = $recurInvoice->shouldSendToday();
@ -140,7 +140,7 @@ class SendRecurringInvoices extends Command
[$today->format('Y-m-d')])
->orderBy('invoices.id', 'asc')
->get();
$this->info(count($delayedAutoBillInvoices).' due recurring invoice instance(s) found');
$this->info($delayedAutoBillInvoices->count() . ' due recurring invoice instance(s) found');
/** @var Invoice $invoice */
foreach ($delayedAutoBillInvoices as $invoice) {
@ -172,7 +172,7 @@ class SendRecurringInvoices extends Command
->whereRaw('is_deleted IS FALSE AND deleted_at IS NULL AND start_date <= ? AND (end_date IS NULL OR end_date >= ?)', [$today, $today])
->orderBy('id', 'asc')
->get();
$this->info(count($expenses).' recurring expenses(s) found');
$this->info($expenses->count() . ' recurring expenses(s) found');
foreach ($expenses as $expense) {
$shouldSendToday = $expense->shouldSendToday();

View File

@ -92,7 +92,7 @@ class SendReminders extends Command
private function chargeLateFees()
{
$accounts = $this->accountRepo->findWithFees();
$this->info(count($accounts) . ' accounts found with fees');
$this->info($accounts->count() . ' accounts found with fees');
foreach ($accounts as $account) {
if (! $account->hasFeature(FEATURE_EMAIL_TEMPLATES_REMINDERS)) {
@ -100,7 +100,7 @@ class SendReminders extends Command
}
$invoices = $this->invoiceRepo->findNeedingReminding($account, false);
$this->info($account->name . ': ' . count($invoices) . ' invoices found');
$this->info($account->name . ': ' . $invoices->count() . ' invoices found');
foreach ($invoices as $invoice) {
if ($reminder = $account->getInvoiceReminder($invoice, false)) {
@ -128,7 +128,7 @@ class SendReminders extends Command
// standard reminders
$invoices = $this->invoiceRepo->findNeedingReminding($account);
$this->info($account->name . ': ' . count($invoices) . ' invoices found');
$this->info($account->name . ': ' . $invoices->count() . ' invoices found');
foreach ($invoices as $invoice) {
if ($reminder = $account->getInvoiceReminder($invoice)) {
@ -142,7 +142,7 @@ class SendReminders extends Command
// endless reminders
$invoices = $this->invoiceRepo->findNeedingEndlessReminding($account);
$this->info($account->name . ': ' . count($invoices) . ' endless invoices found');
$this->info($account->name . ': ' . $invoices->count() . ' endless invoices found');
foreach ($invoices as $invoice) {
if ($invoice->last_sent_date == date('Y-m-d')) {
@ -159,7 +159,7 @@ class SendReminders extends Command
$scheduledReports = ScheduledReport::where('send_date', '<=', date('Y-m-d'))
->with('user', 'account.company')
->get();
$this->info(count($scheduledReports) . ' scheduled reports');
$this->info($scheduledReports->count() . ' scheduled reports');
foreach ($scheduledReports as $scheduledReport) {
$user = $scheduledReport->user;

View File

@ -60,10 +60,10 @@ class SendRenewalInvoices extends Command
$companies = Company::whereRaw("datediff(plan_expires, curdate()) = 10 and (plan = 'pro' or plan = 'enterprise')")
->orderBy('id')
->get();
$this->info(count($companies).' companies found renewing in 10 days');
$this->info($companies->count() . ' companies found renewing in 10 days');
foreach ($companies as $company) {
if (! count($company->accounts)) {
if (! $company->accounts->count()) {
continue;
}

View File

@ -452,7 +452,7 @@ class AccountController extends BaseController
{
$account = Auth::user()->account;
$account->load('account_gateways');
$count = count($account->account_gateways);
$count = $account->account_gateways->count();
$trashedCount = AccountGateway::scope()->withTrashed()->count();
if ($accountGateway = $account->getGatewayConfig(GATEWAY_STRIPE)) {
@ -737,7 +737,7 @@ class AccountController extends BaseController
return $font->id == $account->header_font_id || $font->id == $account->body_font_id;
});
if ($account->live_preview && count($fonts)) {
if ($account->live_preview && $fonts->count()) {
$account->live_preview = false;
Session::flash('warning', trans('texts.live_preview_disabled'));
}

View File

@ -152,7 +152,7 @@ class AccountGatewayController extends BaseController
'config' => false,
'gateways' => $gateways,
'creditCardTypes' => $creditCards,
'countGateways' => count($currentGateways),
'countGateways' => $currentGateways->count(),
];
}

View File

@ -43,12 +43,12 @@ class DashboardApiController extends BaseAPIController
$data = [
'id' => 1,
'paidToDate' => count($paidToDate) && $paidToDate[0]->value ? $paidToDate[0]->value : 0,
'paidToDateCurrency' => count($paidToDate) && $paidToDate[0]->currency_id ? $paidToDate[0]->currency_id : 0,
'balances' => count($balances) && $balances[0]->value ? $balances[0]->value : 0,
'balancesCurrency' => count($balances) && $balances[0]->currency_id ? $balances[0]->currency_id : 0,
'averageInvoice' => count($averageInvoice) && $averageInvoice[0]->invoice_avg ? $averageInvoice[0]->invoice_avg : 0,
'averageInvoiceCurrency' => count($averageInvoice) && $averageInvoice[0]->currency_id ? $averageInvoice[0]->currency_id : 0,
'paidToDate' => $paidToDate->count() && $paidToDate[0]->value ? $paidToDate[0]->value : 0,
'paidToDateCurrency' => $paidToDate->count() && $paidToDate[0]->currency_id ? $paidToDate[0]->currency_id : 0,
'balances' => $balances->count() && $balances[0]->value ? $balances[0]->value : 0,
'balancesCurrency' => $balances->count() && $balances[0]->currency_id ? $balances[0]->currency_id : 0,
'averageInvoice' => $averageInvoice->count() && $averageInvoice[0]->invoice_avg ? $averageInvoice[0]->invoice_avg : 0,
'averageInvoiceCurrency' => $averageInvoice->count() && $averageInvoice[0]->currency_id ? $averageInvoice[0]->currency_id : 0,
'invoicesSent' => $metrics ? $metrics->invoices_sent : 0,
'activeClients' => $metrics ? $metrics->active_clients : 0,
'activities' => $this->createCollection($activities, new ActivityTransformer(), ENTITY_ACTIVITY),

View File

@ -83,7 +83,7 @@ class DashboardController extends BaseController
'tasks' => $tasks,
'showBlueVinePromo' => $showBlueVinePromo,
'showWhiteLabelExpired' => $showWhiteLabelExpired,
'showExpenses' => count($expenses) && $account->isModuleEnabled(ENTITY_EXPENSE),
'showExpenses' => $expenses->count() && $account->isModuleEnabled(ENTITY_EXPENSE),
'headerClass' => in_array(\App::getLocale(), ['lt', 'pl', 'cs', 'sl', 'tr_TR']) ? 'in-large' : 'in-thin',
'footerClass' => in_array(\App::getLocale(), ['lt', 'pl', 'cs', 'sl', 'tr_TR']) ? '' : 'in-thin',
];

View File

@ -54,34 +54,5 @@ class DownloadInvoices extends Job
$zip->finish();
exit;
/*
// if queues are disabled download a zip file
if (config('queue.default') === 'sync' || count($this->invoices) <= 10) {
$zip = Archive::instance_by_useragent(date('Y-m-d') . '-Invoice_PDFs');
foreach ($this->invoices as $invoice) {
$zip->add_file($invoice->getFileName(), $invoice->getPDFString());
}
$zip->finish();
exit;
// otherwise sends the PDFs in an email
} else {
$data = [];
foreach ($this->invoices as $invoice) {
$data[] = [
'name' => $invoice->getFileName(),
'data' => $invoice->getPDFString(),
];
}
$subject = trans('texts.invoices_are_attached');
$data = [
'documents' => $data
];
$userMailer->sendMessage($this->user, $subject, false, $data);
}
*/
}
}

View File

@ -501,7 +501,7 @@ class Account extends Eloquent
if ($gatewayId) {
return $this->getGatewayConfig($gatewayId) != false;
} else {
return count($this->account_gateways) > 0;
return $this->account_gateways->count() > 0;
}
}

View File

@ -351,7 +351,7 @@ class Client extends EntityModel
return $this->name;
}
if (! count($this->contacts)) {
if (! $this->contacts->count()) {
return '';
}

View File

@ -1470,18 +1470,18 @@ class Invoice extends EntityModel implements BalanceAffecting
*/
public function countDocuments($expenses = false)
{
$count = count($this->documents);
$count = $this->documents->count();
foreach ($this->expenses as $expense) {
if ($expense->invoice_documents) {
$count += count($expense->documents);
$count += $expense->documents->count();
}
}
if ($expenses) {
foreach ($expenses as $expense) {
if ($expense->invoice_documents) {
$count += count($expense->documents);
$count += $expense->documents->count();
}
}
}
@ -1511,7 +1511,7 @@ class Invoice extends EntityModel implements BalanceAffecting
public function hasExpenseDocuments()
{
foreach ($this->expenses as $expense) {
if ($expense->invoice_documents && count($expense->documents)) {
if ($expense->invoice_documents && $expense->documents->count()) {
return true;
}
}

View File

@ -270,7 +270,7 @@ class ContactMailer extends Mailer
$invitation = $payment->invitation;
} else {
$user = $payment->user;
$contact = count($client->contacts) ? $client->contacts[0] : '';
$contact = $client->contacts->count() ? $client->contacts[0] : '';
$invitation = $payment->invoice->invitations[0];
}

View File

@ -114,7 +114,7 @@ class StripePaymentDriver extends BasePaymentDriver
$this->tokenResponse = $response->getData();
// import Stripe tokens created before payment methods table was added
if (! count($customer->payment_methods)) {
if (! $customer->payment_methods->count()) {
if ($paymentMethod = $this->createPaymentMethod($customer)) {
$customer->default_payment_method_id = $paymentMethod->id;
$customer->save();

View File

@ -175,7 +175,7 @@ class InvoicePresenter extends EntityPresenter
{
$client = $this->entity->client;
return count($client->contacts) ? $client->contacts[0]->email : '';
return $client->contacts->count() ? $client->contacts[0]->email : '';
}
public function autoBillEmailMessage()
@ -271,7 +271,7 @@ class InvoicePresenter extends EntityPresenter
foreach ($invoice->payments as $payment) {
$label = trans('texts.view_payment');
if (count($invoice->payments) > 1) {
if ($invoice->payments->count() > 1) {
$label .= ' - ' . $invoice->account->formatMoney($payment->amount, $invoice->client);
}
$actions[] = ['url' => $payment->present()->url, 'label' => $label];

View File

@ -59,7 +59,7 @@ class InvoiceReport extends AbstractReport
foreach ($clients->get() as $client) {
foreach ($client->invoices as $invoice) {
$payments = count($invoice->payments) ? $invoice->payments : [false];
$payments = $invoice->payments->count() ? $invoice->payments : [false];
foreach ($payments as $payment) {
$this->data[] = [
$this->isExport ? $client->getDisplayName() : $client->present()->link,

View File

@ -804,7 +804,7 @@ class InvoiceRepository extends BaseRepository
$client->load('contacts');
$sendInvoiceIds = [];
if (! count($client->contacts)) {
if (! $client->contacts->count()) {
return $invoice;
}

View File

@ -165,7 +165,7 @@ class BankAccountService extends BaseService
}
// if we can't find a match skip the account
if (count($bankAccounts) && ! $obj->account_name) {
if ($bankAccounts->count() && ! $obj->account_name) {
return false;
}

View File

@ -947,7 +947,7 @@ class ImportService
$this->maps['client'][$name] = $client->id;
$this->maps['client_ids'][$client->public_id] = $client->id;
}
if (count($client->contacts) && $name = strtolower(trim($client->contacts[0]->email))) {
if ($client->contacts->count() && $name = strtolower(trim($client->contacts[0]->email))) {
$this->maps['client'][$name] = $client->id;
$this->maps['client_ids'][$client->public_id] = $client->id;
}