Completed
Push — master ( 3170d8...c44a53 )
by Sergey
05:08
created
src/Api/Endpoints/EndpointsContainer.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
     }
46 46
 
47 47
     /**
48
-     * @param $endpoint
48
+     * @param string $endpoint
49 49
      * @throws WrongEndpoint
50 50
      */
51 51
     protected function addProvider($endpoint)
Please login to merge, or discard this patch.
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -8,63 +8,63 @@
 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
-    /**
24
-     * @param HttpClient $http
25
-     */
26
-    public function __construct(HttpClient $http)
27
-    {
28
-        $this->http = $http;
29
-    }
23
+	/**
24
+	 * @param HttpClient $http
25
+	 */
26
+	public function __construct(HttpClient $http)
27
+	{
28
+		$this->http = $http;
29
+	}
30 30
 
31
-    /**
32
-     * @param string $endpoint
33
-     * @return Endpoint
34
-     */
35
-    public function resolve($endpoint)
36
-    {
37
-        $endpoint = strtolower($endpoint);
31
+	/**
32
+	 * @param string $endpoint
33
+	 * @return Endpoint
34
+	 */
35
+	public function resolve($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
-    /**
48
-     * @param $endpoint
49
-     * @throws WrongEndpoint
50
-     */
51
-    protected function addProvider($endpoint)
52
-    {
53
-        $className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint);
47
+	/**
48
+	 * @param $endpoint
49
+	 * @throws WrongEndpoint
50
+	 */
51
+	protected function addProvider($endpoint)
52
+	{
53
+		$className = self::ENDPOINTS_NAMESPACE . ucfirst($endpoint);
54 54
 
55
-        if (!class_exists($className)) {
56
-            throw new WrongEndpoint("Endpoint $className not found.");
57
-        }
55
+		if (!class_exists($className)) {
56
+			throw new WrongEndpoint("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
-    /**
63
-     * @param string $className
64
-     * @return Endpoint|object
65
-     */
66
-    protected function buildEndpoint($className)
67
-    {
68
-        return (new ReflectionClass($className))->newInstanceArgs([$this->http]);
69
-    }
62
+	/**
63
+	 * @param string $className
64
+	 * @return Endpoint|object
65
+	 */
66
+	protected function buildEndpoint($className)
67
+	{
68
+		return (new ReflectionClass($className))->newInstanceArgs([$this->http]);
69
+	}
70 70
 }
71 71
\ No newline at end of file
Please login to merge, or discard this patch.
src/Favro.php 1 patch
Indentation   +29 added lines, -29 removed lines patch added patch discarded remove patch
@@ -8,36 +8,36 @@
 block discarded – undo
8 8
 
9 9
 class Favro
10 10
 {
11
-    /**
12
-     * @param string $login
13
-     * @param string $password
14
-     * @return Api
15
-     */
16
-    public static function create($login, $password)
17
-    {
18
-        $endpointsContainer = new EndpointsContainer(
19
-            self::getHttpInterfaceAdapter($login, $password)
20
-        );
21
-        return new Api($endpointsContainer);
22
-    }
11
+	/**
12
+	 * @param string $login
13
+	 * @param string $password
14
+	 * @return Api
15
+	 */
16
+	public static function create($login, $password)
17
+	{
18
+		$endpointsContainer = new EndpointsContainer(
19
+			self::getHttpInterfaceAdapter($login, $password)
20
+		);
21
+		return new Api($endpointsContainer);
22
+	}
23 23
 
24
-    /**
25
-     * @param string $login
26
-     * @param string $password
27
-     * @return GuzzleHttpClient
28
-     */
29
-    protected static function getHttpInterfaceAdapter($login, $password)
30
-    {
31
-        return new GuzzleHttpClient(
32
-            new Client(['auth' => [$login, $password]])
33
-        );
34
-    }
24
+	/**
25
+	 * @param string $login
26
+	 * @param string $password
27
+	 * @return GuzzleHttpClient
28
+	 */
29
+	protected static function getHttpInterfaceAdapter($login, $password)
30
+	{
31
+		return new GuzzleHttpClient(
32
+			new Client(['auth' => [$login, $password]])
33
+		);
34
+	}
35 35
 
36
-    private function __construct()
37
-    {
38
-    }
36
+	private function __construct()
37
+	{
38
+	}
39 39
 
40
-    private function __clone()
41
-    {
42
-    }
40
+	private function __clone()
41
+	{
42
+	}
43 43
 }
44 44
\ No newline at end of file
Please login to merge, or discard this patch.
src/Contracts/HttpClient.php 1 patch
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -4,41 +4,41 @@
 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 $body
34
-     * @param array $headers
35
-     * @return mixed
36
-     */
37
-    public function delete($uri, $body = [], $headers = []);
31
+	/**
32
+	 * @param string $uri
33
+	 * @param array $body
34
+	 * @param array $headers
35
+	 * @return mixed
36
+	 */
37
+	public function delete($uri, $body = [], $headers = []);
38 38
 
39
-    /**
40
-     * @param string $url
41
-     * @return $this
42
-     */
43
-    public function setBaseUrl($url);
39
+	/**
40
+	 * @param string $url
41
+	 * @return $this
42
+	 */
43
+	public function setBaseUrl($url);
44 44
 }
45 45
\ No newline at end of file
Please login to merge, or discard this patch.
src/GuzzleHttpClient.php 1 patch
Indentation   +110 added lines, -110 removed lines patch added patch discarded remove patch
@@ -8,115 +8,115 @@
 block discarded – undo
8 8
 
9 9
 class GuzzleHttpAdapter implements HttpInterface
10 10
 {
11
-    /**
12
-     * @var ClientInterface
13
-     */
14
-    protected $client;
15
-
16
-    /**
17
-     * @param ClientInterface $client
18
-     */
19
-    public function __construct(ClientInterface $client)
20
-    {
21
-        $this->client = $client;
22
-    }
23
-
24
-    /**
25
-     * @param string $uri
26
-     * @param array $params
27
-     * @param array $headers
28
-     * @return string
29
-     */
30
-    public function get($uri, $params = [], $headers = [])
31
-    {
32
-        if (!empty($params)) {
33
-            $uri .= '?' . http_build_query($params);
34
-        }
35
-
36
-        $response = $this
37
-            ->client
38
-            ->get($uri, ['headers' => $headers]);
39
-
40
-        return $this->parseResponse($response);
41
-    }
42
-
43
-    /**
44
-     * @param string $uri
45
-     * @param array $body
46
-     * @param array $headers
47
-     * @return string
48
-     */
49
-    public function post($uri, $body = [], $headers = [])
50
-    {
51
-        $response = $this
52
-            ->client
53
-            ->post(
54
-                $uri, [
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
-                    'headers'     => $headers,
76
-                    'form_params' => $body,
77
-                ]
78
-            );
79
-
80
-        return $this->parseResponse($response);
81
-    }
82
-
83
-    /**
84
-     * @param string $uri
85
-     * @param array $body
86
-     * @param array $headers
87
-     * @return mixed
88
-     */
89
-    public function delete($uri, $body = [], $headers = [])
90
-    {
91
-        $response = $this
92
-            ->client
93
-            ->delete($uri, [
94
-                'headers'     => $headers,
95
-                'form_params' => $body,
96
-            ]);
97
-
98
-        return $this->parseResponse($response);
99
-    }
100
-
101
-    /**
102
-     * @param string $url
103
-     * @return $this
104
-     */
105
-    public function setBaseUrl($url)
106
-    {
107
-        $this->client->setBaseUrl($url);
108
-        return $this;
109
-    }
110
-
111
-    /**
112
-     * @param ResponseInterface $response
113
-     * @return array|null
114
-     */
115
-    protected function parseResponse(ResponseInterface $response)
116
-    {
117
-        $responseContents = $response->getBody()->getContents();
118
-
119
-        return json_decode($responseContents, true);
120
-    }
11
+	/**
12
+	 * @var ClientInterface
13
+	 */
14
+	protected $client;
15
+
16
+	/**
17
+	 * @param ClientInterface $client
18
+	 */
19
+	public function __construct(ClientInterface $client)
20
+	{
21
+		$this->client = $client;
22
+	}
23
+
24
+	/**
25
+	 * @param string $uri
26
+	 * @param array $params
27
+	 * @param array $headers
28
+	 * @return string
29
+	 */
30
+	public function get($uri, $params = [], $headers = [])
31
+	{
32
+		if (!empty($params)) {
33
+			$uri .= '?' . http_build_query($params);
34
+		}
35
+
36
+		$response = $this
37
+			->client
38
+			->get($uri, ['headers' => $headers]);
39
+
40
+		return $this->parseResponse($response);
41
+	}
42
+
43
+	/**
44
+	 * @param string $uri
45
+	 * @param array $body
46
+	 * @param array $headers
47
+	 * @return string
48
+	 */
49
+	public function post($uri, $body = [], $headers = [])
50
+	{
51
+		$response = $this
52
+			->client
53
+			->post(
54
+				$uri, [
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
+					'headers'     => $headers,
76
+					'form_params' => $body,
77
+				]
78
+			);
79
+
80
+		return $this->parseResponse($response);
81
+	}
82
+
83
+	/**
84
+	 * @param string $uri
85
+	 * @param array $body
86
+	 * @param array $headers
87
+	 * @return mixed
88
+	 */
89
+	public function delete($uri, $body = [], $headers = [])
90
+	{
91
+		$response = $this
92
+			->client
93
+			->delete($uri, [
94
+				'headers'     => $headers,
95
+				'form_params' => $body,
96
+			]);
97
+
98
+		return $this->parseResponse($response);
99
+	}
100
+
101
+	/**
102
+	 * @param string $url
103
+	 * @return $this
104
+	 */
105
+	public function setBaseUrl($url)
106
+	{
107
+		$this->client->setBaseUrl($url);
108
+		return $this;
109
+	}
110
+
111
+	/**
112
+	 * @param ResponseInterface $response
113
+	 * @return array|null
114
+	 */
115
+	protected function parseResponse(ResponseInterface $response)
116
+	{
117
+		$responseContents = $response->getBody()->getContents();
118
+
119
+		return json_decode($responseContents, true);
120
+	}
121 121
 
122 122
 }
123 123
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Api.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -64,7 +64,7 @@
 block discarded – undo
64 64
      */
65 65
     public function setOrganization($organizationName)
66 66
     {
67
-        if($organization = $this->getOrganizationByName($organizationName)) {
67
+        if ($organization = $this->getOrganizationByName($organizationName)) {
68 68
             $this->setOrganizationId($organization['organizationId']);
69 69
         }
70 70
 
Please login to merge, or discard this patch.
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -30,86 +30,86 @@
 block discarded – undo
30 30
  */
31 31
 class Api
32 32
 {
33
-    /**
34
-     * @var EndpointsContainer
35
-     */
36
-    protected $endpointsContainer;
37
-
38
-    /**
39
-     * @var string
40
-     */
41
-    protected $organizationId;
42
-
43
-    public function __construct(EndpointsContainer $endpointsContainer)
44
-    {
45
-        $this->endpointsContainer = $endpointsContainer;
46
-    }
47
-
48
-    /**
49
-     * Magic method to access different endpoints.
50
-     *
51
-     * @param string $endpoint
52
-     *
53
-     * @return Endpoint
54
-     */
55
-    public function __get($endpoint)
56
-    {
57
-        $endpoint = $this->endpointsContainer->resolve($endpoint);
58
-
59
-        if (method_exists($endpoint, 'setOrganizationId')) {
60
-            $endpoint->setOrganizationId($this->organizationId);
61
-        }
62
-
63
-        return $endpoint;
64
-    }
65
-
66
-    /**
67
-     * @param $organizationName
68
-     * @return $this
69
-     */
70
-    public function setOrganization($organizationName)
71
-    {
72
-        if($organization = $this->getOrganizationByName($organizationName)) {
73
-            $this->setOrganizationId($organization['organizationId']);
74
-        }
75
-
76
-        return $this;
77
-    }
78
-
79
-    /**
80
-     * @param int $organizationId
81
-     * @return $this
82
-     */
83
-    public function setOrganizationId($organizationId)
84
-    {
85
-        $this->organizationId = $organizationId;
86
-
87
-        return $this;
88
-    }
89
-
90
-
91
-    /**
92
-     * @return string
93
-     */
94
-    public function getOrganizationId()
95
-    {
96
-        return $this->organizationId;
97
-    }
98
-
99
-    /**
100
-     * @param $organization
101
-     * @return array|bool
102
-     * @throws WrongOrganizationName
103
-     */
104
-    protected function getOrganizationByName($organization)
105
-    {
106
-        $organizations = $this->organizations->getAll();
107
-        foreach ($organizations['entities'] as $entity) {
108
-            if ($entity['name'] == $organization) {
109
-                return $entity;
110
-            }
111
-        }
112
-
113
-        throw new WrongOrganizationName("Organization $organization not found!");
114
-    }
33
+	/**
34
+	 * @var EndpointsContainer
35
+	 */
36
+	protected $endpointsContainer;
37
+
38
+	/**
39
+	 * @var string
40
+	 */
41
+	protected $organizationId;
42
+
43
+	public function __construct(EndpointsContainer $endpointsContainer)
44
+	{
45
+		$this->endpointsContainer = $endpointsContainer;
46
+	}
47
+
48
+	/**
49
+	 * Magic method to access different endpoints.
50
+	 *
51
+	 * @param string $endpoint
52
+	 *
53
+	 * @return Endpoint
54
+	 */
55
+	public function __get($endpoint)
56
+	{
57
+		$endpoint = $this->endpointsContainer->resolve($endpoint);
58
+
59
+		if (method_exists($endpoint, 'setOrganizationId')) {
60
+			$endpoint->setOrganizationId($this->organizationId);
61
+		}
62
+
63
+		return $endpoint;
64
+	}
65
+
66
+	/**
67
+	 * @param $organizationName
68
+	 * @return $this
69
+	 */
70
+	public function setOrganization($organizationName)
71
+	{
72
+		if($organization = $this->getOrganizationByName($organizationName)) {
73
+			$this->setOrganizationId($organization['organizationId']);
74
+		}
75
+
76
+		return $this;
77
+	}
78
+
79
+	/**
80
+	 * @param int $organizationId
81
+	 * @return $this
82
+	 */
83
+	public function setOrganizationId($organizationId)
84
+	{
85
+		$this->organizationId = $organizationId;
86
+
87
+		return $this;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @return string
93
+	 */
94
+	public function getOrganizationId()
95
+	{
96
+		return $this->organizationId;
97
+	}
98
+
99
+	/**
100
+	 * @param $organization
101
+	 * @return array|bool
102
+	 * @throws WrongOrganizationName
103
+	 */
104
+	protected function getOrganizationByName($organization)
105
+	{
106
+		$organizations = $this->organizations->getAll();
107
+		foreach ($organizations['entities'] as $entity) {
108
+			if ($entity['name'] == $organization) {
109
+				return $entity;
110
+			}
111
+		}
112
+
113
+		throw new WrongOrganizationName("Organization $organization not found!");
114
+	}
115 115
 }
116 116
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Users.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
 class Users extends Endpoint
6 6
 {
7 7
 
8
-    /**
9
-     * @var string
10
-     */
11
-    protected $endpoint = 'users';
8
+	/**
9
+	 * @var string
10
+	 */
11
+	protected $endpoint = 'users';
12 12
 }
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/TaskLists.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -5,8 +5,8 @@
 block discarded – undo
5 5
 class TaskLists extends CrudEndpoint
6 6
 {
7 7
 
8
-    /**
9
-     * @var string
10
-     */
11
-    protected $endpoint = 'tasklists';
8
+	/**
9
+	 * @var string
10
+	 */
11
+	protected $endpoint = 'tasklists';
12 12
 }
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Collections.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 class Collections extends CrudEndpoint
6 6
 {
7
-    /**
8
-     * @var string
9
-     */
10
-    protected $endpoint = 'collections';
7
+	/**
8
+	 * @var string
9
+	 */
10
+	protected $endpoint = 'collections';
11 11
 }
12 12
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Tags.php 1 patch
Indentation   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@
 block discarded – undo
4 4
 
5 5
 class Tags extends CrudEndpoint
6 6
 {
7
-    /**
8
-     * @var string
9
-     */
10
-    protected $endpoint = 'tags';
7
+	/**
8
+	 * @var string
9
+	 */
10
+	protected $endpoint = 'tags';
11 11
 }
12 12
\ No newline at end of file
Please login to merge, or discard this patch.