Completed
Push — master ( 381725...d23a27 )
by Ashleigh
02:15 queued 38s
created

Salesforce::runReport()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 1
1
<?php
2
3
namespace Surge\LaravelSalesforce;
4
5
use Event;
6
use Surge\LaravelSalesforce\Objects\BaseObject;
7
8
class Salesforce
9
{
10
    /**
11
     * @var string
12
     */
13
    protected $objName;
14
15
    /**
16
     * @var SalesforceAuth
17
     */
18
    private $auth;
19
20
    /**
21
     * Salesforce constructor.
22
     *
23
     * @param                $client
24
     * @param SalesforceAuth $auth
25
     */
26
    public function __construct($client, SalesforceAuth $auth)
27
    {
28
        $this->client = $client;
0 ignored issues
show
Bug introduced by
The property client does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
29
        $this->auth = $auth;
30
    }
31
32
    /**
33
     * @param  stirng $method
34
     * @param  array  $args
35
     * @return bool|mixed|string
36
     */
37
    public function __call($method, $args)
38
    {
39
        if (0 === strpos($method, 'create')) {
40
            return $this->callCreateOnObject($method, $args);
41
        }
42
43
        if (0 === strpos($method, 'update')) {
44
            return $this->callUpdateOnObject($method, $args);
45
        }
46
47
        if (0 === strpos($method, 'delete')) {
48
            return $this->callDeleteOnObject($method, $args);
49
        }
50
51
        if (0 === strpos($method, 'get')) {
52
            return $this->callGetOnObject($method, $args);
53
        }
54
55
        return (new BaseObject(''))->$method;
56
    }
57
58
    /**
59
     * Create object dynamically
60
     *
61
     * @param $method
62
     * @param $args
63
     * @return bool
64
     */
65 View Code Duplication
    private function callCreateOnObject($method, $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
66
    {
67
        $type = substr($method, 6);
68
        $class = '\\Surge\\LaravelSalesforce\\Objects\\' . $type;
69
70
        if (class_exists($class)) {
71
            return (new $class())->create($args[0]);
72
        }
73
74
        return (new BaseObject($type))->create($args[0]);
75
    }
76
77 View Code Duplication
    private function callUpdateOnObject($method, $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
78
    {
79
        $type = substr($method, 6);
80
        $class = '\\Surge\\LaravelSalesforce\\Objects\\' . $type;
81
82
        if (class_exists($class)) {
83
            return (new $class())->update($args[0]);
84
        }
85
86
        return (new BaseObject($type))->update($type, $args[0]);
87
    }
88
89 View Code Duplication
    private function callDeleteOnObject($method, $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
90
    {
91
        $type = substr($method, 6);
92
        $class = '\\Surge\\LaravelSalesforce\\Objects\\' . $type;
93
94
        if (class_exists($class)) {
95
            return (new $class())->delete($args[0]);
96
        }
97
98
        return (new BaseObject($type))->delete($type, $args[0]);
0 ignored issues
show
Unused Code introduced by
The call to BaseObject::delete() has too many arguments starting with $args[0].

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
99
    }
100
101 View Code Duplication
    private function callGetOnObject($method, $args)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
102
    {
103
        $type = substr($method, 3);
104
        $class = '\\Surge\\LaravelSalesforce\\Objects\\' . $type;
105
106
        if (class_exists($class)) {
107
            return (new $class())->get($args[0]);
108
        }
109
110
        return (new BaseObject($type))->get($args[0]);
111
    }
112
}
113