Factory::createWithToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 4
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SevenShores\Hubspot;
4
5
use SevenShores\Hubspot\Http\Client;
6
7
/**
8
 * Class Factory.
9
 *
10
 * @method \SevenShores\Hubspot\Resources\BlogAuthors blogAuthors()
11
 * @method \SevenShores\Hubspot\Resources\Blogs blogs()
12
 * @method \SevenShores\Hubspot\Resources\BlogPosts blogPosts()
13
 * @method \SevenShores\Hubspot\Resources\BlogTopics blogTopics()
14
 * @method \SevenShores\Hubspot\Resources\Companies companies()
15
 * @method \SevenShores\Hubspot\Resources\CompanyProperties companyProperties()
16
 * @method \SevenShores\Hubspot\Resources\CalendarEvents calendarEvents()
17
 * @method \SevenShores\Hubspot\Resources\ContactLists contactLists()
18
 * @method \SevenShores\Hubspot\Resources\ContactProperties contactProperties()
19
 * @method \SevenShores\Hubspot\Resources\Contacts contacts()
20
 * @method \SevenShores\Hubspot\Resources\CrmAssociations crmAssociations()
21
 * @method \SevenShores\Hubspot\Resources\Email email()
22
 * @method \SevenShores\Hubspot\Resources\EmailEvents emailEvents()
23
 * @method \SevenShores\Hubspot\Resources\Engagements engagements()
24
 * @method \SevenShores\Hubspot\Resources\Files files()
25
 * @method \SevenShores\Hubspot\Resources\Forms forms()
26
 * @method \SevenShores\Hubspot\Resources\HubDB hubDB()
27
 * @method \SevenShores\Hubspot\Resources\Keywords keywords()
28
 * @method \SevenShores\Hubspot\Resources\Pages pages()
29
 * @method \SevenShores\Hubspot\Resources\SocialMedia socialMedia()
30
 * @method \SevenShores\Hubspot\Resources\Tickets tickets()
31
 * @method \SevenShores\Hubspot\Resources\Timeline timeline()
32
 * @method \SevenShores\Hubspot\Resources\Workflows workflows()
33
 * @method \SevenShores\Hubspot\Resources\Events events()
34
 * @method \SevenShores\Hubspot\Resources\DealPipelines dealPipelines()
35
 * @method \SevenShores\Hubspot\Resources\DealProperties dealProperties()
36
 * @method \SevenShores\Hubspot\Resources\Deals deals()
37
 * @method \SevenShores\Hubspot\Resources\Owners owners()
38
 * @method \SevenShores\Hubspot\Resources\SingleEmail singleEmail()
39
 * @method \SevenShores\Hubspot\Resources\Integration integration()
40
 * @method \SevenShores\Hubspot\Resources\EcommerceBridge ecommerceBridge()
41
 * @method \SevenShores\Hubspot\Resources\Webhooks webhooks()
42
 */
43
class Factory
44
{
45
    /**
46
     * C O N S T R U C T O R ( ^_^)y.
47
     *
48
     * @param array  $config        An array of configurations. You need at least the 'key'.
49
     * @param Client $client
50
     * @param array  $clientOptions options to be send with each request
51
     * @param bool   $wrapResponse  wrap request response in own Response object
52
     */
53
    public function __construct($config = [], $client = null, $clientOptions = [], $wrapResponse = true)
54
    {
55
        $this->client = $client ?: new Client($config, null, $clientOptions, $wrapResponse);
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...
56
    }
57
58
    /**
59
     * Create an instance of the service with an API key.
60
     *
61
     * @param string $api_key       Hubspot API key.
62
     * @param Client $client        An Http client.
63
     * @param array  $clientOptions options to be send with each request
64
     * @param bool   $wrapResponse  wrap request response in own Response object
65
     *
66
     * @return static
67
     */
68
    public static function create($api_key = null, $client = null, $clientOptions = [], $wrapResponse = true)
69
    {
70
        return new static(['key' => $api_key], $client, $clientOptions, $wrapResponse);
71
    }
72
73
    /**
74
     * Create an instance of the service with an Oauth token.
75
     *
76
     * @param string $token         Hubspot oauth access token.
77
     * @param Client $client        An Http client.
78
     * @param array  $clientOptions options to be send with each request
79
     * @param bool   $wrapResponse  wrap request response in own Response object
80
     *
81
     * @return static
82
     */
83
    public static function createWithToken($token, $client = null, $clientOptions = [], $wrapResponse = true)
84
    {
85
        return new static(['key' => $token, 'oauth' => true], $client, $clientOptions, $wrapResponse);
86
    }
87
88
    /**
89
     * Return an instance of a Resource based on the method called.
90
     *
91
     * @param string $name
92
     * @param array  $arguments
93
     *
94
     * @return \SevenShores\Hubspot\Resources\Resource
95
     */
96
    public function __call($name, $arguments = null)
97
    {
98
        $resource = 'SevenShores\\Hubspot\\Resources\\'.ucfirst($name);
99
100
        return new $resource($this->client);
101
    }
102
}
103