Completed
Branch master (ff5b0d)
by Tobias
02:37
created
src/Happyr/ApiClient/Http/Client.php 2 patches
Doc Comments   +1 added lines, -5 removed lines patch added patch discarded remove patch
@@ -46,10 +46,8 @@  discard block
 block discarded – undo
46 46
      * be the post variables
47 47
      * @param string $httpVerb (optional) either GET or POST.
48 48
      * will contain the http response code
49
-     * @param boolean $suppressExceptions, (optional) if true, we will catch all HttpExceptions that might be thrown by
50
-     * the Connection class
51 49
      *
52
-     * @return \Happyr\ApiClient\Http\Response
50
+     * @return Response
53 51
      * @throws HttpException
54 52
      */
55 53
     public function sendRequest($uri, array $data=array(), $httpVerb='GET')
@@ -72,8 +70,6 @@  discard block
 block discarded – undo
72 70
     /**
73 71
      * Handle stuff when an error occur
74 72
      *
75
-     * @param string $body
76
-     * @param int $httpStatus
77 73
      *
78 74
      * @return Response
79 75
      * @throws \Happyr\ApiClient\Exceptions\HttpException
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
     public function __construct(Configuration $configuration)
35 35
     {
36 36
         $this->configuration = $configuration;
37
-        $class=$configuration->httpRequestClass;
37
+        $class = $configuration->httpRequestClass;
38 38
         $this->request = new $class();
39 39
     }
40 40
 
@@ -52,13 +52,13 @@  discard block
 block discarded – undo
52 52
      * @return \Happyr\ApiClient\Http\Response
53 53
      * @throws HttpException
54 54
      */
55
-    public function sendRequest($uri, array $data=array(), $httpVerb='GET')
55
+    public function sendRequest($uri, array $data = array(), $httpVerb = 'GET')
56 56
     {
57 57
         //get headers
58 58
         $headers = array_merge($this->getAcceptHeader(), $this->getAuthenticationHeader());
59 59
         $headers['User-Agent'] = 'HappyrApiClient/'.$this->configuration->clientVersion;
60 60
 
61
-        $response=$this->request->send($this->configuration->baseUrl.'/api/'.$uri, $data, $httpVerb, $headers);
61
+        $response = $this->request->send($this->configuration->baseUrl.'/api/'.$uri, $data, $httpVerb, $headers);
62 62
         $response->setFormat($this->configuration->format);
63 63
 
64 64
         //if we got some non good http response code
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
             echo ('Exception: '.$response->getBody()."\n");
85 85
         }
86 86
 
87
-        $exception=new HttpException($response);
87
+        $exception = new HttpException($response);
88 88
 
