Account::exists()   B
last analyzed

Complexity

Conditions 6
Paths 7

Size

Total Lines 27
Code Lines 15

Duplication

Lines 3
Ratio 11.11 %

Importance

Changes 0
Metric Value
dl 3
loc 27
rs 8.439
c 0
b 0
f 0
cc 6
eloc 15
nc 7
nop 3
1
<?php
2
3
namespace Surge\LaravelSalesforce\Objects;
4
5
class Account extends AbstractObject
6
{
7
    /**
8
     * Insert new account.
9
     *
10
     * @param $params
11
     */
12
    public function create(array $params)
13
    {
14
        $params['RecordTypeId'] = config('laravel-salesforce.record_type.account');
15
16
        return parent::create($params);
17
    }
18
19
    /**
20
     * Check if account already exists on SF.
21
     * $params = [
22
     *  'PersonEmail' => '[email protected]'
23
     * ]
24
     *
25
     *
26
     * @param array  $param to search
0 ignored issues
show
Documentation introduced by
There is no parameter named $param. Did you maybe mean $params?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

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

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

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

Loading history...
27
     * @param string $condition
28
     * @return bool|array
29
     */
30
    public function exists($params, $condition = 'AND', $returnAllRecords = false)
31
    {
32
        if (empty($params)) {
33
            return false;
34
        }
35
36
        $query = 'SELECT Id, OwnerId, Salutation, FirstName, LastName FROM ' . $this->getType() . ' WHERE RecordTypeId = \'' . config('laravel-salesforce.record_type.account') . '\'';
37
38
        $paramsWithKeys = [];
39 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...
40
            $paramsWithKeys[] = $fieldName . ' = \'' . addslashes(trim($fieldValue)) . '\'';
41
        }
42
43
        $query .= ' AND (' . implode(' ' . $condition . ' ', $paramsWithKeys) . ')';
44
45
        $response = $this->query($query);
46
47
        if ($response && $response->totalSize > 0) {
48
            if ($returnAllRecords) {
49
                return $response->records;
50
            } else {
51
                return array_shift($response->records);
52
            }
53
        }
54
55
        return false;
56
    }
57
}
58