Completed
Push — master ( b1bd72...501a41 )
by Sergey
12:53
created
src/Api/Api.php 1 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/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.
src/Api/Endpoints/Cards.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -4,33 +4,33 @@
 block discarded – undo
4 4
 
5 5
 class Cards extends CrudEndpoint
6 6
 {
7
-    /**
8
-     * @var string
9
-     */
10
-    protected $endpoint = 'cards';
7
+	/**
8
+	 * @var string
9
+	 */
10
+	protected $endpoint = 'cards';
11 11
 
12
-    /**
13
-     * @param string $widgetCommonId
14
-     * @return mixed
15
-     */
16
-    public function getAll($widgetCommonId)
17
-    {
18
-        return parent::getAll(['widgetCommonId'=>$widgetCommonId]);
19
-    }
12
+	/**
13
+	 * @param string $widgetCommonId
14
+	 * @return mixed
15
+	 */
16
+	public function getAll($widgetCommonId)
17
+	{
18
+		return parent::getAll(['widgetCommonId'=>$widgetCommonId]);
19
+	}
20 20
 
21
-    /**
22
-     * @param string $cardId
23
-     * @param bool $everywhere
24
-     * @return mixed
25
-     */
26
-    public function delete($cardId, $everywhere)
27
-    {
28
-        return $this
29
-            ->getHttp()
30
-            ->delete(
31
-                $this->makeRequestUrl($cardId),
32
-                ['everywhere' => $everywhere],
33
-                $this->getHeaders()
34
-            );
35
-    }
21
+	/**
22
+	 * @param string $cardId
23
+	 * @param bool $everywhere
24
+	 * @return mixed
25
+	 */
26
+	public function delete($cardId, $everywhere)
27
+	{
28
+		return $this
29
+			->getHttp()
30
+			->delete(
31
+				$this->makeRequestUrl($cardId),
32
+				['everywhere' => $everywhere],
33
+				$this->getHeaders()
34
+			);
35
+	}
36 36
 }
37 37
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Comments.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 Comments extends CrudEndpoint
6 6
 {
7 7
 
8
-    /**
9
-     * @var string
10
-     */
11
-    protected $endpoint = 'comments';
8
+	/**
9
+	 * @var string
10
+	 */
11
+	protected $endpoint = 'comments';
12 12
 }
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/CrudEndpoint.php 1 patch
Indentation   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -4,49 +4,49 @@
 block discarded – undo
4 4
 
5 5
 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
