Lead::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Surge\LaravelSalesforce\Objects;
4
5
class Lead extends AbstractObject
6
{
7
    /**
8
     * Insert new lead.
9
     *
10
     * @param $params
11
     */
12
    public function create(array $params)
13
    {
14
        $params['RecordTypeId'] = config('laravel-salesforce.record_type.lead');
15
16
        return parent::create($params);
17
    }
18
19
    /**
20
     * Check if lead already exists on SF.
21
     *
22
     * $params = [
23
     *   'Email' => '[email protected]'
24
     * ]
25
     *
26
     * @param array  $params
27
     * @param string $condition
28
     *
29
     * @return bool|array
30
     */
31
    public function exists($params, $condition = 'AND')
32
    {
33
        //return false if not enough data provided
34
        if (empty($params)) {
35
            return false;
36
        }
37
38
        $query = 'SELECT Id, OwnerId FROM ' . $this->getType() . ' WHERE RecordTypeId = \'' . config('laravel-salesforce.record_type.lead') . '\'';
39
40
        $paramsWithKeys = [];
41 View Code Duplication
        foreach ($params as $fieldName => $fieldValue) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
42
            $paramsWithKeys[] = $fieldName . ' = \'' . addslashes(trim($fieldValue)) . '\'';
43
        }
44
45
        $query .= ' AND (' . implode(' ' . $condition . ' ', $paramsWithKeys) . ')';
46
47
        $response = $this->query($query);
48
49
        if ($response && $response->totalSize > 0) {
50
            return array_shift($response->records);
51
        }
52
53
        return false;
54
    }
55
}
56