Test Failed
Pull Request — master (#473)
by Kiran
12:54
created
google-api-php-client/src/Google/Auth/AssertionCredentials.php 2 patches
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -51,22 +51,22 @@  discard block
 block discarded – undo
51 51
    *              automatic caching of the generated token.
52 52
    */
53 53
   public function __construct(
54
-      $serviceAccountName,
55
-      $scopes,
56
-      $privateKey,
57
-      $privateKeyPassword = 'notasecret',
58
-      $assertionType = 'http://oauth.net/grant_type/jwt/1.0/bearer',
59
-      $sub = false,
60
-      $useCache = true
54
+	  $serviceAccountName,
55
+	  $scopes,
56
+	  $privateKey,
57
+	  $privateKeyPassword = 'notasecret',
58
+	  $assertionType = 'http://oauth.net/grant_type/jwt/1.0/bearer',
59
+	  $sub = false,
60
+	  $useCache = true
61 61
   ) {
62
-    $this->serviceAccountName = $serviceAccountName;
63
-    $this->scopes = is_string($scopes) ? $scopes : implode(' ', $scopes);
64
-    $this->privateKey = $privateKey;
65
-    $this->privateKeyPassword = $privateKeyPassword;
66
-    $this->assertionType = $assertionType;
67
-    $this->sub = $sub;
68
-    $this->prn = $sub;
69
-    $this->useCache = $useCache;
62
+	$this->serviceAccountName = $serviceAccountName;
63
+	$this->scopes = is_string($scopes) ? $scopes : implode(' ', $scopes);
64
+	$this->privateKey = $privateKey;
65
+	$this->privateKeyPassword = $privateKeyPassword;
66
+	$this->assertionType = $assertionType;
67
+	$this->sub = $sub;
68
+	$this->prn = $sub;
69
+	$this->useCache = $useCache;
70 70
   }
71 71
   
72 72
   /**
@@ -75,36 +75,36 @@  discard block
 block discarded – undo
75 75
    */
76 76
   public function getCacheKey()
77 77
   {
78
-    if (!$this->useCache) {
79
-      return false;
80
-    }
81
-    $h = $this->sub;
82
-    $h .= $this->assertionType;
83
-    $h .= $this->privateKey;
84
-    $h .= $this->scopes;
85
-    $h .= $this->serviceAccountName;
86
-    return md5($h);
78
+	if (!$this->useCache) {
79
+	  return false;
80
+	}
81
+	$h = $this->sub;
82
+	$h .= $this->assertionType;
83
+	$h .= $this->privateKey;
84
+	$h .= $this->scopes;
85
+	$h .= $this->serviceAccountName;
86
+	return md5($h);
87 87
   }
88 88
 
89 89
   public function generateAssertion()
90 90
   {
91
-    $now = time();
91
+	$now = time();
92 92
 
93
-    $jwtParams = array(
94
-          'aud' => Google_Auth_OAuth2::OAUTH2_TOKEN_URI,
95
-          'scope' => $this->scopes,
96
-          'iat' => $now,
97
-          'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
98
-          'iss' => $this->serviceAccountName,
99
-    );
93
+	$jwtParams = array(
94
+		  'aud' => Google_Auth_OAuth2::OAUTH2_TOKEN_URI,
95
+		  'scope' => $this->scopes,
96
+		  'iat' => $now,
97
+		  'exp' => $now + self::MAX_TOKEN_LIFETIME_SECS,
98
+		  'iss' => $this->serviceAccountName,
99
+	);
100 100
 
101
-    if ($this->sub !== false) {
102
-      $jwtParams['sub'] = $this->sub;
103
-    } else if ($this->prn !== false) {
104
-      $jwtParams['prn'] = $this->prn;
105
-    }
101
+	if ($this->sub !== false) {
102
+	  $jwtParams['sub'] = $this->sub;
103
+	} else if ($this->prn !== false) {
104
+	  $jwtParams['prn'] = $this->prn;
105
+	}
106 106
 
107
-    return $this->makeSignedJwt($jwtParams);
107
+	return $this->makeSignedJwt($jwtParams);
108 108
   }
109 109
 
110 110
   /**
@@ -114,23 +114,23 @@  discard block
 block discarded – undo
114 114
    */
115 115
   private function makeSignedJwt($payload)
116 116
   {
117
-    $header = array('typ' => 'JWT', 'alg' => 'RS256');
117
+	$header = array('typ' => 'JWT', 'alg' => 'RS256');
118 118
 
119
-    $payload = json_encode($payload);
120
-    // Handle some overzealous escaping in PHP json that seemed to cause some errors
121
-    // with claimsets.
122
-    $payload = str_replace('\/', '/', $payload);
119
+	$payload = json_encode($payload);
120
+	// Handle some overzealous escaping in PHP json that seemed to cause some errors
121
+	// with claimsets.
122
+	$payload = str_replace('\/', '/', $payload);
123 123
 
124
-    $segments = array(
125
-      Google_Utils::urlSafeB64Encode(json_encode($header)),
126
-      Google_Utils::urlSafeB64Encode($payload)
127
-    );
124
+	$segments = array(
125
+	  Google_Utils::urlSafeB64Encode(json_encode($header)),
126
+	  Google_Utils::urlSafeB64Encode($payload)
127
+	);
128 128
 
129
-    $signingInput = implode('.', $segments);
130
-    $signer = new Google_Signer_P12($this->privateKey, $this->privateKeyPassword);
131
-    $signature = $signer->sign($signingInput);
132
-    $segments[] = Google_Utils::urlSafeB64Encode($signature);
129
+	$signingInput = implode('.', $segments);
130
+	$signer = new Google_Signer_P12($this->privateKey, $this->privateKeyPassword);
131
+	$signature = $signer->sign($signingInput);
132
+	$segments[] = Google_Utils::urlSafeB64Encode($signature);
133 133
 
134
-    return implode(".", $segments);
134
+	return implode(".", $segments);
135 135
   }
136 136
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!class_exists('Google_Client')) {
19
-  require_once dirname(__FILE__) . '/../autoload.php';
19
+  require_once dirname(__FILE__).'/../autoload.php';
20 20
 }
21 21
 
22 22
 /**
Please login to merge, or discard this patch.
geodirectory-admin/google-api-php-client/src/Google/Auth/AppIdentity.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
 
39 39
   public function __construct(Google_Client $client, $config = null)
40 40
   {
41
-    $this->client = $client;
41
+	$this->client = $client;
42 42
   }
43 43
 
44 44
   /**
@@ -46,27 +46,27 @@  discard block
 block discarded – undo
46 46
    */
47 47
   public function authenticateForScope($scopes)
48 48
   {
49
-    if ($this->token && $this->tokenScopes == $scopes) {
50
-      return $this->token;
51
-    }
49
+	if ($this->token && $this->tokenScopes == $scopes) {
50
+	  return $this->token;
51
+	}
52 52
 
53
-    $cacheKey = self::CACHE_PREFIX;
54
-    if (is_string($scopes)) {
55
-      $cacheKey .= $scopes;
56
-    } else if (is_array($scopes)) {
57
-      $cacheKey .= implode(":", $scopes);
58
-    }
53
+	$cacheKey = self::CACHE_PREFIX;
54
+	if (is_string($scopes)) {
55
+	  $cacheKey .= $scopes;
56
+	} else if (is_array($scopes)) {
57
+	  $cacheKey .= implode(":", $scopes);
58
+	}
59 59
 
60
-    $this->token = $this->client->getCache()->get($cacheKey);
61
-    if (!$this->token) {
62
-      $this->retrieveToken($scopes, $cacheKey);
63
-    } else if ($this->token['expiration_time'] < time()) {
64
-      $this->client->getCache()->delete($cacheKey);
65
-      $this->retrieveToken($scopes, $cacheKey);
66
-    }
60
+	$this->token = $this->client->getCache()->get($cacheKey);
61
+	if (!$this->token) {
62
+	  $this->retrieveToken($scopes, $cacheKey);
63
+	} else if ($this->token['expiration_time'] < time()) {
64
+	  $this->client->getCache()->delete($cacheKey);
65
+	  $this->retrieveToken($scopes, $cacheKey);
66
+	}
67 67
 
68
-    $this->tokenScopes = $scopes;
69
-    return $this->token;
68
+	$this->tokenScopes = $scopes;
69
+	return $this->token;
70 70
   }
71 71
 
72 72
   /**
@@ -76,13 +76,13 @@  discard block
 block discarded – undo
76 76
    */
77 77
   private function retrieveToken($scopes, $cacheKey)
