Test Failed
Push — master ( c1559b...0edaee )
by Mauro
02:36
created

PilotApiClient   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 6
c 3
b 1
f 0
lcom 1
cbo 4
dl 0
loc 88
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 14 1
B storeLead() 0 36 4
A getGuzzleClient() 0 4 1
1
<?php
2
/**
3
 * Class PilotApiClient
4
 *
5
 * @author Cristian Jimenez <[email protected]>
6
 */
7
8
namespace Zephia\PilotApiClient\Client;
9
10
use GuzzleHttp\Client as GuzzleClient;
11
use Zephia\PilotApiClient\Exception\InvalidArgumentException;
12
use Zephia\PilotApiClient\Model\LeadData;
13
14
class PilotApiClient
15
{
16
    /**
17
     * Pilot API URI
18
     */
19
    const BASE_URI = 'http://www.pilotsolution.com.ar/api/webhooks/welcome.php';
20
21
    private $appKey;
22
    private $debug;
23
    private $notification_email;
0 ignored issues
show
Unused Code introduced by
The property $notification_email is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
24
    private $guzzleClient;
25
26
    /**
27
     * PilotApi constructor.
28
     * @param array $config
29
     */
30
    public function __construct(array $config = [])
31
    {
32
        $defaults = [
33
            'debug' => false,
34
            'app_key' => null,
35
        ];
36
37
        $config = array_merge($config, $defaults);
38
39
        $this->appKey = $config['app_key'];
40
        $this->debug = $config['debug'];
41
42
        $this->guzzleClient = new GuzzleClient();
43
    }
44
45
    /**
46
     * Store lead
47
     *
48
     * @param array $lead_data Lead data array.
49
     * See documentation at http://www.pilotsolution.com.ar/home/api.php (Array keys without 'pilot_' prefix)
50
     * Example:
51
     * $lead_data = ['firstname' => 'John', 'lastname' = 'Doe', 'phone' => '+543512345678', 'email' => '[email protected]'];
52
     *
53
     * @param int $business_type_id Código numérico del tipo negocio del dato (1: 0km, 2: Usados, 3: Plan de Ahorro)
0 ignored issues
show
Bug introduced by
There is no parameter named $business_type_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
54
     * @param int $contact_type_id Código numérico del tipo de contacto del dato (1: Electrónico, 2: Telefónico , 3: Entrevista)
0 ignored issues
show
Bug introduced by
There is no parameter named $contact_type_id. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
55
     * @return string Pilot API response
56
     */
57
    public function storeLead(LeadData $lead_data, $notification_email = '')
58
    {
59
        if (empty($lead_data)) {
60
            throw new InvalidArgumentException("Lead Data is empty.");
61
        }
62
63
        /*$pilot_lead_data = [];
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
64
65
        foreach ($lead_data as $key => $value) {
66
            $pilot_lead_data['pilot_' . $key] = $value;
67
        }*/
68
69
        $form_params = [
70
            'debug' => $this->debug,
71
            'action' => 'create',
72
            'appkey' => $this->appKey,
73
        ];
74
75
        $form_params = array_merge($form_params, $lead_data->toArray());
76
77
        if (!empty($notification_email)) {
78
            $form_params['notification_email'] = $notification_email;
79
        }
80
81
        $response = $this->guzzleClient->post(self::BASE_URI, [
82
            'body' => $form_params
83
        ]);
84
85
        if ($response->getStatusCode() != 200) {
86
            throw new \InvalidArgumentException(
87
                $response->getBody()->getContents()
88
            );
89
        } else {
90
            return $response->getBody()->getContents();
91
        }
92
    }
93
94
    /**
95
     * @return GuzzleClient
96
     */
97
    public function getGuzzleClient()
98
    {
99
        return $this->guzzleClient;
100
    }
101
}
102