Completed
Branch master (ab0b6b)
by Sergey
03:09
created
src/Adapters/GuzzleHttpAdapter.php 1 patch
Indentation   +101 added lines, -101 removed lines patch added patch discarded remove patch
@@ -8,112 +8,112 @@
 block discarded – undo
8 8
 
9 9
 class GuzzleHttpAdapter implements HttpInterface
10 10
 {
11
-    /**
12
-     * @var ClientInterface
13
-     */
14
-    protected $client;
15
-    /**
16
-     * @param ClientInterface $client
17
-     */
18
-    public function __construct(ClientInterface $client)
19
-    {
20
-        $this->client = $client;
21
-    }
22
-
23
-    /**
24
-     * @param string $uri
25
-     * @param array $params
26
-     * @param array $headers
27
-     * @return string
28
-     */
29
-    public function get($uri, $params = [], $headers = [])
30
-    {
31
-        if (!empty($params)) {
32
-            $uri .= '?' . http_build_query($params);
33
-        }
34
-
35
-        $response = $this
36
-            ->client
37
-            ->get($uri, ['headers' => $headers]);
38
-
39
-        return $this->parseResponse($response);
40
-    }
41
-
42
-    /**
43
-     * @param string $uri
44
-     * @param array $body
45
-     * @param array $headers
46
-     * @return string
47
-     */
48
-    public function post($uri, $body = [], $headers = [])
49
-    {
50
-        $response = $this
51
-            ->client
52
-            ->post(
53
-                $uri,
54
-                [
55
-                    'headers' => $headers,
56
-                    'form_params' => $body
57
-                ]
58
-            );
59
-
60
-        return $this->parseResponse($response);
61
-    }
62
-
63
-    /**
64
-     * @param string $uri
65
-     * @param array $body
66
-     * @param array $headers
67
-     * @return mixed
68
-     */
69
-    public function put($uri, $body = [], $headers = [])
70
-    {
71
-        $response = $this
72
-            ->client
73
-            ->put(
74
-                $uri,
75
-                [
76
-                    'headers' => $headers,
77
-                    'form_params'    => $body,
78
-                ]
79
-            );
80
-
81
-        return $this->parseResponse($response);
82
-    }
83
-
84
-    /**
85
-     * @param string $uri
86
-     * @param array $headers
87
-     * @return mixed
88
-     */
89
-    public function delete($uri, $headers = [])
90
-    {
91
-        $response = $this
92
-            ->client
93
-            ->delete($uri, ['headers' => $headers]);
94
-
95
-        return $this->parseResponse($response);
96
-    }
97
-
98
-    /**
99
-     * @param string $url
100
-     * @return $this
101
-     */
102
-    public function setBaseUrl($url)
103
-    {
104
-        $this->client->setBaseUrl($url);
105
-        return $this;
106
-    }
11
+	/**
12
+	 * @var ClientInterface
13
+	 */
14
+	protected $client;
15
+	/**
16
+	 * @param ClientInterface $client
17
+	 */
18
+	public function __construct(ClientInterface $client)
19
+	{
20
+		$this->client = $client;
21
+	}
22
+
23
+	/**
24
+	 * @param string $uri
25
+	 * @param array $params
26
+	 * @param array $headers
27
+	 * @return string
28
+	 */
29
+	public function get($uri, $params = [], $headers = [])
30
+	{
31
+		if (!empty($params)) {
32
+			$uri .= '?' . http_build_query($params);
33
+		}
34
+
35
+		$response = $this
36
+			->client
37
+			->get($uri, ['headers' => $headers]);
38
+
39
+		return $this->parseResponse($response);
40
+	}
41
+
42
+	/**
43
+	 * @param string $uri
44
+	 * @param array $body
45
+	 * @param array $headers
46
+	 * @return string
47
+	 */
48
+	public function post($uri, $body = [], $headers = [])
49
+	{
50
+		$response = $this
51
+			->client
52
+			->post(
53
+				$uri,
54
+				[
55
+					'headers' => $headers,
56
+					'form_params' => $body
57
+				]
58
+			);
59
+
60
+		return $this->parseResponse($response);
61
+	}
62
+
63
+	/**
64
+	 * @param string $uri
65
+	 * @param array $body
66
+	 * @param array $headers
67
+	 * @return mixed
68
+	 */
69
+	public function put($uri, $body = [], $headers = [])
70
+	{
71
+		$response = $this
72
+			->client
73
+			->put(
74
+				$uri,
75
+				[
76
+					'headers' => $headers,
77
+					'form_params'    => $body,
78
+				]
79
+			);
80
+
81
+		return $this->parseResponse($response);
82
+	}
83
+
84
+	/**
85
+	 * @param string $uri
86
+	 * @param array $headers
87
+	 * @return mixed
88
+	 */
89
+	public function delete($uri, $headers = [])
90
+	{
91
+		$response = $this
92
+			->client
93
+			->delete($uri, ['headers' => $headers]);
94
+
95
+		return $this->parseResponse($response);
96
+	}
97
+
98
+	/**
99
+	 * @param string $url
100
+	 * @return $this
101
+	 */
102
+	public function setBaseUrl($url)
103
+	{
104
+		$this->client->setBaseUrl($url);
105
+		return $this;
106
+	}
107 107
 
108 108
 	/**
109 109
 	 * @param ResponseInterface $response
110 110
 	 * @return array|null
111 111
 	 */
112
-    protected function parseResponse(ResponseInterface $response)
113
-    {
114
-        $responseContents = $response->getBody()->getContents();
112
+	protected function parseResponse(ResponseInterface $response)
113
+	{
114
+		$responseContents = $response->getBody()->getContents();
115 115
 
116
-        return json_decode($responseContents, true);
117
-    }
116
+		return json_decode($responseContents, true);
117
+	}
118 118
 
119 119
 }