78 78
   {
79
-    $this->token = AppIdentityService::getAccessToken($scopes);
80
-    if ($this->token) {
81
-      $this->client->getCache()->set(
82
-          $cacheKey,
83
-          $this->token
84
-      );
85
-    }
79
+	$this->token = AppIdentityService::getAccessToken($scopes);
80
+	if ($this->token) {
81
+	  $this->client->getCache()->set(
82
+		  $cacheKey,
83
+		  $this->token
84
+	  );
85
+	}
86 86
   }
87 87
 
88 88
   /**
@@ -97,24 +97,24 @@  discard block
 block discarded – undo
97 97
    */
98 98
   public function authenticatedRequest(Google_Http_Request $request)
99 99
   {
100
-    $request = $this->sign($request);
101
-    return $this->client->getIo()->makeRequest($request);
100
+	$request = $this->sign($request);
101
+	return $this->client->getIo()->makeRequest($request);
102 102
   }
103 103
 
104 104
   public function sign(Google_Http_Request $request)
105 105
   {
106
-    if (!$this->token) {
107
-      // No token, so nothing to do.
108
-      return $request;
109
-    }
106
+	if (!$this->token) {
107
+	  // No token, so nothing to do.
108
+	  return $request;
109
+	}
110 110
 
111
-    $this->client->getLogger()->debug('App Identity authentication');
111
+	$this->client->getLogger()->debug('App Identity authentication');
112 112
 
113
-    // Add the OAuth2 header to the request
114
-    $request->setRequestHeaders(
115
-        array('Authorization' => 'Bearer ' . $this->token['access_token'])
116
-    );
113
+	// Add the OAuth2 header to the request
114
+	$request->setRequestHeaders(
115
+		array('Authorization' => 'Bearer ' . $this->token['access_token'])
116
+	);
117 117
 
118
-    return $request;
118
+	return $request;
119 119
   }
120 120
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 use google\appengine\api\app_identity\AppIdentityService;
24 24
 
25 25
 if (!class_exists('Google_Client')) {
26
-  require_once dirname(__FILE__) . '/../autoload.php';
26
+  require_once dirname(__FILE__).'/../autoload.php';
27 27
 }
28 28
 
29 29
 /**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
 
113 113
     // Add the OAuth2 header to the request
114 114
     $request->setRequestHeaders(
115
-        array('Authorization' => 'Bearer ' . $this->token['access_token'])
115
+        array('Authorization' => 'Bearer '.$this->token['access_token'])
116 116
     );
117 117
 
118 118
     return $request;
Please login to merge, or discard this patch.
geodirectory-admin/google-api-php-client/src/Google/Auth/Simple.php 2 patches
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
 
31 31
   public function __construct(Google_Client $client, $config = null)
32 32
   {
33
-    $this->client = $client;
33
+	$this->client = $client;
34 34
   }
35 35
 
36 36
   /**
@@ -45,19 +45,19 @@  discard block
 block discarded – undo
45 45
    */
46 46
   public function authenticatedRequest(Google_Http_Request $request)
47 47
   {
48
-    $request = $this->sign($request);
49
-    return $this->io->makeRequest($request);
48
+	$request = $this->sign($request);
49
+	return $this->io->makeRequest($request);
50 50
   }
51 51
 
52 52
   public function sign(Google_Http_Request $request)
53 53
   {
54
-    $key = $this->client->getClassConfig($this, 'developer_key');
55
-    if ($key) {
56
-      $this->client->getLogger()->debug(
57
-          'Simple API Access developer key authentication'
58
-      );
59
-      $request->setQueryParam('key', $key);
60
-    }
61
-    return $request;
54
+	$key = $this->client->getClassConfig($this, 'developer_key');
55
+	if ($key) {
56
+	  $this->client->getLogger()->debug(
57
+		  'Simple API Access developer key authentication'
58
+	  );
59
+	  $request->setQueryParam('key', $key);
60
+	}
61
+	return $request;
62 62
   }
63 63
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!class_exists('Google_Client')) {
19
-  require_once dirname(__FILE__) . '/../autoload.php';
19
+  require_once dirname(__FILE__).'/../autoload.php';
20 20
 }
21 21
 
22 22
 /**
Please login to merge, or discard this patch.
geodirectory-admin/google-api-php-client/src/Google/Auth/Exception.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!class_exists('Google_Client')) {
19
-  require_once dirname(__FILE__) . '/../autoload.php';
19
+  require_once dirname(__FILE__).'/../autoload.php';
20 20
 }
21 21
 
22 22
 class Google_Auth_Exception extends Google_Exception
Please login to merge, or discard this patch.
geodirectory-admin/google-api-php-client/src/Google/Auth/ComputeEngine.php 2 patches
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -28,13 +28,13 @@  discard block
 block discarded – undo
28 28
 class Google_Auth_ComputeEngine extends Google_Auth_Abstract
29 29
 {
30 30
   const METADATA_AUTH_URL =
31
-      'http://metadata/computeMetadata/v1/instance/service-accounts/default/token';
31
+	  'http://metadata/computeMetadata/v1/instance/service-accounts/default/token';
32 32
   private $client;
33 33
   private $token;
34 34
 
35 35
   public function __construct(Google_Client $client, $config = null)
36 36
   {
37
-    $this->client = $client;
37
+	$this->client = $client;
38 38
   }
39 39
 
40 40
   /**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
    */
50 50
   public function authenticatedRequest(Google_Http_Request $request)
51 51
   {
52
-    $request = $this->sign($request);
53
-    return $this->client->getIo()->makeRequest($request);
52
+	$request = $this->sign($request);
53
+	return $this->client->getIo()->makeRequest($request);
54 54
   }
55 55
 
56 56
   /**
@@ -59,20 +59,20 @@  discard block
 block discarded – undo
59 59
    */
60 60
   public function setAccessToken($token)
61 61
   {
62
-    $token = json_decode($token, true);
63
-    if ($token == null) {
64
-      throw new Google_Auth_Exception('Could not json decode the token');
65
-    }
66
-    if (! isset($token['access_token'])) {
67
-      throw new Google_Auth_Exception("Invalid token format");
68
-    }
69
-    $token['created'] = time();
70
-    $this->token = $token;
62
+	$token = json_decode($token, true);
63
+	if ($token == null) {
64
+	  throw new Google_Auth_Exception('Could not json decode the token');
65
+	}
66
+	if (! isset($token['access_token'])) {
67
+	  throw new Google_Auth_Exception("Invalid token format");
68
+	}
69
+	$token['created'] = time();
70
+	$this->token = $token;
71 71
   }
72 72
 
73 73
   public function getAccessToken()
74 74
   {
75
-    return json_encode($this->token);
75
+	return json_encode($this->token);
76 76
   }
77 77
 
78 78
   /**
@@ -81,29 +81,29 @@  discard block
 block discarded – undo
81 81
    */
82 82
   public function acquireAccessToken()
83 83
   {
84
-    $request = new Google_Http_Request(
85
-        self::METADATA_AUTH_URL,
86
-        'GET',
87
-        array(
88
-          'Metadata-Flavor' => 'Google'
89
-        )
90
-    );
91
-    $request->disableGzip();
92
-    $response = $this->client->getIo()->makeRequest($request);
84
+	$request = new Google_Http_Request(
85
+		self::METADATA_AUTH_URL,
86
+		'GET',
87
+		array(
88
+		  'Metadata-Flavor' => 'Google'
89
+		)
90
+	);
91
+	$request->disableGzip();
92
+	$response = $this->client->getIo()->makeRequest($request);
93 93
 
94
-    if ($response->getResponseHttpCode() == 200) {
95
-      $this->setAccessToken($response->getResponseBody());
96
-      $this->token['created'] = time();
97
-      return $this->getAccessToken();
98
-    } else {
99
-      throw new Google_Auth_Exception(
100
-          sprintf(
101
-              "Error fetching service account access token, message: '%s'",
102
-              $response->getResponseBody()
103
-          ),
104
-          $response->getResponseHttpCode()
105
-      );
106
-    }
94
+	if ($response->getResponseHttpCode() == 200) {
95
+	  $this->setAccessToken($response->getResponseBody());
96
+	  $this->token['created'] = time();
97
+	  return $this->getAccessToken();
98
+	} else {
99
+	  throw new Google_Auth_Exception(
100
+		  sprintf(
101
+			  "Error fetching service account access token, message: '%s'",
102
+			  $response->getResponseBody()
103
+		  ),
104
+		  $response->getResponseHttpCode()
105
+	  );
106
+	}
107 107
   }
108 108
 
