Completed
Push — master ( 4ff52b...8a69c1 )
by
unknown
02:53
created

User::exists()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 3
Ratio 13.04 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 3
loc 23
rs 8.5906
c 1
b 0
f 0
cc 5
eloc 12
nc 5
nop 2
1
<?php
2
3
namespace Surge\LaravelSalesforce\Objects;
4
5
class User extends AbstractObject
6
{
7
    /**
8
     * Check if user already exists on SF.
9
     * $params = [
10
     *  'Email' => '[email protected]'
11
     * ]
12
     *
13
     * @param $params
14
     * @param string $condition
15
     * @return bool|mixed
16
     */
17
    public function exists($params, $condition = 'AND')
18
    {
19
        if (empty($params)) {
20
            return false;
21
        }
22
23
        $query = 'SELECT Id, Name, Email, UserType, UserRoleId FROM ' . $this->getType() . ' WHERE ';
24
25
        $paramsWithKeys = [];
26 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...
27
            $paramsWithKeys[] = $fieldName . ' = \'' . addslashes(trim($fieldValue)) . '\'';
28
        }
29
30
        $query .= '(' . implode(' ' . $condition . ' ', $paramsWithKeys) . ')';
31
32
        $response = $this->query($query);
33
34
        if ($response && $response->totalSize > 0) {
35
            return array_shift($response->records);
36
        }
37
38
        return false;
39
    }
40
41
}
42