Passed
Push — dev6 ( 98cfbc...9c7079 )
by Ron
19:23
created

DownloadContactController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 2
b 0
f 0
dl 0
loc 30
ccs 0
cts 14
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 25 4
1
<?php
2
3
namespace App\Http\Controllers\Customers;
4
5
use JeroenDesloovere\VCard\VCard;
6
7
use App\Models\Customer;
8
use App\Models\CustomerContact;
9
use App\Http\Controllers\Controller;
10
use App\Events\Customers\CustomerContactDownloadedEvent;
11
12
class DownloadContactController extends Controller
13
{
14
    /**
15
     * Download a customer contact in v-card format
16
     */
17
    public function __invoke($contID)
18
    {
19
        $contact  = CustomerContact::findOrFail($contID);
20
        $customer = Customer::find($contact->cust_id);
21
        $name     = explode(' ', $contact->name);
22
23
        //  Build the VCard
24
        $vcard = new VCard();
25
        $vcard->addName(isset($name[1]) ? $name[1] : null, $name[0]);
26
        $vcard->addCompany($customer->name);
27
        $vcard->addAddress(null, null, $customer->address, $customer->city, $customer->state, $customer->zip, null);
28
29
        //  Add phone numbers to the VCard
30
        foreach($contact->CustomerContactPhone as $phone)
31
        {
32
            $number = $phone->readable;
33
            if($phone->extension)
34
            {
35
                $number .= ', '.$phone->extension;
36
            }
37
            $vcard->addPhoneNumber($number, $phone->type_name);
38
        }
39
40
        event(new CustomerContactDownloadedEvent($customer, $contact));
41
        return $vcard->download();
1 ignored issue
show
Bug introduced by
Are you sure the usage of $vcard->download() targeting JeroenDesloovere\VCard\VCard::download() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
42
    }
43
}
44