109 109
   /**
@@ -114,17 +114,17 @@  discard block
 block discarded – undo
114 114
    */
115 115
   public function sign(Google_Http_Request $request)
116 116
   {
117
-    if ($this->isAccessTokenExpired()) {
118
-      $this->acquireAccessToken();
119
-    }
117
+	if ($this->isAccessTokenExpired()) {
118
+	  $this->acquireAccessToken();
119
+	}
120 120
 
121
-    $this->client->getLogger()->debug('Compute engine service account authentication');
121
+	$this->client->getLogger()->debug('Compute engine service account authentication');
122 122
 
123
-    $request->setRequestHeaders(
124
-        array('Authorization' => 'Bearer ' . $this->token['access_token'])
125
-    );
123
+	$request->setRequestHeaders(
124
+		array('Authorization' => 'Bearer ' . $this->token['access_token'])
125
+	);
126 126
 
127
-    return $request;
127
+	return $request;
128 128
   }
129 129
 
130 130
   /**
@@ -133,14 +133,14 @@  discard block
 block discarded – undo
133 133
    */
134 134
   public function isAccessTokenExpired()
135 135
   {
136
-    if (!$this->token || !isset($this->token['created'])) {
137
-      return true;
138
-    }
136
+	if (!$this->token || !isset($this->token['created'])) {
137
+	  return true;
138
+	}
139 139
 
140
-    // If the token is set to expire in the next 30 seconds.
141
-    $expired = ($this->token['created']
142
-        + ($this->token['expires_in'] - 30)) < time();
140
+	// If the token is set to expire in the next 30 seconds.
141
+	$expired = ($this->token['created']
142
+		+ ($this->token['expires_in'] - 30)) < time();
143 143
 
144
-    return $expired;
144
+	return $expired;
145 145
   }
146 146
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!class_exists('Google_Client')) {
19
-  require_once dirname(__FILE__) . '/../autoload.php';
19
+  require_once dirname(__FILE__).'/../autoload.php';
20 20
 }
21 21
 
22 22
 /**
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     if ($token == null) {
64 64
       throw new Google_Auth_Exception('Could not json decode the token');
65 65
     }
66
-    if (! isset($token['access_token'])) {
66
+    if (!isset($token['access_token'])) {
67 67
       throw new Google_Auth_Exception("Invalid token format");
68 68
     }
69 69
     $token['created'] = time();
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
     $this->client->getLogger()->debug('Compute engine service account authentication');
122 122
 
123 123
     $request->setRequestHeaders(
124
-        array('Authorization' => 'Bearer ' . $this->token['access_token'])
124
+        array('Authorization' => 'Bearer '.$this->token['access_token'])
125 125
     );
126 126
 
127 127
     return $request;
Please login to merge, or discard this patch.
geodirectory-admin/google-api-php-client/src/Google/Http/CacheParser.php 2 patches
Indentation   +111 added lines, -111 removed lines patch added patch discarded remove patch
@@ -38,20 +38,20 @@  discard block
 block discarded – undo
38 38
    */
39 39
   public static function isRequestCacheable(Google_Http_Request $resp)
40 40
   {
41
-    $method = $resp->getRequestMethod();
42
-    if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
43
-      return false;
44
-    }
45
-
46
-    // Don't cache authorized requests/responses.
47
-    // [rfc2616-14.8] When a shared cache receives a request containing an
48
-    // Authorization field, it MUST NOT return the corresponding response
49
-    // as a reply to any other request...
50
-    if ($resp->getRequestHeader("authorization")) {
51
-      return false;
52
-    }
53
-
54
-    return true;
41
+	$method = $resp->getRequestMethod();
42
+	if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
43
+	  return false;
44
+	}
45
+
46
+	// Don't cache authorized requests/responses.
47
+	// [rfc2616-14.8] When a shared cache receives a request containing an
48
+	// Authorization field, it MUST NOT return the corresponding response
49
+	// as a reply to any other request...
50
+	if ($resp->getRequestHeader("authorization")) {
51
+	  return false;
52
+	}
53
+
54
+	return true;
55 55
   }
56 56
 
57 57
   /**
@@ -64,48 +64,48 @@  discard block
 block discarded – undo
64 64
    */
65 65
   public static function isResponseCacheable(Google_Http_Request $resp)
66 66
   {
67
-    // First, check if the HTTP request was cacheable before inspecting the
68
-    // HTTP response.
69
-    if (false == self::isRequestCacheable($resp)) {
70
-      return false;
71
-    }
72
-
73
-    $code = $resp->getResponseHttpCode();
74
-    if (! in_array($code, self::$CACHEABLE_STATUS_CODES)) {
75
-      return false;
76
-    }
77
-
78
-    // The resource is uncacheable if the resource is already expired and
79
-    // the resource doesn't have an ETag for revalidation.
80
-    $etag = $resp->getResponseHeader("etag");
81
-    if (self::isExpired($resp) && $etag == false) {
82
-      return false;
83
-    }
84
-
85
-    // [rfc2616-14.9.2]  If [no-store is] sent in a response, a cache MUST NOT
86
-    // store any part of either this response or the request that elicited it.
87
-    $cacheControl = $resp->getParsedCacheControl();
88
-    if (isset($cacheControl['no-store'])) {
89
-      return false;
90
-    }
91
-
92
-    // Pragma: no-cache is an http request directive, but is occasionally
93
-    // used as a response header incorrectly.
94
-    $pragma = $resp->getResponseHeader('pragma');
95
-    if ($pragma == 'no-cache' || strpos($pragma, 'no-cache') !== false) {
96
-      return false;
97
-    }
98
-
99
-    // [rfc2616-14.44] Vary: * is extremely difficult to cache. "It implies that
100
-    // a cache cannot determine from the request headers of a subsequent request
101
-    // whether this response is the appropriate representation."
102
-    // Given this, we deem responses with the Vary header as uncacheable.
103
-    $vary = $resp->getResponseHeader('vary');
104
-    if ($vary) {
105
-      return false;
106
-    }
107
-
108
-    return true;
67
+	// First, check if the HTTP request was cacheable before inspecting the
68
+	// HTTP response.
69
+	if (false == self::isRequestCacheable($resp)) {
70
+	  return false;
71
+	}
72
+
73
+	$code = $resp->getResponseHttpCode();
74
+	if (! in_array($code, self::$CACHEABLE_STATUS_CODES)) {
75
+	  return false;
76
+	}
77
+
78
+	// The resource is uncacheable if the resource is already expired and
79
+	// the resource doesn't have an ETag for revalidation.
80
+	$etag = $resp->getResponseHeader("etag");
81
+	if (self::isExpired($resp) && $etag == false) {
82
+	  return false;
83
+	}
84
+
85
+	// [rfc2616-14.9.2]  If [no-store is] sent in a response, a cache MUST NOT
86
+	// store any part of either this response or the request that elicited it.
87
+	$cacheControl = $resp->getParsedCacheControl();
88
+	if (isset($cacheControl['no-store'])) {
89
+	  return false;
90
+	}
91
+
92
+	// Pragma: no-cache is an http request directive, but is occasionally
93
+	// used as a response header incorrectly.
94
+	$pragma = $resp->getResponseHeader('pragma');
95
+	if ($pragma == 'no-cache' || strpos($pragma, 'no-cache') !== false) {
96
+	  return false;
97
+	}
98
+
99
+	// [rfc2616-14.44] Vary: * is extremely difficult to cache. "It implies that
100
+	// a cache cannot determine from the request headers of a subsequent request
101
+	// whether this response is the appropriate representation."
102
+	// Given this, we deem responses with the Vary header as uncacheable.
103
+	$vary = $resp->getResponseHeader('vary');
104
+	if ($vary) {
105
+	  return false;
106
+	}
107
+
108
+	return true;
109 109
   }
110 110
 
111 111
   /**
@@ -116,57 +116,57 @@  discard block
 block discarded – undo
116 116
    */
117 117
   public static function isExpired(Google_Http_Request $resp)
