Passed
Push — master ( 1d6d9a...2a90e7 )
by Ron
02:47 queued 12s
created

CustomerContactsController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace App\Http\Controllers\Customers;
4
5
use App\Customers;
6
use App\PhoneNumberTypes;
7
use App\CustomerContacts;
8
use Illuminate\Http\Request;
9
use App\CustomerContactPhones;
10
use App\Domains\Customers\GetCustomerContacts;
11
use App\Domains\Customers\GetCustomerDetails;
12
use App\Domains\Customers\SetCustomerContacts;
13
use JeroenDesloovere\VCard\VCard;
14
use Illuminate\Support\Facades\Log;
15
use Illuminate\Support\Facades\Auth;
16
use App\Http\Controllers\Controller;
17
use App\Http\Requests\CustomerEditContactRequest;
18
use App\Http\Requests\CustomerNewContactRequest;
19
use Illuminate\Support\Facades\Route;
20
21
class CustomerContactsController extends Controller
22
{
23 26
    public function __construct()
24
    {
25 26
        $this->middleware('auth');
26 26
    }
27
28
    //  Index funtion will only return the type of phone numbers that can be assigned to a customer
29
    public function index()
30
    {
31
        return (new GetCustomerContacts)->getPhoneNumberTypes(true);
32
    }
33
34
    //  Store a new customer contact
35 4
    public function store(CustomerNewContactRequest $request)
36
    {
37 4
        (new SetCustomerContacts($request->cust_id))->createContact($request);
38 4
        return response()->json(['success' => true]);
39
    }
40
41
    //  Get the contacts for a customer
42 4
    public function show($id)
43
    {
44 4
        return (new GetCustomerContacts($id))->execute();
45
    }
46
47
    //  Edit function will actually download the contact information in V-Card format
48
    public function edit($id)
49
    {
50
        $contData = (new GetCustomerContacts)->getOneContact($id);
51
        $custData = (new GetCustomerDetails)->getDetails($contData['cust_id']);
52
53
54
        $vcard = new VCard();
55
        $vcard->addName($contData['lastName'], $contData['firstName'], $contData['additional'], $contData['prefix'], $contData['suffix']);
56
        $vcard->addCompany($custData['name']);
0 ignored issues
show
Bug introduced by
It seems like $custData['name'] can also be of type Illuminate\Database\Eloq...uent\Relations\Relation and Illuminate\Database\Eloquent\Relations\Relation; however, parameter $company of JeroenDesloovere\VCard\VCard::addCompany() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

56
        $vcard->addCompany(/** @scrutinizer ignore-type */ $custData['name']);
Loading history...
57
        $vcard->addEmail($contData['email']);
58
        $vcard->addAddress(null, null, $custData['address'], $custData['city'], $custData['state'], $custData['zip'], null);
59
        if(!empty($contData['numbers']))
60
        {
61
            foreach($contData['numbers'] as $phone)
62
            {
63
                $vcard->addPhoneNumber($phone->phone_number, $phone->description);
64
            }
65
        }
66
        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...
67
    }
68
69
    //  Update an existing Customer Contact
70 6
    public function update(CustomerEditContactRequest $request, $id)
71
    {
72 6
        (new SetCustomerContacts($id))->updateContact($request);
73 6
        return response()->json(['success' => true]);
74
    }
75
76
    //  Delete an existing contact
77 2
    public function destroy($id)
78
    {
79 2
        (new SetCustomerContacts($id))->deleteContact($id);
80 2
        return response()->json(['success' => true]);
81
    }
82
}
83