Completed
Push — master ( d8491f...251a35 )
by Haridarshan
02:20
created
src/InstagramRequest.php 1 patch
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,8 +2,8 @@
 block discarded – undo
2 2
 namespace Haridarshan\Instagram;
3 3
 
4 4
 use Haridarshan\Instagram\Constants;
5
-use Haridarshan\Instagram\Exceptions\InstagramThrottleException;
6 5
 use Haridarshan\Instagram\Exceptions\InstagramRequestException;
6
+use Haridarshan\Instagram\Exceptions\InstagramThrottleException;
7 7
 use Haridarshan\Instagram\HelperFactory;
8 8
 use Haridarshan\Instagram\Instagram;
9 9
 use Haridarshan\Instagram\InstagramResponse;
Please login to merge, or discard this patch.
src/HelperFactory.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -11,33 +11,33 @@  discard block
 block discarded – undo
11 11
 
12 12
 class HelperFactory
13 13
 {
14
-    /** @var Response $response */
15
-    protected static $response;
14
+	/** @var Response $response */
15
+	protected static $response;
16 16
     
17
-    /** @var Stream $stream */
18
-    protected static $stream;
17
+	/** @var Stream $stream */
18
+	protected static $stream;
19 19
     
20
-    /** @var object $content */
21
-    protected static $content;
20
+	/** @var object $content */
21
+	protected static $content;
22 22
     
23
-    private function __construct()
24
-    {
25
-        // a factory constructor should never be invoked
26
-    }
23
+	private function __construct()
24
+	{
25
+		// a factory constructor should never be invoked
26
+	}
27 27
     
28
-    /*
28
+	/*
29 29
      * Factory Client method to create \GuzzleHttp\Client object
30 30
      * @param string $uri
31 31
      * @return Client
32 32
      */
33
-    public static function client($uri)
34
-    {
35
-        return new Client([
36
-            'base_uri' => $uri
37
-        ]);
38
-    }
33
+	public static function client($uri)
34
+	{
35
+		return new Client([
36
+			'base_uri' => $uri
37
+		]);
38
+	}
39 39
     
40
-    /*
40
+	/*
41 41
      * @param Client $client
42 42
      * @param string $endpoint
43 43
      * @param array|string $options
@@ -46,79 +46,79 @@  discard block
 block discarded – undo
46 46
      * @throws InstagramOAuthException
47 47
      * @throws InstagramException
48 48
      */
49
-    public static function request(Client $client, $endpoint, $options, $method = 'GET')
50
-    {
51
-        try {
52
-            return $client->request($method, $endpoint, [
53
-                'headers' => ['Accept' => 'application/json'],
54
-                'body' => static::createBody($options, $method)
55
-            ]);
56
-        } catch (ClientException $e) {
57
-            static::throwException(static::extractOriginalExceptionMessage($e), $e);
58
-        }
59
-    }
49
+	public static function request(Client $client, $endpoint, $options, $method = 'GET')
50
+	{
51
+		try {
52
+			return $client->request($method, $endpoint, [
53
+				'headers' => ['Accept' => 'application/json'],
54
+				'body' => static::createBody($options, $method)
55
+			]);
56
+		} catch (ClientException $e) {
57
+			static::throwException(static::extractOriginalExceptionMessage($e), $e);
58
+		}
59
+	}
60 60
     
61
-    /*
61
+	/*
62 62
      * Create body for Guzzle client request
63 63
      * @param array|null|string $options
64 64
      * @param string $method GET|POST
65 65
      * @return string|mixed
66 66
      */
67
-    protected static function createBody($options, $method)
68
-    {
69
-        return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
70
-    }
67
+	protected static function createBody($options, $method)
68
+	{
69
+		return ('GET' !== $method) ? is_array($options) ? http_build_query($options) : ltrim($options, '&') : null;
70
+	}
71 71
     
72
-    /*
72
+	/*
73 73
      * Method to extract all exceptions for Guzzle ClientException
74 74
      * @param ClientException $e
75 75
      * @return
76 76
      */
77
-    protected static function extractOriginalExceptionMessage(ClientException $e)
78
-    {
79
-        self::$response = $e->getResponse();
80
-        self::$stream = self::$response->getBody();
81
-        self::$content = self::$stream->getContents();
82
-        if (empty(self::$content)) {
83
-            throw new InstagramServerException(
84
-                $e->getMessage(),
85
-                $e->getCode(),
86
-                $e
87
-            );
88
-        } else {
89
-            return json_decode(self::$content);
90
-        }
91
-    }
77
+	protected static function extractOriginalExceptionMessage(ClientException $e)
78
+	{
79
+		self::$response = $e->getResponse();
80
+		self::$stream = self::$response->getBody();
81
+		self::$content = self::$stream->getContents();
82
+		if (empty(self::$content)) {
83
+			throw new InstagramServerException(
84
+				$e->getMessage(),
85
+				$e->getCode(),
86
+				$e
87
+			);
88
+		} else {
89
+			return json_decode(self::$content);
90
+		}
91
+	}
92 92
     
93
-    /*
93
+	/*
94 94
      * @param object $object
95 95
 	 * @param ClientException $e
96 96
      * @return void
97 97
      */
98
-    protected static function throwException(object $object, $e)
99
-    {
100
-        $exception = array();
101
-        if (isset($object->meta)) {
102
-            $exception['error_type'] = $object->meta->error_type;
103
-            $exception['error_message'] = $object->meta->error_message;
104
-            $exception['error_code'] = $object->meta->code;
105
-        } else {
106
-            $exception['error_type'] = $object->error_type;
107
-            $exception['error_message'] = $object->error_message;
108
-            $exception['error_code'] = $object->code;
109
-        }
110
-        if (stripos($exception['error_type'], "oauth") !== false) {
111
-            throw new InstagramOAuthException(
112
-                json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
113
-                $exception['error_code'],
114
-                $e
115
-            );
116
-        } else {
117
-            throw new InstagramException(
118
-                json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
119
-                $exception['error_code'],
120
-                $e
121
-            );
122
-        }
123
-    }
98
+	protected static function throwException(object $object, $e)
99
+	{
100
+		$exception = array();
101
+		if (isset($object->meta)) {
102
+			$exception['error_type'] = $object->meta->error_type;
103
+			$exception['error_message'] = $object->meta->error_message;
104
+			$exception['error_code'] = $object->meta->code;
105
+		} else {
106
+			$exception['error_type'] = $object->error_type;
107
+			$exception['error_message'] = $object->error_message;
108
+			$exception['error_code'] = $object->code;
109
+		}
110
+		if (stripos($exception['error_type'], "oauth") !== false) {
111
+			throw new InstagramOAuthException(
112
+				json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
113
+				$exception['error_code'],
114
+				$e
115
+			);
116
+		} else {
117
+			throw new InstagramException(
118
+				json_encode(array("Type" => $exception['error_type'], "Message" => $exception['error_message'])),
119
+				$exception['error_code'],
120
+				$e
121
+			);
122
+		}
123
+	}
124 124
 }
Please login to merge, or discard this patch.