118 118
   {
119
-    // HTTP/1.1 clients and caches MUST treat other invalid date formats,
120
-    // especially including the value “0”, as in the past.
121
-    $parsedExpires = false;
122
-    $responseHeaders = $resp->getResponseHeaders();
123
-
124
-    if (isset($responseHeaders['expires'])) {
125
-      $rawExpires = $responseHeaders['expires'];
126
-      // Check for a malformed expires header first.
127
-      if (empty($rawExpires) || (is_numeric($rawExpires) && $rawExpires <= 0)) {
128
-        return true;
129
-      }
130
-
131
-      // See if we can parse the expires header.
132
-      $parsedExpires = strtotime($rawExpires);
133
-      if (false == $parsedExpires || $parsedExpires <= 0) {
134
-        return true;
135
-      }
136
-    }
137
-
138
-    // Calculate the freshness of an http response.
139
-    $freshnessLifetime = false;
140
-    $cacheControl = $resp->getParsedCacheControl();
141
-    if (isset($cacheControl['max-age'])) {
142
-      $freshnessLifetime = $cacheControl['max-age'];
143
-    }
144
-
145
-    $rawDate = $resp->getResponseHeader('date');
146
-    $parsedDate = strtotime($rawDate);
147
-
148
-    if (empty($rawDate) || false == $parsedDate) {
149
-      // We can't default this to now, as that means future cache reads
150
-      // will always pass with the logic below, so we will require a
151
-      // date be injected if not supplied.
152
-      throw new Google_Exception("All cacheable requests must have creation dates.");
153
-    }
154
-
155
-    if (false == $freshnessLifetime && isset($responseHeaders['expires'])) {
156
-      $freshnessLifetime = $parsedExpires - $parsedDate;
157
-    }
158
-
159
-    if (false == $freshnessLifetime) {
160
-      return true;
161
-    }
162
-
163
-    // Calculate the age of an http response.
164
-    $age = max(0, time() - $parsedDate);
165
-    if (isset($responseHeaders['age'])) {
166
-      $age = max($age, strtotime($responseHeaders['age']));
167
-    }
168
-
169
-    return $freshnessLifetime <= $age;
119
+	// HTTP/1.1 clients and caches MUST treat other invalid date formats,
120
+	// especially including the value “0”, as in the past.
121
+	$parsedExpires = false;
122
+	$responseHeaders = $resp->getResponseHeaders();
123
+
124
+	if (isset($responseHeaders['expires'])) {
125
+	  $rawExpires = $responseHeaders['expires'];
126
+	  // Check for a malformed expires header first.
127
+	  if (empty($rawExpires) || (is_numeric($rawExpires) && $rawExpires <= 0)) {
128
+		return true;
129
+	  }
130
+
131
+	  // See if we can parse the expires header.
132
+	  $parsedExpires = strtotime($rawExpires);
133
+	  if (false == $parsedExpires || $parsedExpires <= 0) {
134
+		return true;
135
+	  }
136
+	}
137
+
138
+	// Calculate the freshness of an http response.
139
+	$freshnessLifetime = false;
140
+	$cacheControl = $resp->getParsedCacheControl();
141
+	if (isset($cacheControl['max-age'])) {
142
+	  $freshnessLifetime = $cacheControl['max-age'];
143
+	}
144
+
145
+	$rawDate = $resp->getResponseHeader('date');
146
+	$parsedDate = strtotime($rawDate);
147
+
148
+	if (empty($rawDate) || false == $parsedDate) {
149
+	  // We can't default this to now, as that means future cache reads
150
+	  // will always pass with the logic below, so we will require a
151
+	  // date be injected if not supplied.
152
+	  throw new Google_Exception("All cacheable requests must have creation dates.");
153
+	}
154
+
155
+	if (false == $freshnessLifetime && isset($responseHeaders['expires'])) {
156
+	  $freshnessLifetime = $parsedExpires - $parsedDate;
157
+	}
158
+
159
+	if (false == $freshnessLifetime) {
160
+	  return true;
161
+	}
162
+
163
+	// Calculate the age of an http response.
164
+	$age = max(0, time() - $parsedDate);
165
+	if (isset($responseHeaders['age'])) {
166
+	  $age = max($age, strtotime($responseHeaders['age']));
167
+	}
168
+
169
+	return $freshnessLifetime <= $age;
170 170
   }
171 171
 
172 172
   /**
@@ -177,9 +177,9 @@  discard block
 block discarded – undo
177 177
    */
178 178
   public static function mustRevalidate(Google_Http_Request $response)
179 179
   {
180
-    // [13.3] When a cache has a stale entry that it would like to use as a
181
-    // response to a client's request, it first has to check with the origin
182
-    // server to see if its cached entry is still usable.
183
-    return self::isExpired($response);
180
+	// [13.3] When a cache has a stale entry that it would like to use as a
181
+	// response to a client's request, it first has to check with the origin
182
+	// server to see if its cached entry is still usable.
183
+	return self::isExpired($response);
184 184
   }
185 185
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!class_exists('Google_Client')) {
19
-  require_once dirname(__FILE__) . '/../autoload.php';
19
+  require_once dirname(__FILE__).'/../autoload.php';
20 20
 }
21 21
 
22 22
 /**
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
   public static function isRequestCacheable(Google_Http_Request $resp)
40 40
   {
41 41
     $method = $resp->getRequestMethod();
42
-    if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
42
+    if (!in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
43 43
       return false;
44 44
     }
45 45
 
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
     }
72 72
 
73 73
     $code = $resp->getResponseHttpCode();
74
-    if (! in_array($code, self::$CACHEABLE_STATUS_CODES)) {
74
+    if (!in_array($code, self::$CACHEABLE_STATUS_CODES)) {
75 75
       return false;
76 76
     }
77 77
 
Please login to merge, or discard this patch.
google-api-php-client/src/Google/Http/MediaFileUpload.php 2 patches
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -73,29 +73,29 @@  discard block
 block discarded – undo
73 73
    * only used if resumable=True
74 74
    */
75 75
   public function __construct(
76
-      Google_Client $client,
77
-      Google_Http_Request $request,
78
-      $mimeType,
79
-      $data,
80
-      $resumable = false,
81
-      $chunkSize = false,
82
-      $boundary = false
76
+	  Google_Client $client,
77
+	  Google_Http_Request $request,
78
+	  $mimeType,
79
+	  $data,
80
+	  $resumable = false,
81
+	  $chunkSize = false,
82
+	  $boundary = false
83 83
   ) {
84
-    $this->client = $client;
85
-    $this->request = $request;
86
-    $this->mimeType = $mimeType;
87
-    $this->data = $data;
88
-    $this->size = strlen($this->data);
89
-    $this->resumable = $resumable;
90
-    if (!$chunkSize) {
91
-      $chunkSize = 256 * 1024;
92
-    }
93
-    $this->chunkSize = $chunkSize;
94
-    $this->progress = 0;
95
-    $this->boundary = $boundary;
96
-
97
-    // Process Media Request
98
-    $this->process();
84
+	$this->client = $client;
85
+	$this->request = $request;
86
+	$this->mimeType = $mimeType;
87
+	$this->data = $data;
88
+	$this->size = strlen($this->data);
89
+	$this->resumable = $resumable;
90
+	if (!$chunkSize) {
91
+	  $chunkSize = 256 * 1024;
92
+	}
93
+	$this->chunkSize = $chunkSize;
94
+	$this->progress = 0;
95
+	$this->boundary = $boundary;
96
+
97
+	// Process Media Request
98
+	$this->process();
99 99
   }
100 100
 
101 101
   /**
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
    */
105 105
   public function setFileSize($size)
106 106
   {
107
-    $this->size = $size;
107
+	$this->size = $size;
108 108
   }
109 109
 
110 110
   /**
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
    */
114 114
   public function getProgress()
115 115
   {
116
-    return $this->progress;
116
+	return $this->progress;
117 117
   }
118 118
 
119 119
   /**
@@ -122,7 +122,7 @@  discard block
 block discarded – undo
122 122
    */
123 123
   public function getHttpResultCode()
124 124
   {
125
-    return $this->httpResultCode;
125
+	return $this->httpResultCode;
126 126
   }
127 127
 
128 128
   /**
@@ -132,56 +132,56 @@  discard block
 block discarded – undo
132 132
    */
133 133
   public function nextChunk($chunk = false)