120 120
\ No newline at end of file
Please login to merge, or discard this patch.
src/Favro.php 2 patches
Indentation   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -9,30 +9,30 @@
 block discarded – undo
9 9
 
10 10
 class Favro
11 11
 {
12
-    /**
13
-     * @param string $login
14
-     * @param string $password
15
-     * @return Api
16
-     */
17
-    public static function create($login, $password)
18
-    {
19
-        $endpointsContainer = new EndpointsContainer(
20
-            self::getHttpInterfaceAdapter($login, $password)
21
-        );
22
-        return new Api($endpointsContainer);
23
-    }
12
+	/**
13
+	 * @param string $login
14
+	 * @param string $password
15
+	 * @return Api
16
+	 */
17
+	public static function create($login, $password)
18
+	{
19
+		$endpointsContainer = new EndpointsContainer(
20
+			self::getHttpInterfaceAdapter($login, $password)
21
+		);
22
+		return new Api($endpointsContainer);
23
+	}
24 24
 
25
-    /**
26
-     * @param string $login
27
-     * @param string $password
28
-     * @return GuzzleHttpAdapter
29
-     */
30
-    protected static function getHttpInterfaceAdapter($login, $password)
31
-    {
32
-        return new GuzzleHttpAdapter(
33
-            new Client(['auth' => [$login, $password]])
34
-        );
35
-    }
25
+	/**
26
+	 * @param string $login
27
+	 * @param string $password
28
+	 * @return GuzzleHttpAdapter
29
+	 */
30
+	protected static function getHttpInterfaceAdapter($login, $password)
31
+	{
32
+		return new GuzzleHttpAdapter(
33
+			new Client(['auth' => [$login, $password]])
34
+		);
35
+	}
36 36
 
37 37
 	private function __construct(){}
38 38
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@
 block discarded – undo
34 34
         );
35 35
     }
36 36
 
37
-	private function __construct(){}
37
+	private function __construct() {}
38 38
 
39
-	private function __clone(){}
39
+	private function __clone() {}
40 40
 }