-            ->getHttp()
15
-            ->post(
16
-                $this->makeRequestUrl(),
17
-                $attributes,
18
-                $this->getHeaders()
19
-            );
20
-    }
7
+	/**
8
+	 * @param array $attributes
9
+	 * @return array
10
+	 */
11
+	public function create(array $attributes)
12
+	{
13
+		return $this
14
+			->getHttp()
15
+			->post(
16
+				$this->makeRequestUrl(),
17
+				$attributes,
18
+				$this->getHeaders()
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
-            ->getHttp()
31
-            ->put(
32
-                $this->makeRequestUrl($itemId),
33
-                $attributes,
34
-                $this->getHeaders()
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
+			->getHttp()
31
+			->put(
32
+				$this->makeRequestUrl($itemId),
33
+				$attributes,
34
+				$this->getHeaders()
35
+			);
36
+	}
37 37
 
38
-    /**
39
-     * @param string $itemId
40
-     * @return mixed
41
-     */
42
-    public function delete($itemId)
43
-    {
44
-        return $this
45
-            ->getHttp()
46
-            ->delete(
47
-                $this->makeRequestUrl($itemId),
48
-                [],
49
-                $this->getHeaders()
50
-            );
51
-    }
38
+	/**
39
+	 * @param string $itemId
40
+	 * @return mixed
41
+	 */
42
+	public function delete($itemId)
43
+	{
44
+		return $this
45
+			->getHttp()
46
+			->delete(
47
+				$this->makeRequestUrl($itemId),
48
+				[],
49
+				$this->getHeaders()
50
+			);
51
+	}
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Columns.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 Columns extends CrudEndpoint
6 6
 {
7
-    /**
8
-     * @var string
9
-     */
10
-    protected $endpoint = 'columns';
7
+	/**
8
+	 * @var string
9
+	 */
10
+	protected $endpoint = 'columns';
11 11
 }
12 12
\ No newline at end of file
Please login to merge, or discard this patch.
src/Api/Endpoints/Endpoint.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -6,112 +6,112 @@
 block discarded – undo
6 6
 
7 7
 class Endpoint
8 8
 {
9
-    /**
10
-     * @var array
11
-     */
12
-    protected $allowedMethods = [
13
-        'getById',
14
-        'getAll',
15
-        'create',
16
-        'update',
17
-        'delete',
18
-    ];
19
-
20
-    /**
21
-     * @var string
22
-     */
23
-    protected $endpoint;
24
-
25
-    /**
26
-     * @var array
27
-     */
28
-    protected $headers = [];
29
-
30
-    /**
31
-     * @var HttpClient
32
-     */
33
-    protected $http;
34
-
35
-    /**
36
-     * @var string
37
-     */
38
-    protected $organizationId;
39
-
40
-    /**
41
-     * @param HttpClient $http
42
-     */
43
-    public function __construct(HttpClient $http)
44
-    {
45
-        $this->http = $http;
46
-    }
47
-
48
-    /**
49
-     * @param string $verb
50
-     * @return string
51
-     */
52
-    public function makeRequestUrl($verb = '')
53
-    {
54
-        return "https://favro.com/api/v1/{$this->endpoint}/$verb";
55
-    }
56
-
57
-    /**
58
-     * @param string $method
59
-     * @return bool
60
-     */
61
-    public function isMethodAllowed($method)
62
-    {
63
-        return in_array($method, $this->allowedMethods);
64
-    }
65
-
66
-    /**
67
-     * @return HttpClient
68
-     */
69
-    public function getHttp()
70
-    {
71
-        return $this->http;
72
-    }
73
-
74
-    /**
75
-     * @param array $params
76
-     * @return array
77
-     */
78
-    public function getAll(array $params = [])
79
-    {
80
-        return $this->getHttp()->get(
81
-            $this->makeRequestUrl(), $params, $this->getHeaders()
82
-        );
83
-    }
84
-
85
-    /**
86
-     * @param string $id
87
-     * @return array
88
-     */
89
-    public function getById($id)
90
-    {
91
-        return $this->getHttp()->get(
92
-            $this->makeRequestUrl($id), [], $this->getHeaders()
93
-        );
94
-    }
95
-
96
-    /**
97
-     * @return array
98
-     */
99
-    protected function getHeaders()
100
-    {
101
-        return array_merge(
102
-            ['organizationId' => $this->organizationId],
103
-            $this->headers
104
-        );
105
-    }
106
-
107
-    /**
108
-     * @param int $organizationId
109
-     * @return $this
110
-     */
111
-    public function setOrganizationId($organizationId)
112
-    {
113
-        $this->organizationId = $organizationId;
114
-
115
-        return $this;
116
-    }
9
+	/**
10
+	 * @var array
11
+	 */
12
+	protected $allowedMethods = [
13
+		'getById',
14
+		'getAll',
15
+		'create',
16
+		'update',
17
+		'delete',
18
+	];
19
+
20
+	/**
21
+	 * @var string
22
+	 */
23
+	protected $endpoint;
24
+
25
+	/**
26
+	 * @var array
27
+	 */
28
+	protected $headers = [];
29
+
30
+	/**
31
+	 * @var HttpClient
32
+	 */
33
+	protected $http;
34
+
35
+	/**
36
+	 * @var string
37
+	 */
38
+	protected $organizationId;
39
+
40
+	/**
41
+	 * @param HttpClient $http
42
+	 */
43
+	public function __construct(HttpClient $http)
44
+	{
45
+		$this->http = $http;
46
+	}
47
+
48
+	/**
49
+	 * @param string $verb
50
+	 * @return string
51
+	 */
52
+	public function makeRequestUrl($verb = '')
53
+	{
54
+		return "https://favro.com/api/v1/{$this->endpoint}/$verb";
55
+	}
56
+
57
+	/**
58
+	 * @param string $method
59
+	 * @return bool
60
+	 */
61
+	public function isMethodAllowed($method)
62
+	{
63
+		return in_array($method, $this->allowedMethods);
64
+	}
65
+
66
+	/**
67
+	 * @return HttpClient
68
+	 */
69
+	public function getHttp()
70
+	{
71
+		return $this->http;
72
+	}
73
+
74
+	/**
75
+	 * @param array $params
76
+	 * @return array
77
+	 */
78
+	public function getAll(array $params = [])
79
+	{
80
+		return $this->getHttp()->get(
81
+			$this->makeRequestUrl(), $params, $this->getHeaders()
82
+		);
83
+	}
84
+
85
+	/**
86
+	 * @param string $id
87
+	 * @return array
88
+	 */
89
+	public function getById($id)
90
+	{
91
+		return $this->getHttp()->get(
92
+			$this->makeRequestUrl($id), [], $this->getHeaders()
93
+		);
94
+	}
95
+
96
+	/**
97
+	 * @return array
98
+	 */
99
+	protected function getHeaders()
100
+	{
101
+		return array_merge(
102
+			['organizationId' => $this->organizationId],
103
+			$this->headers
104
+		);
105
+	}
106
+
107
+	/**
108
+	 * @param int $organizationId
109
+	 * @return $this
110
+	 */
111
+	public function setOrganizationId($organizationId)
112
+	{
113
+		$this->organizationId = $organizationId;
114
+
115
+		return $this;
116
+	}
117 117
 }
118 118
\ No newline at end of file
Please login to merge, or discard this patch.