134 134
   {
135
-    if (false == $this->resumeUri) {
136
-      $this->resumeUri = $this->getResumeUri();
137
-    }
138
-
139
-    if (false == $chunk) {
140
-      $chunk = substr($this->data, $this->progress, $this->chunkSize);
141
-    }
142
-
143
-    $lastBytePos = $this->progress + strlen($chunk) - 1;
144
-    $headers = array(
145
-      'content-range' => "bytes $this->progress-$lastBytePos/$this->size",
146
-      'content-type' => $this->request->getRequestHeader('content-type'),
147
-      'content-length' => $this->chunkSize,
148
-      'expect' => '',
149
-    );
150
-
151
-    $httpRequest = new Google_Http_Request(
152
-        $this->resumeUri,
153
-        'PUT',
154
-        $headers,
155
-        $chunk
156
-    );
157
-
158
-    if ($this->client->getClassConfig("Google_Http_Request", "enable_gzip_for_uploads")) {
159
-      $httpRequest->enableGzip();
160
-    } else {
161
-      $httpRequest->disableGzip();
162
-    }
163
-
164
-    $response = $this->client->getIo()->makeRequest($httpRequest);
165
-    $response->setExpectedClass($this->request->getExpectedClass());
166
-    $code = $response->getResponseHttpCode();
167
-    $this->httpResultCode = $code;
168
-
169
-    if (308 == $code) {
170
-      // Track the amount uploaded.
171
-      $range = explode('-', $response->getResponseHeader('range'));
172
-      $this->progress = $range[1] + 1;
173
-
174
-      // Allow for changing upload URLs.
175
-      $location = $response->getResponseHeader('location');
176
-      if ($location) {
177
-        $this->resumeUri = $location;
178
-      }
179
-
180
-      // No problems, but upload not complete.
181
-      return false;
182
-    } else {
183
-      return Google_Http_REST::decodeHttpResponse($response, $this->client);
184
-    }
135
+	if (false == $this->resumeUri) {
136
+	  $this->resumeUri = $this->getResumeUri();
137
+	}
138
+
139
+	if (false == $chunk) {
140
+	  $chunk = substr($this->data, $this->progress, $this->chunkSize);
141
+	}
142
+
143
+	$lastBytePos = $this->progress + strlen($chunk) - 1;
144
+	$headers = array(
145
+	  'content-range' => "bytes $this->progress-$lastBytePos/$this->size",
146
+	  'content-type' => $this->request->getRequestHeader('content-type'),
147
+	  'content-length' => $this->chunkSize,
148
+	  'expect' => '',
149
+	);
150
+
151
+	$httpRequest = new Google_Http_Request(
152
+		$this->resumeUri,
153
+		'PUT',
154
+		$headers,
155
+		$chunk
156
+	);
157
+
158
+	if ($this->client->getClassConfig("Google_Http_Request", "enable_gzip_for_uploads")) {
159
+	  $httpRequest->enableGzip();
160
+	} else {
161
+	  $httpRequest->disableGzip();
162
+	}
163
+
164
+	$response = $this->client->getIo()->makeRequest($httpRequest);
165
+	$response->setExpectedClass($this->request->getExpectedClass());
166
+	$code = $response->getResponseHttpCode();
167
+	$this->httpResultCode = $code;
168
+
169
+	if (308 == $code) {
170
+	  // Track the amount uploaded.
171
+	  $range = explode('-', $response->getResponseHeader('range'));
172
+	  $this->progress = $range[1] + 1;
173
+
174
+	  // Allow for changing upload URLs.
175
+	  $location = $response->getResponseHeader('location');
176
+	  if ($location) {
177
+		$this->resumeUri = $location;
178
+	  }
179
+
180
+	  // No problems, but upload not complete.
181
+	  return false;
182
+	} else {
183
+	  return Google_Http_REST::decodeHttpResponse($response, $this->client);
184
+	}
185 185
   }
186 186
 
187 187
   /**
@@ -192,53 +192,53 @@  discard block
 block discarded – undo
192 192
    */
193 193
   private function process()
194 194
   {
195
-    $postBody = false;
196
-    $contentType = false;
197
-
198
-    $meta = $this->request->getPostBody();
199
-    $meta = is_string($meta) ? json_decode($meta, true) : $meta;
200
-
201
-    $uploadType = $this->getUploadType($meta);
202
-    $this->request->setQueryParam('uploadType', $uploadType);
203
-    $this->transformToUploadUrl();
204
-    $mimeType = $this->mimeType ?
205
-        $this->mimeType :
206
-        $this->request->getRequestHeader('content-type');
207
-
208
-    if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) {
209
-      $contentType = $mimeType;
210
-      $postBody = is_string($meta) ? $meta : json_encode($meta);
211
-    } else if (self::UPLOAD_MEDIA_TYPE == $uploadType) {
212
-      $contentType = $mimeType;
213
-      $postBody = $this->data;
214
-    } else if (self::UPLOAD_MULTIPART_TYPE == $uploadType) {
215
-      // This is a multipart/related upload.
216
-      $boundary = $this->boundary ? $this->boundary : mt_rand();
217
-      $boundary = str_replace('"', '', $boundary);
218
-      $contentType = 'multipart/related; boundary=' . $boundary;
219
-      $related = "--$boundary\r\n";
220
-      $related .= "Content-Type: application/json; charset=UTF-8\r\n";
221
-      $related .= "\r\n" . json_encode($meta) . "\r\n";
222
-      $related .= "--$boundary\r\n";
223
-      $related .= "Content-Type: $mimeType\r\n";
224
-      $related .= "Content-Transfer-Encoding: base64\r\n";
225
-      $related .= "\r\n" . base64_encode($this->data) . "\r\n";
226
-      $related .= "--$boundary--";
227
-      $postBody = $related;
228
-    }
229
-
230
-    $this->request->setPostBody($postBody);
231
-
232
-    if (isset($contentType) && $contentType) {
233
-      $contentTypeHeader['content-type'] = $contentType;
234
-      $this->request->setRequestHeaders($contentTypeHeader);
235
-    }
195
+	$postBody = false;
196
+	$contentType = false;
197
+
198
+	$meta = $this->request->getPostBody();
199
+	$meta = is_string($meta) ? json_decode($meta, true) : $meta;
200
+
201
+	$uploadType = $this->getUploadType($meta);
202
+	$this->request->setQueryParam('uploadType', $uploadType);
203
+	$this->transformToUploadUrl();
204
+	$mimeType = $this->mimeType ?
205
+		$this->mimeType :
206
+		$this->request->getRequestHeader('content-type');
207
+
208
+	if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) {
209
+	  $contentType = $mimeType;
210
+	  $postBody = is_string($meta) ? $meta : json_encode($meta);
211
+	} else if (self::UPLOAD_MEDIA_TYPE == $uploadType) {
212
+	  $contentType = $mimeType;
213
+	  $postBody = $this->data;
214
+	} else if (self::UPLOAD_MULTIPART_TYPE == $uploadType) {
215
+	  // This is a multipart/related upload.
216
+	  $boundary = $this->boundary ? $this->boundary : mt_rand();
217
+	  $boundary = str_replace('"', '', $boundary);
218
+	  $contentType = 'multipart/related; boundary=' . $boundary;
219
+	  $related = "--$boundary\r\n";
220
+	  $related .= "Content-Type: application/json; charset=UTF-8\r\n";
221
+	  $related .= "\r\n" . json_encode($meta) . "\r\n";
222
+	  $related .= "--$boundary\r\n";
223
+	  $related .= "Content-Type: $mimeType\r\n";
224
+	  $related .= "Content-Transfer-Encoding: base64\r\n";
225
+	  $related .= "\r\n" . base64_encode($this->data) . "\r\n";
226
+	  $related .= "--$boundary--";
227
+	  $postBody = $related;
228
+	}
229
+
230
+	$this->request->setPostBody($postBody);
231
+
232
+	if (isset($contentType) && $contentType) {
233
+	  $contentTypeHeader['content-type'] = $contentType;
234
+	  $this->request->setRequestHeaders($contentTypeHeader);
235
+	}
236 236
   }
237 237
 
238 238
   private function transformToUploadUrl()
239 239
   {
240
-    $base = $this->request->getBaseComponent();
241
-    $this->request->setBaseComponent($base . '/upload');
240
+	$base = $this->request->getBaseComponent();
241
+	$this->request->setBaseComponent($base . '/upload');
242 242
   }
243 243
 
244 244
   /**
@@ -252,56 +252,56 @@  discard block
 block discarded – undo
252 252
    */
253 253
   public function getUploadType($meta)
254 254
   {
255
-    if ($this->resumable) {
256
-      return self::UPLOAD_RESUMABLE_TYPE;
257
-    }
255
+	if ($this->resumable) {
256
+	  return self::UPLOAD_RESUMABLE_TYPE;
257
+	}
258 258
 
259
-    if (false == $meta && $this->data) {
260
-      return self::UPLOAD_MEDIA_TYPE;
261
-    }
259
+	if (false == $meta && $this->data) {
260
+	  return self::UPLOAD_MEDIA_TYPE;
261
+	}
262 262
 
263
-    return self::UPLOAD_MULTIPART_TYPE;
263
+	return self::UPLOAD_MULTIPART_TYPE;
264 264
   }
265 265
 
266 266
   private function getResumeUri()
