Passed
Push — master ( 99d751...45eca1 )
by Thomas
07:06
created

compare_invoice_relationsCommand   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 20
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 3
1
<?php
2
3
namespace App\Console\Commands;
4
5
use App\Models\Enrollment;
6
use App\Models\Invoice;
7
use Illuminate\Console\Command;
8
9
class compare_invoice_relationsCommand extends Command
10
{
11
    protected $signature = 'academico:invoice-check';
12
13
    protected $description = 'Command description';
14
15
    public function handle()
16
    {
17
        $anomalies = 0;
18
        foreach (Invoice::all() as $invoice) {
19
            // get enrollments
20
            $enrollments = $invoice->enrollments->pluck('id')->toArray();
21
            $realEnrollments = $invoice->invoiceDetails()->where('product_type', Enrollment::class)->get()->pluck('product_id')->toArray();
22
23
            if (count(array_diff($enrollments, $realEnrollments)) > 0) {
24
                $anomalies++;
25
                echo "\ninvoice ".$invoice->id.' is linked to enrollments '.implode(' - ', $enrollments).'and really has '.implode(' - ', $realEnrollments);
26
            }
27
        }
28
        echo $anomalies.' anomalies detected';
29
    }
30
}
31