41 41
\ No newline at end of file
Please login to merge, or discard this patch.
src/Contracts/HttpInterface.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 HttpInterface
6 6
 {
7
-    /**
8
-     * @param $uri
9
-     * @param array $params
10
-     * @param array $headers
11
-     * @return array
12
-     */
13
-    public function get($uri, $params = [], $headers = []);
7
+	/**
8
+	 * @param $uri
9
+	 * @param array $params
10
+	 * @param array $headers
11
+	 * @return array
12
+	 */
13
+	public function get($uri, $params = [], $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, $body = [], $headers = []);
15
+	/**
16
+	 * @param string $uri
17
+	 * @param array $body
18
+	 * @param array $headers
19
+	 * @return array
20
+	 */
21
+	public function post($uri, $body = [], $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, $body = [], $headers = []);
23
+	/**
24
+	 * @param string $uri
25
+	 * @param array $body
26
+	 * @param array $headers
27
+	 * @return mixed
28
+	 */
29
+	public function put($uri, $body = [], $headers = []);
30 30
 
31
-    /**
32
-     * @param string $uri
33
-     * @param array $headers
34
-     * @return mixed
35
-     */
36
-    public function delete($uri, $headers = []);
31
+	/**
32
+	 * @param string $uri
33
+	 * @param array $headers
34
+	 * @return mixed
35
+	 */
36
+	public function delete($uri, $headers = []);
37 37
 
38
-    /**
39
-     * @param string $url
40
-     * @return $this
41
-     */
42
-    public function setBaseUrl($url);
38
+	/**
39
+	 * @param string $url
40
+	 * @return $this
41
+	 */
42
+	public function setBaseUrl($url);
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Api.php 2 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -25,10 +25,10 @@  discard block
 block discarded – undo
25 25
  */
26 26
 class Api
27 27
 {
28
-    /**
29
-     * @var EndpointsContainer
30
-     */
31
-    protected $endpointsContainer;
28
+	/**
29
+	 * @var EndpointsContainer
30
+	 */
31
+	protected $endpointsContainer;
32 32
 
33 33
 	/**
34 34
 	 * @var string
@@ -37,28 +37,28 @@  discard block
 block discarded – undo
37 37
 
38 38
 
39 39
 	public function __construct(EndpointsContainer $endpointsContainer)
40
-    {
41
-        $this->endpointsContainer = $endpointsContainer;
42
-    }
40
+	{
41
+		$this->endpointsContainer = $endpointsContainer;
42
+	}
43 43
 
44
-    /**
45
-     * Magic method to access different endpoints.
46
-     *
47
-     * @param string $endpoint
48
-     *
49
-     * @return Endpoint
50
-     */
51
-    public function __get($endpoint)
52
-    {
53
-        $endpoint = $this->endpointsContainer
54
-	        ->resolveEndpoint($endpoint);
44
+	/**
45
+	 * Magic method to access different endpoints.
46
+	 *
47
+	 * @param string $endpoint
48
+	 *
49
+	 * @return Endpoint
50
+	 */
51
+	public function __get($endpoint)
52
+	{
53
+		$endpoint = $this->endpointsContainer
54
+			->resolveEndpoint($endpoint);
55 55
 
56
-	    if(method_exists($endpoint, 'setOrganizationId')) {
57
-	    	$endpoint->setOrganizationId($this->organizationId);
58
-	    }
56
+		if(method_exists($endpoint, 'setOrganizationId')) {
57
+			$endpoint->setOrganizationId($this->organizationId);
58
+		}
59 59
 
60
-	    return $endpoint;
61
-    }
60
+		return $endpoint;
61
+	}
62 62
 
63 63
 	/**
64 64
 	 * @param int $organizationId
@@ -69,5 +69,5 @@  discard block
 block discarded – undo
69 69
 		$this->organizationId = $organizationId;
70 70
 
71 71
 		return $this;
72
-    }
72
+	}
73 73
 }
74 74
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
         $endpoint = $this->endpointsContainer
54 54
 	        ->resolveEndpoint($endpoint);
55 55
 
56
-	    if(method_exists($endpoint, 'setOrganizationId')) {
56
+	    if (method_exists($endpoint, 'setOrganizationId')) {
57 57
 	    	$endpoint->setOrganizationId($this->organizationId);
58 58
 	    }
59 59
 
Please login to merge, or discard this patch.
src/Api/Endpoints/Collections.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -12,5 +12,5 @@
 block discarded – undo
12 12
 	/**
13 13
 	 * @var string
14 14
 	 */
15
-    protected $endpoint = 'collections';
15
+	protected $endpoint = 'collections';
16 16
 }
17 17
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Users.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,5 +11,5 @@
 block discarded – undo
11 11
 	/**
12 12
 	 * @var string
13 13
 	 */
14
-    protected $endpoint = 'users';
14
+	protected $endpoint = 'users';
15 15
 }
16 16
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/EndpointsContainer.php 1 patch
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -8,65 +8,65 @@
 block discarded – undo
8 8
 
9 9
 class EndpointsContainer