267 267
   {
268
-    $result = null;
269
-    $body = $this->request->getPostBody();
270
-    if ($body) {
271
-      $headers = array(
272
-        'content-type' => 'application/json; charset=UTF-8',
273
-        'content-length' => Google_Utils::getStrLen($body),
274
-        'x-upload-content-type' => $this->mimeType,
275
-        'x-upload-content-length' => $this->size,
276
-        'expect' => '',
277
-      );
278
-      $this->request->setRequestHeaders($headers);
279
-    }
280
-
281
-    $response = $this->client->getIo()->makeRequest($this->request);
282
-    $location = $response->getResponseHeader('location');
283
-    $code = $response->getResponseHttpCode();
284
-
285
-    if (200 == $code && true == $location) {
286
-      return $location;
287
-    }
288
-    $message = $code;
289
-    $body = @json_decode($response->getResponseBody());
290
-    if (!empty($body->error->errors) ) {
291
-      $message .= ': ';
292
-      foreach ($body->error->errors as $error) {
293
-        $message .= "{$error->domain}, {$error->message};";
294
-      }
295
-      $message = rtrim($message, ';');
296
-    }
297
-
298
-    $error = "Failed to start the resumable upload (HTTP {$message})";
299
-    $this->client->getLogger()->error($error);
300
-    throw new Google_Exception($error);
268
+	$result = null;
269
+	$body = $this->request->getPostBody();
270
+	if ($body) {
271
+	  $headers = array(
272
+		'content-type' => 'application/json; charset=UTF-8',
273
+		'content-length' => Google_Utils::getStrLen($body),
274
+		'x-upload-content-type' => $this->mimeType,
275
+		'x-upload-content-length' => $this->size,
276
+		'expect' => '',
277
+	  );
278
+	  $this->request->setRequestHeaders($headers);
279
+	}
280
+
281
+	$response = $this->client->getIo()->makeRequest($this->request);
282
+	$location = $response->getResponseHeader('location');
283
+	$code = $response->getResponseHttpCode();
284
+
285
+	if (200 == $code && true == $location) {
286
+	  return $location;
287
+	}
288
+	$message = $code;
289
+	$body = @json_decode($response->getResponseBody());
290
+	if (!empty($body->error->errors) ) {
291
+	  $message .= ': ';
292
+	  foreach ($body->error->errors as $error) {
293
+		$message .= "{$error->domain}, {$error->message};";
294
+	  }
295
+	  $message = rtrim($message, ';');
296
+	}
297
+
298
+	$error = "Failed to start the resumable upload (HTTP {$message})";
299
+	$this->client->getLogger()->error($error);
300
+	throw new Google_Exception($error);
301 301
   }
302 302
 
303 303
   public function setChunkSize($chunkSize)
304 304
   {
305
-    $this->chunkSize = $chunkSize;
305
+	$this->chunkSize = $chunkSize;
306 306
   }
307 307
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -8 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!class_exists('Google_Client')) {
19
-  require_once dirname(__FILE__) . '/../autoload.php';
19
+  require_once dirname(__FILE__).'/../autoload.php';
20 20
 }
21 21
 
22 22
 /**
@@ -202,8 +202,7 @@  discard block
 block discarded – undo
202 202
     $this->request->setQueryParam('uploadType', $uploadType);
203 203
     $this->transformToUploadUrl();
204 204
     $mimeType = $this->mimeType ?
205
-        $this->mimeType :
206
-        $this->request->getRequestHeader('content-type');
205
+        $this->mimeType : $this->request->getRequestHeader('content-type');
207 206
 
208 207
     if (self::UPLOAD_RESUMABLE_TYPE == $uploadType) {
209 208
       $contentType = $mimeType;
@@ -215,14 +214,14 @@  discard block
 block discarded – undo
215 214
       // This is a multipart/related upload.
216 215
       $boundary = $this->boundary ? $this->boundary : mt_rand();
217 216
       $boundary = str_replace('"', '', $boundary);
218
-      $contentType = 'multipart/related; boundary=' . $boundary;
217
+      $contentType = 'multipart/related; boundary='.$boundary;
219 218
       $related = "--$boundary\r\n";
220 219
       $related .= "Content-Type: application/json; charset=UTF-8\r\n";
221
-      $related .= "\r\n" . json_encode($meta) . "\r\n";
220
+      $related .= "\r\n".json_encode($meta)."\r\n";
222 221
       $related .= "--$boundary\r\n";
223 222
       $related .= "Content-Type: $mimeType\r\n";
224 223
       $related .= "Content-Transfer-Encoding: base64\r\n";
225
-      $related .= "\r\n" . base64_encode($this->data) . "\r\n";
224
+      $related .= "\r\n".base64_encode($this->data)."\r\n";
226 225
       $related .= "--$boundary--";
227 226
       $postBody = $related;
228 227
     }
@@ -238,7 +237,7 @@  discard block
 block discarded – undo
238 237
   private function transformToUploadUrl()
239 238
   {
240 239
     $base = $this->request->getBaseComponent();
241
-    $this->request->setBaseComponent($base . '/upload');
240
+    $this->request->setBaseComponent($base.'/upload');
242 241
   }
243 242
 
244 243
   /**
@@ -287,7 +286,7 @@  discard block
 block discarded – undo
287 286
     }
288 287
     $message = $code;
289 288
     $body = @json_decode($response->getResponseBody());
290
-    if (!empty($body->error->errors) ) {
289
+    if (!empty($body->error->errors)) {
291 290
       $message .= ': ';
292 291
       foreach ($body->error->errors as $error) {
293 292
         $message .= "{$error->domain}, {$error->message};";
Please login to merge, or discard this patch.
geodirectory-admin/google-api-php-client/src/Google/Http/Batch.php 2 patches
Indentation   +82 added lines, -82 removed lines patch added patch discarded remove patch
@@ -41,105 +41,105 @@
 block discarded – undo
41 41
 
42 42
   public function __construct(Google_Client $client, $boundary = false, $rootUrl = '', $batchPath = '')
43 43
   {
44
-    $this->client = $client;
45
-    $this->root_url = rtrim($rootUrl ? $rootUrl : $this->client->getBasePath(), '/');
46
-    $this->batch_path = $batchPath ? $batchPath : 'batch';
47
-    $this->expected_classes = array();
48
-    $boundary = (false == $boundary) ? mt_rand() : $boundary;
49
-    $this->boundary = str_replace('"', '', $boundary);
44
+	$this->client = $client;
45
+	$this->root_url = rtrim($rootUrl ? $rootUrl : $this->client->getBasePath(), '/');
46
+	$this->batch_path = $batchPath ? $batchPath : 'batch';
47
+	$this->expected_classes = array();
48
+	$boundary = (false == $boundary) ? mt_rand() : $boundary;
49
+	$this->boundary = str_replace('"', '', $boundary);
50 50
   }
51 51
 
52 52
   public function add(Google_Http_Request $request, $key = false)
53 53
   {
54
-    if (false == $key) {
55
-      $key = mt_rand();
56
-    }
54
+	if (false == $key) {
55
+	  $key = mt_rand();
56
+	}
57 57
 
58
-    $this->requests[$key] = $request;
58
+	$this->requests[$key] = $request;
59 59
   }
60 60
 
61 61
   public function execute()
62 62
   {
63
-    $body = '';
63
+	$body = '';
64 64
 
65
-    /** @var Google_Http_Request $req */
66
-    foreach ($this->requests as $key => $req) {
67
-      $body .= "--{$this->boundary}\n";
68
-      $body .= $req->toBatchString($key) . "\n\n";
69
-      $this->expected_classes["response-" . $key] = $req->getExpectedClass();
70
-    }
65
+	/** @var Google_Http_Request $req */
66
+	foreach ($this->requests as $key => $req) {
67
+	  $body .= "--{$this->boundary}\n";
68
+	  $body .= $req->toBatchString($key) . "\n\n";
69
+	  $this->expected_classes["response-" . $key] = $req->getExpectedClass();
70
+	}
71 71
 
72
-    $body .= "--{$this->boundary}--";
72
+	$body .= "--{$this->boundary}--";
73 73
 
74
-    $url = $this->root_url . '/' . $this->batch_path;
75
-    $httpRequest = new Google_Http_Request($url, 'POST');
76
-    $httpRequest->setRequestHeaders(
77
-        array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary)
78
-    );
74
+	$url = $this->root_url . '/' . $this->batch_path;
75
+	$httpRequest = new Google_Http_Request($url, 'POST');
76
+	$httpRequest->setRequestHeaders(
77
+		array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary)
78
+	);
79 79
 
