Conditions | 5 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 12 |
Lines | 3 |
Ratio | 12.5 % |
Changes | 0 |
1 | <?php |
||
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) { |
|
|
|||
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 |
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.