Test Setup Failed
Pull Request — master (#11)
by
unknown
05:17
created
src/Api/Endpoints/Widgets.php 1 patch
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -4,29 +4,29 @@
 block discarded – undo
4 4
 
5 5
 class Widgets extends CrudEndpoint
6 6
 {
7
-    /**
8
-     * @param string $itemId
9
-     * @param string|null $collectionId
10
-     * @return mixed
11
-     */
12
-    public function delete($itemId, $collectionId = null)
13
-    {
14
-        $attributes = $collectionId ? ['collectionId' => $collectionId] : [];
7
+	/**
8
+	 * @param string $itemId
9
+	 * @param string|null $collectionId
10
+	 * @return mixed
11
+	 */
12
+	public function delete($itemId, $collectionId = null)
13
+	{
14
+		$attributes = $collectionId ? ['collectionId' => $collectionId] : [];
15 15
 
16
-        return $this
17
-            ->http
18
-            ->delete(
19
-                $this->makeRequestUrl($itemId),
20
-                $attributes,
21
-                $this->headers()
22
-            );
23
-    }
16
+		return $this
17
+			->http
18
+			->delete(
19
+				$this->makeRequestUrl($itemId),
20
+				$attributes,
21
+				$this->headers()
22
+			);
23
+	}
24 24
 
25
-    /**
26
-     * {@inheritdoc}
27
-     */
28
-    public function endpoint()
29
-    {
30
-        return 'widgets';
31
-    }
25
+	/**
26
+	 * {@inheritdoc}
27
+	 */
28
+	public function endpoint()
29
+	{
30
+		return 'widgets';
31
+	}
32 32
 }
Please login to merge, or discard this patch.
src/Api/Endpoints/CrudEndpoint.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -4,52 +4,52 @@
 block discarded – undo
4 4
 
5 5
 abstract class CrudEndpoint extends Endpoint
6 6
 {
7
-    /**
8
-     * @param array $attributes
9
-     * @return array
10
-     */
11
-    public function create(array $attributes)
12
-    {
13
-        return $this
14
-            ->http
15
-            ->post(
16
-                $this->makeRequestUrl(),
17
-                $attributes,
18
-                $this->headers()
19
-            );
20
-    }
7
+	/**
8
+	 * @param array $attributes
9
+	 * @return array
10
+	 */
11
+	public function create(array $attributes)
12
+	{
13
+		return $this
14
+			->http
15
+			->post(
16
+				$this->makeRequestUrl(),
17
+				$attributes,
18
+				$this->headers()
19
+			);
20
+	}
21 21
 
22
-    /**
23
-     * @param string $itemId
24
-     * @param array $attributes
25
-     * @return mixed
26
-     */
27
-    public function update($itemId, array $attributes)
28
-    {
29
-        return $this
30
-            ->http
31
-            ->put(
32
-                $this->makeRequestUrl($itemId),
33
-                $attributes,
34
-                $this->headers()
35
-            );
36
-    }
22
+	/**
23
+	 * @param string $itemId
24
+	 * @param array $attributes
25
+	 * @return mixed
26
+	 */
27
+	public function update($itemId, array $attributes)
28
+	{
29
+		return $this
30
+			->http
31
+			->put(
32
+				$this->makeRequestUrl($itemId),
33
+				$attributes,
34
+				$this->headers()
35
+			);
36
+	}
37 37
 
38
-    /**
39
-     * @param string $itemId
40
-     * @param bool $everywhere
41
-     * @return mixed
42
-     */
43
-    public function delete($itemId, $everywhere = false)
44
-    {
45
-        $params = $everywhere ? ['everywhere' => $everywhere] : [];
38
+	/**
39
+	 * @param string $itemId
40
+	 * @param bool $everywhere
41
+	 * @return mixed
42
+	 */
43
+	public function delete($itemId, $everywhere = false)
44
+	{
45
+		$params = $everywhere ? ['everywhere' => $everywhere] : [];
46 46
 
47
-        return $this
48
-            ->http
49
-            ->delete(
50
-                $this->makeRequestUrl($itemId),
51
-                $params,
52
-                $this->headers()
53
-            );
54
-    }
47
+		return $this
48
+			->http
49
+			->delete(
50
+				$this->makeRequestUrl($itemId),
51
+				$params,
52
+				$this->headers()
53
+			);
54
+	}
55 55
 }
Please login to merge, or discard this patch.
src/Api/Endpoints/Organizations.php 1 patch
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -5,30 +5,30 @@
 block discarded – undo
5 5
 
6 6
 class Organizations extends CrudEndpoint
7 7
 {
8
-    /**
9
-     * @param string $id
10
-     * @return array
11
-     */
12
-    public function getById($id)
13
-    {
14
-        return $this->withOrganization($id)->getById($id);
15
-    }
8
+	/**
9
+	 * @param string $id
10
+	 * @return array
11
+	 */
12
+	public function getById($id)
13
+	{
14
+		return $this->withOrganization($id)->getById($id);
15
+	}
16 16
 
17
-    /**
18
-     * @param string $itemId
19
-     * @param array $attributes
20
-     * @return mixed
21
-     */
22
-    public function update($itemId, array $attributes)
23
-    {
24
-        return $this->withOrganization($itemId)->update($itemId, $attributes);
25
-    }
17
+	/**
18
+	 * @param string $itemId
19
+	 * @param array $attributes
20
+	 * @return mixed
21
+	 */
22
+	public function update($itemId, array $attributes)
23
+	{
24
+		return $this->withOrganization($itemId)->update($itemId, $attributes);
25
+	}
26 26
 
27
-    /**
28
-     * {@inheritdoc}
29
-     */
30
-    public function endpoint()
31
-    {
32
-        return 'organizations';
33
-    }
27
+	/**
28
+	 * {@inheritdoc}
29
+	 */
30
+	public function endpoint()
31
+	{
32
+		return 'organizations';
33
+	}
34 34
 }
Please login to merge, or discard this patch.
src/Api/Endpoints/Endpoint.php 1 patch
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -6,97 +6,97 @@
 block discarded – undo
6 6
 
7 7
 abstract class Endpoint
8 8
 {
9
-    /**
10
-     * @var array
11
-     */
12
-    protected $rateLimitInfo;
9
+	/**
10
+	 * @var array
11
+	 */
12
+	protected $rateLimitInfo;
13 13
 
14
-    /**
15
-     * @var array
16
-     */
17
-    protected $headers = [];
14
+	/**
15
+	 * @var array
16
+	 */
17
+	protected $headers = [];
18 18
 
19
-    /**
20
-     * @var HttpClient
21
-     */
22
-    protected $http;
19
+	/**
20
+	 * @var HttpClient
21
+	 */
22
+	protected $http;
23 23
 
24
-    /**
25
-     * @var string
26
-     */
27
-    protected $organizationId;
24
+	/**
25
+	 * @var string
26
+	 */
27
+	protected $organizationId;
28 28
 
29
-    /**
30
-     * @param HttpClient $http
31
-     */
32
-    public function __construct(HttpClient $http)
33
-    {
34
-        $this->http = $http;
35
-    }
29
+	/**
30
+	 * @param HttpClient $http
31
+	 */
32
+	public function __construct(HttpClient $http)
33
+	{
34
+		$this->http = $http;
35
+	}
36 36
 
37
-    /**
38
-     * @param string $verb
39
-     * @return string
40
-     */
41
-    public function makeRequestUrl($verb = '')
42
-    {
43
-        return "https://favro.com/api/v1/{$this->endpoint()}/$verb";
44
-    }
37
+	/**
38
+	 * @param string $verb
39
+	 * @return string
40
+	 */
41
+	public function makeRequestUrl($verb = '')
42
+	{
43
+		return "https://favro.com/api/v1/{$this->endpoint()}/$verb";
44
+	}
45 45
 
46
-    /**
47
-     * @param array $params
48
-     * @return array
49
-     */
50
-    public function getAll(array $params = [])
51
-    {
52
-        return $this
53
-            ->http
54
-            ->get(
55
-                $this->makeRequestUrl(),
56
-                $params,
57
-                $this->headers()
58
-            );
59
-    }
46
+	/**
47
+	 * @param array $params
48
+	 * @return array
49
+	 */
50
+	public function getAll(array $params = [])
51
+	{
52
+		return $this
53
+			->http
54
+			->get(
55
+				$this->makeRequestUrl(),
56
+				$params,
57
+				$this->headers()
58
+			);
59
+	}
60 60
 
61
-    /**
62
-     * @param string $id
63
-     * @return array
64
-     */
65
-    public function getById($id)
66
-    {
67
-        return $this
68
-            ->http
69
-            ->get(
70
-                $this->makeRequestUrl($id),
71
-                [],
72
-                $this->headers()
73
-            );
74
-    }
61
+	/**
62
+	 * @param string $id
63
+	 * @return array
64
+	 */
65
+	public function getById($id)
66
+	{
67
+		return $this
68
+			->http
69
+			->get(
70
+				$this->makeRequestUrl($id),
71
+				[],
72
+				$this->headers()
73
+			);
74
+	}
75 75
 
76
-    /**
77
-     * @return array
78
-     */
79
-    protected function headers()
80
-    {
81
-        return array_merge(
82
-            ['organizationId' => $this->organizationId],
83
-            $this->headers
84
-        );
85
-    }
76
+	/**
77
+	 * @return array
78
+	 */
79
+	protected function headers()
80
+	{
81
+		return array_merge(
82
+			['organizationId' => $this->organizationId],
83
+			$this->headers
84
+		);
85
+	}
86 86
 
87
-    /**
88
-     * @param string $organizationId
89
-     * @return $this
90
-     */
91
-    public function withOrganization($organizationId)
92
-    {
93
-        $this->organizationId = $organizationId;
87
+	/**
88
+	 * @param string $organizationId
89
+	 * @return $this
90
+	 */
91
+	public function withOrganization($organizationId)
92
+	{
93
+		$this->organizationId = $organizationId;
94 94
 
95
-        return $this;
96
-    }
95
+		return $this;
96
+	}
97 97
 
98
-    /**
99
-     * @return string
100
-     */
101
-    abstract public function endpoint();
98
+	/**
99
+	 * @return string
100
+	 */
101
+	abstract public function endpoint();
102 102
 }
Please login to merge, or discard this patch.
src/Api/Api.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -31,102 +31,102 @@
 block discarded – undo
31 31
  */
32 32
 class Api
33 33
 {
34
-    /**
35
-     * @var string
36
-     */
37
-    private $organizationId;
38
-
39
-    /**
40
-     * @var HttpClient
41
-     */
42
-    private $http;
43
-
44
-    /**
45
-     * @var Endpoint[]
46
-     */
47
-    private $endpoints;
48
-
49
-    public function __construct(HttpClient $http, Endpoint ...$endpoints)
50
-    {
51
-        $this->http = $http;
52
-        foreach ($endpoints as $endpoint) {
53
-            $this->endpoints[$endpoint->endpoint()] = $endpoint;
54
-        }
55
-    }
56
-
57
-    /**
58
-     * Magic method to access different endpoints.
59
-     *
60
-     * @param string $alias
61
-     *
62
-     * @return Endpoint
63
-     * @throws WrongEndpoint
64
-     */
65
-    public function __get($alias)
66
-    {
67
-        return $this
68
-            ->resolveEndpoint($alias)
69
-            ->withOrganization($this->organizationId);
70
-    }
71
-
72
-    /**
73
-     * @param string $organizationName
74
-     * @return $this
75
-     * @throws WrongOrganizationName
76
-     */
77
-    public function useOrganization($organizationName)
78
-    {
79
-        if ($organization = $this->getOrganizationByName($organizationName)) {
80
-            $this->organizationId = $organization['organizationId'];
81
-        }
82
-
83
-        return $this;
84
-    }
85
-
86
-    /**
87
-     * @param string $organizationName
88
-     * @return array|bool
89
-     * @throws WrongOrganizationName
90
-     */
91
-    private function getOrganizationByName($organizationName)
92
-    {
93
-        $organizations = $this->organizations->getAll();
94
-        foreach ($organizations['entities'] as $entity) {
95
-            if ($entity['name'] === $organizationName) {
96
-                return $entity;
97
-            }
98
-        }
99
-
100
-        throw new WrongOrganizationName("Organization $organizationName not found!");
101
-    }
102
-
103
-    /**
104
-     * @param string $alias
105
-     * @return Endpoint
106
-     * @throws WrongEndpoint
107
-     */
108
-    private function resolveEndpoint($alias)
109
-    {
110
-        $alias = strtolower($alias);
111
-
112
-        if (isset($this->endpoints[$alias])) {
113
-            return $this->endpoints[$alias];
114
-        }
115
-
116
-        throw new WrongEndpoint("There is no endpoint called $alias.");
117
-    }
118
-
119
-    /**
120
-     * @return array
121
-     */
122
-    public function getRateInfo()
123
-    {
124
-        $responseHeaders = $this->http->getResponseHeaders();
125
-
126
-        return [
127
-            'reset'     => $responseHeaders['X-RateLimit-Reset'][0],
128
-            'limit'     => $responseHeaders['X-RateLimit-Limit'][0],
129
-            'remaining' => $responseHeaders['X-RateLimit-Remaining'][0],
130
-        ];
131
-    }
34
+	/**
35
+	 * @var string
36
+	 */
37
+	private $organizationId;
38
+
39
+	/**
40
+	 * @var HttpClient
41
+	 */
42
+	private $http;
43
+
44
+	/**
45
+	 * @var Endpoint[]
46
+	 */
47
+	private $endpoints;
48
+
49
+	public function __construct(HttpClient $http, Endpoint ...$endpoints)
50
+	{
51
+		$this->http = $http;
52
+		foreach ($endpoints as $endpoint) {
53
+			$this->endpoints[$endpoint->endpoint()] = $endpoint;
54
+		}
55
+	}
56
+
57
+	/**
58
+	 * Magic method to access different endpoints.
59
+	 *
60
+	 * @param string $alias
61
+	 *
62
+	 * @return Endpoint
63
+	 * @throws WrongEndpoint
64
+	 */
65
+	public function __get($alias)
66
+	{
67
+		return $this
68
+			->resolveEndpoint($alias)
69
+			->withOrganization($this->organizationId);
70
+	}
71
+
72
+	/**
73
+	 * @param string $organizationName
74
+	 * @return $this
75
+	 * @throws WrongOrganizationName
76
+	 */
77
+	public function useOrganization($organizationName)
78
+	{
79
+		if ($organization = $this->getOrganizationByName($organizationName)) {
80
+			$this->organizationId = $organization['organizationId'];
81
+		}
82
+
83
+		return $this;
84
+	}
85
+
86
+	/**
87
+	 * @param string $organizationName
88
+	 * @return array|bool
89
+	 * @throws WrongOrganizationName
90
+	 */
91
+	private function getOrganizationByName($organizationName)
92
+	{
93
+		$organizations = $this->organizations->getAll();
94
+		foreach ($organizations['entities'] as $entity) {
95
+			if ($entity['name'] === $organizationName) {
96
+				return $entity;
97
+			}
98
+		}
99
+
100
+		throw new WrongOrganizationName("Organization $organizationName not found!");
101
+	}
102
+
103
+	/**
104
+	 * @param string $alias
105
+	 * @return Endpoint
106
+	 * @throws WrongEndpoint
107
+	 */
108
+	private function resolveEndpoint($alias)
109
+	{
110
+		$alias = strtolower($alias);
111
+
112
+		if (isset($this->endpoints[$alias])) {
113
+			return $this->endpoints[$alias];
114
+		}
115
+
116
+		throw new WrongEndpoint("There is no endpoint called $alias.");
117
+	}
118
+
119
+	/**
120
+	 * @return array
121
+	 */
122
+	public function getRateInfo()
123
+	{
124
+		$responseHeaders = $this->http->getResponseHeaders();
125
+
126
+		return [
127
+			'reset'     => $responseHeaders['X-RateLimit-Reset'][0],
128
+			'limit'     => $responseHeaders['X-RateLimit-Limit'][0],
129
+			'remaining' => $responseHeaders['X-RateLimit-Remaining'][0],
130
+		];
131
+	}
132 132
 }
Please login to merge, or discard this patch.
src/Contracts/HttpClient.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -4,40 +4,40 @@
 block discarded – undo
4 4
 
5 5
 interface HttpClient
6 6
 {
7
-    /**
8
-     * @param string $uri
9
-     * @param array $params
10
-     * @param array $headers
11
-     * @return array
12
-     */
13
-    public function get($uri, array $params = [], array $headers = []);
7
+	/**
8
+	 * @param string $uri
9
+	 * @param array $params
10
+	 * @param array $headers
11
+	 * @return array
12
+	 */
13
+	public function get($uri, array $params = [], array $headers = []);
14 14
 
15
-    /**
16
-     * @param string $uri
17
-     * @param array $body
18
-     * @param array $headers
19
-     * @return array
20
-     */
21
-    public function post($uri, array $body = [], array $headers = []);
15
+	/**
16
+	 * @param string $uri
17
+	 * @param array $body
18
+	 * @param array $headers
19
+	 * @return array
20
+	 */
21
+	public function post($uri, array $body = [], array $headers = []);
22 22
 
23
-    /**
24
-     * @param string $uri
25
-     * @param array $body
26
-     * @param array $headers
27
-     * @return mixed
28
-     */
29
-    public function put($uri, array $body = [], array $headers = []);
23
+	/**
24
+	 * @param string $uri
25
+	 * @param array $body
26
+	 * @param array $headers
27
+	 * @return mixed
28
+	 */
29
+	public function put($uri, array $body = [], array $headers = []);
30 30
 
31
-    /**
32
-     * @param string $uri
33
-     * @param array $body
34
-     * @param array $headers
35
-     * @return mixed
36
-     */
37
-    public function delete($uri, array $body = [], array $headers = []);
31
+	/**
32
+	 * @param string $uri
33
+	 * @param array $body
34
+	 * @param array $headers
35
+	 * @return mixed
36
+	 */
37
+	public function delete($uri, array $body = [], array $headers = []);
38 38
 
39
-    /**
40
-     * @return array
41
-     */
42
-    public function getResponseHeaders();
39
+	/**
40
+	 * @return array
41
+	 */
42
+	public function getResponseHeaders();
43 43
 }
Please login to merge, or discard this patch.