80
-    $httpRequest->setPostBody($body);
81
-    $response = $this->client->getIo()->makeRequest($httpRequest);
80
+	$httpRequest->setPostBody($body);
81
+	$response = $this->client->getIo()->makeRequest($httpRequest);
82 82
 
83
-    return $this->parseResponse($response);
83
+	return $this->parseResponse($response);
84 84
   }
85 85
 
86 86
   public function parseResponse(Google_Http_Request $response)
87 87
   {
88
-    $contentType = $response->getResponseHeader('content-type');
89
-    $contentType = explode(';', $contentType);
90
-    $boundary = false;
91
-    foreach ($contentType as $part) {
92
-      $part = (explode('=', $part, 2));
93
-      if (isset($part[0]) && 'boundary' == trim($part[0])) {
94
-        $boundary = $part[1];
95
-      }
96
-    }
97
-
98
-    $body = $response->getResponseBody();
99
-    if ($body) {
100
-      $body = str_replace("--$boundary--", "--$boundary", $body);
101
-      $parts = explode("--$boundary", $body);
102
-      $responses = array();
103
-
104
-      foreach ($parts as $part) {
105
-        $part = trim($part);
106
-        if (!empty($part)) {
107
-          list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2);
108
-          $metaHeaders = $this->client->getIo()->getHttpResponseHeaders($metaHeaders);
109
-
110
-          $status = substr($part, 0, strpos($part, "\n"));
111
-          $status = explode(" ", $status);
112
-          $status = $status[1];
113
-
114
-          list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
115
-          $response = new Google_Http_Request("");
116
-          $response->setResponseHttpCode($status);
117
-          $response->setResponseHeaders($partHeaders);
118
-          $response->setResponseBody($partBody);
119
-
120
-          // Need content id.
121
-          $key = $metaHeaders['content-id'];
122
-
123
-          if (isset($this->expected_classes[$key]) &&
124
-              strlen($this->expected_classes[$key]) > 0) {
125
-            $class = $this->expected_classes[$key];
126
-            $response->setExpectedClass($class);
127
-          }
128
-
129
-          try {
130
-            $response = Google_Http_REST::decodeHttpResponse($response, $this->client);
131
-            $responses[$key] = $response;
132
-          } catch (Google_Service_Exception $e) {
133
-            // Store the exception as the response, so successful responses
134
-            // can be processed.
135
-            $responses[$key] = $e;
136
-          }
137
-        }
138
-      }
139
-
140
-      return $responses;
141
-    }
142
-
143
-    return null;
88
+	$contentType = $response->getResponseHeader('content-type');
89
+	$contentType = explode(';', $contentType);
90
+	$boundary = false;
91
+	foreach ($contentType as $part) {
92
+	  $part = (explode('=', $part, 2));
93
+	  if (isset($part[0]) && 'boundary' == trim($part[0])) {
94
+		$boundary = $part[1];
95
+	  }
96
+	}
97
+
98
+	$body = $response->getResponseBody();
99
+	if ($body) {
100
+	  $body = str_replace("--$boundary--", "--$boundary", $body);
101
+	  $parts = explode("--$boundary", $body);
102
+	  $responses = array();
103
+
104
+	  foreach ($parts as $part) {
105
+		$part = trim($part);
106
+		if (!empty($part)) {
107
+		  list($metaHeaders, $part) = explode("\r\n\r\n", $part, 2);
108
+		  $metaHeaders = $this->client->getIo()->getHttpResponseHeaders($metaHeaders);
109
+
110
+		  $status = substr($part, 0, strpos($part, "\n"));
111
+		  $status = explode(" ", $status);
112
+		  $status = $status[1];
113
+
114
+		  list($partHeaders, $partBody) = $this->client->getIo()->ParseHttpResponse($part, false);
115
+		  $response = new Google_Http_Request("");
116
+		  $response->setResponseHttpCode($status);
117
+		  $response->setResponseHeaders($partHeaders);
118
+		  $response->setResponseBody($partBody);
119
+
120
+		  // Need content id.
121
+		  $key = $metaHeaders['content-id'];
122
+
123
+		  if (isset($this->expected_classes[$key]) &&
124
+			  strlen($this->expected_classes[$key]) > 0) {
125
+			$class = $this->expected_classes[$key];
126
+			$response->setExpectedClass($class);
127
+		  }
128
+
129
+		  try {
130
+			$response = Google_Http_REST::decodeHttpResponse($response, $this->client);
131
+			$responses[$key] = $response;
132
+		  } catch (Google_Service_Exception $e) {
133
+			// Store the exception as the response, so successful responses
134
+			// can be processed.
135
+			$responses[$key] = $e;
136
+		  }
137
+		}
138
+	  }
139
+
140
+	  return $responses;
141
+	}
142
+
143
+	return null;
144 144
   }
145 145
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!class_exists('Google_Client')) {
19
-  require_once dirname(__FILE__) . '/../autoload.php';
19
+  require_once dirname(__FILE__).'/../autoload.php';
20 20
 }
21 21
 
22 22
 /**
@@ -65,16 +65,16 @@  discard block
 block discarded – undo
65 65
     /** @var Google_Http_Request $req */
66 66
     foreach ($this->requests as $key => $req) {
67 67
       $body .= "--{$this->boundary}\n";
68
-      $body .= $req->toBatchString($key) . "\n\n";
69
-      $this->expected_classes["response-" . $key] = $req->getExpectedClass();
68
+      $body .= $req->toBatchString($key)."\n\n";
69
+      $this->expected_classes["response-".$key] = $req->getExpectedClass();
70 70
     }
71 71
 
72 72
     $body .= "--{$this->boundary}--";
73 73
 
74
-    $url = $this->root_url . '/' . $this->batch_path;
74
+    $url = $this->root_url.'/'.$this->batch_path;
75 75
     $httpRequest = new Google_Http_Request($url, 'POST');
76 76
     $httpRequest->setRequestHeaders(
77
-        array('Content-Type' => 'multipart/mixed; boundary=' . $this->boundary)
77
+        array('Content-Type' => 'multipart/mixed; boundary='.$this->boundary)
78 78
     );
79 79
 
80 80
     $httpRequest->setPostBody($body);
Please login to merge, or discard this patch.
geodirectory-admin/google-api-php-client/src/Google/Http/REST.php 2 patches
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -36,14 +36,14 @@  discard block
 block discarded – undo
36 36
    */
37 37
   public static function execute(Google_Client $client, Google_Http_Request $req)
38 38
   {
39
-    $runner = new Google_Task_Runner(
40
-        $client,
41
-        sprintf('%s %s', $req->getRequestMethod(), $req->getUrl()),
42
-        array(get_class(), 'doExecute'),
43
-        array($client, $req)
44
-    );
39
+	$runner = new Google_Task_Runner(
40
+		$client,
41
+		sprintf('%s %s', $req->getRequestMethod(), $req->getUrl()),
42
+		array(get_class(), 'doExecute'),
43
+		array($client, $req)
44
+	);
45 45
 
46
-    return $runner->run();
46
+	return $runner->run();
47 47
   }
48 48
 
49 49
   /**
@@ -57,9 +57,9 @@  discard block
 block discarded – undo
57 57
    */
58 58
   public static function doExecute(Google_Client $client, Google_Http_Request $req)
59 59
   {
60
-    $httpRequest = $client->getIo()->makeRequest($req);
61
-    $httpRequest->setExpectedClass($req->getExpectedClass());
62
-    return self::decodeHttpResponse($httpRequest, $client);
60
+	$httpRequest = $client->getIo()->makeRequest($req);
61
+	$httpRequest->setExpectedClass($req->getExpectedClass());
62
+	return self::decodeHttpResponse($httpRequest, $client);
63 63
   }
64 64
 
65 65
   /**
@@ -72,65 +72,65 @@  discard block
 block discarded – undo
72 72
    */
73 73
   public static function decodeHttpResponse($response, Google_Client $client = null)