10 10
 {
11
-    const ENDPOINTS_NAMESPACE = 'seregazhuk\\Favro\\Api\\Endpoints\\';
11
+	const ENDPOINTS_NAMESPACE = 'seregazhuk\\Favro\\Api\\Endpoints\\';
12 12
 
13
-     /*
13
+	 /*
14 14
      * @var HttpInterface
15 15
      */
16
-    protected $http;
16
+	protected $http;
17 17
 
18
-    /*
18
+	/*
19 19
      * @var array
20 20
      */
21
-    protected $endpoints = [];
21
+	protected $endpoints = [];
22 22
 
23 23
 	/**
24 24
 	 * @param HttpInterface $http
25 25
 	 */
26
-    public function __construct(HttpInterface $http)
27
-    {
28
-        $this->http = $http;
29
-    }
26
+	public function __construct(HttpInterface $http)
27
+	{
28
+		$this->http = $http;
29
+	}
30 30
 
31 31
 	/**
32 32
 	 * @param string $endpoint
33 33
 	 * @return Endpoint
34 34
 	 */
35
-    public function resolveEndpoint($endpoint)
36
-    {
37
-        $endpoint = strtolower($endpoint);
35
+	public function resolveEndpoint($endpoint)
36
+	{
37
+		$endpoint = strtolower($endpoint);
38 38
 
39
-        // Check if an instance has already been initiated
40
-        if (!isset($this->endpoints[$endpoint])) {
41
-            $this->addProvider($endpoint);
42
-        }
39
+		// Check if an instance has already been initiated
40
+		if (!isset($this->endpoints[$endpoint])) {
41
+			$this->addProvider($endpoint);
42
+		}
43 43
 
44
-        return $this->endpoints[$endpoint];
45
-    }
44
+		return $this->endpoints[$endpoint];
45
+	}
46 46
 
47 47
 	/**
48 48
 	 * @param $endpoint
49 49
 	 * @throws BadEndpointException
50 50
 	 */
51
-    protected function addProvider($endpoint)
52
-    {
53
-        $className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint);
51
+	protected function addProvider($endpoint)
52
+	{
53
+		$className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint);
54 54
 
55
-        if (!class_exists($className)) {
56
-            throw new BadEndpointException("Endpoint $className not found.");
57
-        }
55
+		if (!class_exists($className)) {
56
+			throw new BadEndpointException("Endpoint $className not found.");
57
+		}
58 58
 
59
-        $this->endpoints[$endpoint] = $this->buildEndpoint($className);
60
-    }
59
+		$this->endpoints[$endpoint] = $this->buildEndpoint($className);
60
+	}
61 61
 
62 62
 
63 63
 	/**
64 64
 	 * @param string $className
65 65
 	 * @return Endpoint|object
66 66
 	 */
67
-    protected function buildEndpoint($className)
68
-    {
69
-        return (new ReflectionClass($className))
70
-            ->newInstanceArgs([$this->http]);
71
-    }
67
+	protected function buildEndpoint($className)
68
+	{
69
+		return (new ReflectionClass($className))
70
+			->newInstanceArgs([$this->http]);
71
+	}
72 72
 }
73 73
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Organizations.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@
 block discarded – undo
11 11
 	/**
12 12
 	 * @var string
13 13
 	 */
14
-    protected $endpoint = 'organizations';
14
+	protected $endpoint = 'organizations';
15 15
 
16 16
 	/**
17 17
 	 * @param string $id
Please login to merge, or discard this patch.
src/Api/Endpoints/Endpoint.php 1 patch
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -11,43 +11,43 @@  discard block
 block discarded – undo
11 11
 	 */
12 12
 	protected $allowedMethods = [
13 13
 		'getById',
14
-	    'getAll',
15
-	    'create',
16
-	    'update',
17
-	    'delete'
14
+		'getAll',
15
+		'create',
16
+		'update',
17
+		'delete'
18 18
 	];
19 19
 
20
-    /**
21
-     * @var string
22
-     */
23
-    protected $endpoint;
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected $endpoint;
24 24
 
25 25
 	/**
26 26
 	 * @var array
27 27
 	 */
28 28
 	protected $headers = [];
29 29
 
30
-    /**
31
-     * @var HttpInterface
32
-     */
33
-    protected $http;
30
+	/**
31
+	 * @var HttpInterface
32
+	 */
33
+	protected $http;
34 34
 
35 35
 	/**
36 36
 	 * @param HttpInterface $http
37 37
 	 */
38
-    public function __construct(HttpInterface $http)
39
-    {
40
-        $this->http = $http;
41
-    }
38
+	public function __construct(HttpInterface $http)
39
+	{
40
+		$this->http = $http;
41
+	}
42 42
 
43
-    /**
44
-     * @param string $verb
45
-     * @return string
46
-     */
47
-    public function makeRequestUrl($verb = '')
48
-    {
49
-        return "https://favro.com/api/v1/{$this->endpoint}/$verb";
50
-    }
43
+	/**
44
+	 * @param string $verb
45
+	 * @return string
46
+	 */
47
+	public function makeRequestUrl($verb = '')
48
+	{
49
+		return "https://favro.com/api/v1/{$this->endpoint}/$verb";
50
+	}
51 51
 
52 52
 	/**
53 53
 	 * @param string $method
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 	public function isMethodAllowed($method)
57 57
 	{
58 58
 		return in_array($method, $this->allowedMethods);
59
-    }
59
+	}
60 60
 
61 61
 	/**
62 62
 	 * @return HttpInterface
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
 	public function getHttp()
65 65
 	{
66 66
 		return $this->http;
67
-    }
67
+	}
68 68
 
69 69
 	/**
70 70
 	 * @param array $params
Please login to merge, or discard this patch.