Completed
Pull Request — master (#1)
by Ben
04:36
created

Easychimp   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 8
Bugs 0 Features 3
Metric Value
wmc 6
c 8
b 0
f 3
lcom 1
cbo 4
dl 0
loc 43
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A mailingList() 0 4 1
A __construct() 0 4 1
A validateKey() 0 15 4
1
<?php
2
3
namespace Easychimp;
4
5
use Mailchimp\Mailchimp;
6
7
class Easychimp
8
{
9
10
    /** @var Mailchimp */
11
    protected $api;
12
13
    public function __construct(Mailchimp $api)
14
    {
15
        $this->api = $api;
16
    }
17
18
    /**
19
     * @param $id
20
     *
21
     * @return \Easychimp\MailingList
22
     */
23
    public function mailingList($id)
24
    {
25
        return new MailingList($this->api, new Support(), $id);
26
    }
27
28
    /**
29
     * Determine if an API key is valid
30
     *
31
     * @throws InvalidApiKey
32
     * @throws \Exception
33
     */
34
    public function validateKey()
35
    {
36
        try {
37
            $this->api->get('');
38
        } catch (\Exception $e) {
39
            if (starts_with($e->getMessage(), '{')) {
40
                $json = json_decode($e->getMessage());
41
                if ($json->status == 401) {
42
                    throw new InvalidApiKey($json->detail);
43
                }
44
            }
45
46
            throw $e;
47
        }
48
    }
49
}