74 74
   {
75
-    $code = $response->getResponseHttpCode();
76
-    $body = $response->getResponseBody();
77
-    $decoded = null;
75
+	$code = $response->getResponseHttpCode();
76
+	$body = $response->getResponseBody();
77
+	$decoded = null;
78 78
 
79
-    if ((intVal($code)) >= 300) {
80
-      $decoded = json_decode($body, true);
81
-      $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
82
-      if (isset($decoded['error']) &&
83
-          isset($decoded['error']['message'])  &&
84
-          isset($decoded['error']['code'])) {
85
-        // if we're getting a json encoded error definition, use that instead of the raw response
86
-        // body for improved readability
87
-        $err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
88
-      } else {
89
-        $err .= ": ($code) $body";
90
-      }
79
+	if ((intVal($code)) >= 300) {
80
+	  $decoded = json_decode($body, true);
81
+	  $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
82
+	  if (isset($decoded['error']) &&
83
+		  isset($decoded['error']['message'])  &&
84
+		  isset($decoded['error']['code'])) {
85
+		// if we're getting a json encoded error definition, use that instead of the raw response
86
+		// body for improved readability
87
+		$err .= ": ({$decoded['error']['code']}) {$decoded['error']['message']}";
88
+	  } else {
89
+		$err .= ": ($code) $body";
90
+	  }
91 91
 
92
-      $errors = null;
93
-      // Specific check for APIs which don't return error details, such as Blogger.
94
-      if (isset($decoded['error']) && isset($decoded['error']['errors'])) {
95
-        $errors = $decoded['error']['errors'];
96
-      }
92
+	  $errors = null;
93
+	  // Specific check for APIs which don't return error details, such as Blogger.
94
+	  if (isset($decoded['error']) && isset($decoded['error']['errors'])) {
95
+		$errors = $decoded['error']['errors'];
96
+	  }
97 97
 
98
-      $map = null;
99
-      if ($client) {
100
-        $client->getLogger()->error(
101
-            $err,
102
-            array('code' => $code, 'errors' => $errors)
103
-        );
98
+	  $map = null;
99
+	  if ($client) {
100
+		$client->getLogger()->error(
101
+			$err,
102
+			array('code' => $code, 'errors' => $errors)
103
+		);
104 104
 
105
-        $map = $client->getClassConfig(
106
-            'Google_Service_Exception',
107
-            'retry_map'
108
-        );
109
-      }
110
-      throw new Google_Service_Exception($err, $code, null, $errors, $map);
111
-    }
105
+		$map = $client->getClassConfig(
106
+			'Google_Service_Exception',
107
+			'retry_map'
108
+		);
109
+	  }
110
+	  throw new Google_Service_Exception($err, $code, null, $errors, $map);
111
+	}
112 112
 
113
-    // Only attempt to decode the response, if the response code wasn't (204) 'no content'
114
-    if ($code != '204') {
115
-      if ($response->getExpectedRaw()) {
116
-        return $body;
117
-      }
113
+	// Only attempt to decode the response, if the response code wasn't (204) 'no content'
114
+	if ($code != '204') {
115
+	  if ($response->getExpectedRaw()) {
116
+		return $body;
117
+	  }
118 118
       
119
-      $decoded = json_decode($body, true);
120
-      if ($decoded === null || $decoded === "") {
121
-        $error = "Invalid json in service response: $body";
122
-        if ($client) {
123
-          $client->getLogger()->error($error);
124
-        }
125
-        throw new Google_Service_Exception($error);
126
-      }
119
+	  $decoded = json_decode($body, true);
120
+	  if ($decoded === null || $decoded === "") {
121
+		$error = "Invalid json in service response: $body";
122
+		if ($client) {
123
+		  $client->getLogger()->error($error);
124
+		}
125
+		throw new Google_Service_Exception($error);
126
+	  }
127 127
 
128
-      if ($response->getExpectedClass()) {
129
-        $class = $response->getExpectedClass();
130
-        $decoded = new $class($decoded);
131
-      }
132
-    }
133
-    return $decoded;
128
+	  if ($response->getExpectedClass()) {
129
+		$class = $response->getExpectedClass();
130
+		$decoded = new $class($decoded);
131
+	  }
132
+	}
133
+	return $decoded;
134 134
   }
135 135
 
136 136
   /**
@@ -144,35 +144,35 @@  discard block
 block discarded – undo
144 144
    */
145 145
   public static function createRequestUri($servicePath, $restPath, $params)
146 146
   {
147
-    $requestUrl = $servicePath . $restPath;
148
-    $uriTemplateVars = array();
149
-    $queryVars = array();
150
-    foreach ($params as $paramName => $paramSpec) {
151
-      if ($paramSpec['type'] == 'boolean') {
152
-        $paramSpec['value'] = ($paramSpec['value']) ? 'true' : 'false';
153
-      }
154
-      if ($paramSpec['location'] == 'path') {
155
-        $uriTemplateVars[$paramName] = $paramSpec['value'];
156
-      } else if ($paramSpec['location'] == 'query') {
157
-        if (isset($paramSpec['repeated']) && is_array($paramSpec['value'])) {
158
-          foreach ($paramSpec['value'] as $value) {
159
-            $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($value));
160
-          }
161
-        } else {
162
-          $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($paramSpec['value']));
163
-        }
164
-      }
165
-    }
147
+	$requestUrl = $servicePath . $restPath;
148
+	$uriTemplateVars = array();
149
+	$queryVars = array();
150
+	foreach ($params as $paramName => $paramSpec) {
151
+	  if ($paramSpec['type'] == 'boolean') {
152
+		$paramSpec['value'] = ($paramSpec['value']) ? 'true' : 'false';
153
+	  }
154
+	  if ($paramSpec['location'] == 'path') {
155
+		$uriTemplateVars[$paramName] = $paramSpec['value'];
156
+	  } else if ($paramSpec['location'] == 'query') {
157
+		if (isset($paramSpec['repeated']) && is_array($paramSpec['value'])) {
158
+		  foreach ($paramSpec['value'] as $value) {
159
+			$queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($value));
160
+		  }
161
+		} else {
162
+		  $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($paramSpec['value']));
163
+		}
164
+	  }
165
+	}
166 166
 
167
-    if (count($uriTemplateVars)) {
168
-      $uriTemplateParser = new Google_Utils_URITemplate();
169
-      $requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars);
170
-    }
167
+	if (count($uriTemplateVars)) {
168
+	  $uriTemplateParser = new Google_Utils_URITemplate();
169
+	  $requestUrl = $uriTemplateParser->parse($requestUrl, $uriTemplateVars);
170
+	}
171 171
 
172
-    if (count($queryVars)) {
173
-      $requestUrl .= '?' . implode($queryVars, '&');
174
-    }
172
+	if (count($queryVars)) {
173
+	  $requestUrl .= '?' . implode($queryVars, '&');
174
+	}
175 175
 
176
-    return $requestUrl;
176
+	return $requestUrl;
177 177
   }
178 178
 }
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
  */
17 17
 
18 18
 if (!class_exists('Google_Client')) {
19
-  require_once dirname(__FILE__) . '/../autoload.php';
19
+  require_once dirname(__FILE__).'/../autoload.php';
20 20
 }
21 21
 
22 22
 /**
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
 
79 79
     if ((intVal($code)) >= 300) {
80 80
       $decoded = json_decode($body, true);
81
-      $err = 'Error calling ' . $response->getRequestMethod() . ' ' . $response->getUrl();
81
+      $err = 'Error calling '.$response->getRequestMethod().' '.$response->getUrl();
82 82
       if (isset($decoded['error']) &&
83
-          isset($decoded['error']['message'])  &&
83
+          isset($decoded['error']['message']) &&
84 84
           isset($decoded['error']['code'])) {
85 85
         // if we're getting a json encoded error definition, use that instead of the raw response
86 86
         // body for improved readability
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
    */
145 145
   public static function createRequestUri($servicePath, $restPath, $params)
146 146
   {
147
-    $requestUrl = $servicePath . $restPath;
147
+    $requestUrl = $servicePath.$restPath;
148 148
     $uriTemplateVars = array();
149 149
     $queryVars = array();
150 150
     foreach ($params as $paramName => $paramSpec) {
@@ -156,10 +156,10 @@  discard block
 block discarded – undo
156 156
       } else if ($paramSpec['location'] == 'query') {
157 157
         if (isset($paramSpec['repeated']) && is_array($paramSpec['value'])) {
158 158
           foreach ($paramSpec['value'] as $value) {
159
-            $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($value));
159
+            $queryVars[] = $paramName.'='.rawurlencode(rawurldecode($value));
160 160
           }
161 161
         } else {
162
-          $queryVars[] = $paramName . '=' . rawurlencode(rawurldecode($paramSpec['value']));
162
+          $queryVars[] = $paramName.'='.rawurlencode(rawurldecode($paramSpec['value']));
163 163
         }
164 164
       }
165 165
     }
@@ -170,7 +170,7 @@  discard block
 block discarded – undo
170 170
     }
171 171
 
172 172
     if (count($queryVars)) {
173
-      $requestUrl .= '?' . implode($queryVars, '&');
173
+      $requestUrl .= '?'.implode($queryVars, '&');
174 174
     }
175 175
 
176 176
     return $requestUrl;
Please login to merge, or discard this patch.