89 89
         if ($this->configuration->enableExceptions) {
90 90
             //throw exceptions
Please login to merge, or discard this patch.
src/Happyr/ApiClient/Http/Request/CurlRequest.php 2 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      * @param string $httpVerb
21 21
      * @param array $headers
22 22
      *
23
-     * @return mixed
23
+     * @return Response
24 24
      */
25 25
     public function send($uri, array $data = array(), $httpVerb = 'GET', array $headers = array())
26 26
     {
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      * Load the curl object with the post data
103 103
      *
104 104
      *
105
-     * @param $ch
105
+     * @param resource $ch
106 106
      * @param array $data
107 107
      *
108 108
      */
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public function send($uri, array $data = array(), $httpVerb = 'GET', array $headers = array())
26 26
     {
27
-        $ch=curl_init();
27
+        $ch = curl_init();
28 28
 
29
-        $headers=$this->rewriteHeaders($headers);
29
+        $headers = $this->rewriteHeaders($headers);
30 30
 
31 31
         // Set a referrer and user agent
32 32
         if (isset($_SERVER['HTTP_HOST'])) {
@@ -91,10 +91,10 @@  discard block
 block discarded – undo
91 91
 
92 92
         //add the filter on the filter string
93 93
         if (count($filters) > 0) {
94
-            $filterString='?'.http_build_query($filters);
94
+            $filterString = '?'.http_build_query($filters);
95 95
         }
96 96
 
97
-        return $uri . $filterString;
97
+        return $uri.$filterString;
98 98
     }
99 99
 
100 100
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
     protected function preparePostData($ch, array $data = array())
110 110
     {
111 111
         //urlify the data for the POST
112
-        $dataString=http_build_query($data);
112
+        $dataString = http_build_query($data);
113 113
 
114 114
         curl_setopt($ch, CURLOPT_POST, count($data));
115 115
         curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
@@ -126,7 +126,7 @@  discard block
 block discarded – undo
126 126
     {
127 127
         $betterHeaders = array();
128 128
         foreach ($headers as $key =>$value) {
129
-            $betterHeaders[]=sprintf('%s: %s', $key, $value);
129
+            $betterHeaders[] = sprintf('%s: %s', $key, $value);
130 130
         }
131 131
 
132 132
         return $betterHeaders;
Please login to merge, or discard this patch.
src/Happyr/ApiClient/Http/Request/Guzzle.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -25,26 +25,26 @@
 block discarded – undo
25 25
      */
26 26
     public function send($url, array $data = array(), $httpVerb = 'GET', array $headers = array())
27 27
     {
28
-        $options=array(
28
+        $options = array(
29 29
             'headers'=>$headers,
30 30
             'timeout' => 60,
31 31
             'exceptions' => false,
32 32
         );
33 33
 
34 34
         $client = new Client();
35
-        if ($httpVerb=='GET' && count($data)>0) {
36
-            $url.='?'.http_build_query($data);
35
+        if ($httpVerb == 'GET' && count($data) > 0) {
36
+            $url .= '?'.http_build_query($data);
37 37
         } else {
38
-            $options['body']=$data;
38
+            $options['body'] = $data;
39 39
         }
40 40
 
41
-        $request=$client->createRequest($httpVerb, $url, $options);
41
+        $request = $client->createRequest($httpVerb, $url, $options);
42 42
         try {
43
-            $res=$client->send($request);
44
-            $response=new Response($res->getBody(), $res->getStatusCode());
43
+            $res = $client->send($request);
44
+            $response = new Response($res->getBody(), $res->getStatusCode());
45 45
         } catch (RequestException $e) {
46 46
             if ($e->hasResponse()) {
47
-                $response=new Response($res->getBody(), $res->getStatusCode());
47
+                $response = new Response($res->getBody(), $res->getStatusCode());
48 48
             } else {
49 49
                 throw $e;
50 50
             }
Please login to merge, or discard this patch.
src/Happyr/ApiClient/Http/Request/RequestInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -19,6 +19,6 @@
 block discarded – undo
19 19
      *
20 20
      * @return \Happyr\ApiClient\Http\Response\Response
21 21
      */
22
-    public function send($uri, array $data=array(), $httpVerb='GET', array $headers=array());
22
+    public function send($uri, array $data = array(), $httpVerb = 'GET', array $headers = array());
23 23
 
24 24
 }
25 25
\ No newline at end of file
Please login to merge, or discard this patch.
src/Happyr/ApiClient/Http/Wsse.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
         $this->nonce = $this->getRandomString();
38 38
 
39 39
         // calculate the digest
40
-        $this->digest = base64_encode(sha1(base64_decode($this->nonce) . $this->created . $this->password, true));
40
+        $this->digest = base64_encode(sha1(base64_decode($this->nonce).$this->created.$this->password, true));
41 41
     }
42 42
 
43 43
     /**
Please login to merge, or discard this patch.
src/Happyr/ApiClient/HappyrApi.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
      * @param Configuration $config
41 41
      *
42 42
      */
43
-    public function __construct(Configuration $config=null)
43
+    public function __construct(Configuration $config = null)
44 44
     {
45 45
         //if we don't get a configuration object in the parameter, then create one now.
46
-        if ($config==null) {
47
-            $config=new Configuration();
46
+        if ($config == null) {
47
+            $config = new Configuration();
48 48
         }
49 49
 
50
-        $this->configuration=$config;
50
+        $this->configuration = $config;
51 51
     }
52 52
 
53 53
     /**
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
      *
60 60
      * @return \Happyr\ApiClient\Http\Response\Response
61 61
      */
62
-    public function api($uri, array $data=array(), $httpVerb='GET')
62
+    public function api($uri, array $data = array(), $httpVerb = 'GET')
63 63
     {
64 64
         return $this->getHttpClient()->sendRequest($uri, $data, $httpVerb);
65 65
     }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     protected function getHttpClient($forceNew = false)
77 77
     {
78 78
         if (!$this->httpClient || $forceNew) {
79
-            $this->httpClient=new Client($this->configuration);
79
+            $this->httpClient = new Client($this->configuration);
80 80
         }
81 81
 
82 82
         return $this->httpClient;
@@ -155,8 +155,8 @@  discard block
 block discarded – undo
155 155
      */
156 156
     public function getUserToken()
157 157
     {
158
-        $code=$this->getCode();
159
-        $token=$this->api('user/get-token', array('code'=>$code));
158
+        $code = $this->getCode();
159
+        $token = $this->api('user/get-token', array('code'=>$code));
160 160
 
161 161
         return $token->getBody();
162 162
     }
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
     protected function setState($state)
183 183
     {
184 184
         if ($state === null) {
185
-            $_SESSION['happyr_ac_state']=null;
185
+            $_SESSION['happyr_ac_state'] = null;
186 186
         }
187 187
 
188 188
         $this->state = $state;
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
     protected function getState()
198 198
     {
199 199
         if ($this->state === null) {
200
-            $this->state = isset($_SESSION['happyr_ac_state'])?$_SESSION['happyr_ac_state']:null;
200
+            $this->state = isset($_SESSION['happyr_ac_state']) ? $_SESSION['happyr_ac_state'] : null;
201 201
         }
202 202
 
203 203
         return $this->state;
Please login to merge, or discard this patch.
src/Happyr/ApiClient/Configuration.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,16 +10,16 @@  discard block
 block discarded – undo
10 10
 class Configuration
11 11
 {
12 12
     //your api identifier
13
-    public $identifier='';
13
+    public $identifier = '';
14 14
 
15 15
     //Your api secret
16
-    public $secret='';
16
+    public $secret = '';
17 17
 
18 18
     //must not end with a slash (/)
19
-    public $baseUrl='http://api.happyr.com';
19
+    public $baseUrl = 'http://api.happyr.com';
20 20
 
21 21
     //You should have a good reason not to choose xml.
22
-    public $format='xml';
22
+    public $format = 'xml';
23 23
 
24 24
     /**
25 25
      * @var string
@@ -27,29 +27,29 @@  discard block
 block discarded – undo
27 27
      * the class to use when making a http request. The class must implement
28 28
      * the Happyr\ApiClient\Http\HttpRequestInterface
29 29
      */
30
-    public $httpRequestClass='\Happyr\ApiClient\Http\Request\Guzzle';
30
+    public $httpRequestClass = '\Happyr\ApiClient\Http\Request\Guzzle';
31 31
 
32 32
     //if true, we will throw exceptions on error
33
-    public $enableExceptions=false;
33
+    public $enableExceptions = false;
34 34
 
35 35
     //enables debug mode
36
-    public $debug=false;
36
+    public $debug = false;
37 37
 
38 38
     //The version of this client. This is for our statistics only
39
-    public $clientVersion=2.0;
39
+    public $clientVersion = 2.0;
40 40
 
41 41
     /**
42 42
      * @param string $identifier
43 43
      * @param string $secret
44 44
      */
45
-    public function __construct($identifier=null, $secret=null)
45
+    public function __construct($identifier = null, $secret = null)
46 46
     {
47
-        if ($secret!=null) {
48
-            $this->secret=$secret;
47
+        if ($secret != null) {
48
+            $this->secret = $secret;
49 49
         }
50 50
 
51
-        if ($identifier!=null) {
52
-            $this->identifier=$identifier;
51
+        if ($identifier != null) {
52
+            $this->identifier = $identifier;
53 53
         }
54 54
     }
55 55
 }
56 56
\ No newline at end of file
Please login to merge, or discard this patch.
src/Happyr/ApiClient/Exceptions/HttpException.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function __construct(Response $response)
24 24
     {
25
-        $this->response=$response;
25
+        $this->response = $response;
26 26
         $message = $response->getBody();
27 27
         try {
28 28
             $xml = @simplexml_load_string($response);
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
      */
45 45
     public function __toString()
46 46
     {
47
-        return $this->getHttpStatus() . ': ' . $this->getMessage();
47
+        return $this->getHttpStatus().': '.$this->getMessage();
48 48
     }
49 49
 
50 50
     /**
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     public function getEmptyResponse()
86 86
     {
87 87
         $response = clone $this->response;
88
-        if ($response->getFormat()=='json') {
88
+        if ($response->getFormat() == 'json') {
89 89
             $response->setBody('[]');
90 90
         } else {
91 91
             $response->setBody('<?xml version="1.0" encoding="UTF-8"?><result/>');
Please login to merge, or discard this patch.