Conditions | 14 |
Paths | 385 |
Total Lines | 73 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
62 | public function makeRequest(Google_HttpRequest $request) { |
||
63 | // First, check to see if we have a valid cached version. |
||
64 | $cached = $this->getCachedRequest($request); |
||
65 | if ($cached !== false) { |
||
66 | if (!$this->checkMustRevaliadateCachedRequest($cached, $request)) { |
||
67 | return $cached; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | $default_options = stream_context_get_options(stream_context_get_default()); |
||
72 | |||
73 | $requestHttpContext = array_key_exists('http', $default_options) ? |
||
74 | $default_options['http'] : array(); |
||
75 | if (array_key_exists($request->getRequestMethod(), |
||
76 | self::$ENTITY_HTTP_METHODS)) { |
||
77 | $request = $this->processEntityRequest($request); |
||
78 | } |
||
79 | |||
80 | if ($request->getPostBody()) { |
||
81 | $requestHttpContext["content"] = $request->getPostBody(); |
||
82 | } |
||
83 | |||
84 | $requestHeaders = $request->getRequestHeaders(); |
||
85 | if ($requestHeaders && is_array($requestHeaders)) { |
||
86 | $headers = ""; |
||
87 | foreach($requestHeaders as $k => $v) { |
||
88 | $headers .= "$k: $v\n"; |
||
89 | } |
||
90 | $requestHttpContext["header"] = $headers; |
||
91 | } |
||
92 | |||
93 | $requestHttpContext["method"] = $request->getRequestMethod(); |
||
94 | $requestHttpContext["user_agent"] = $request->getUserAgent(); |
||
95 | |||
96 | $requestSslContext = array_key_exists('ssl', $default_options) ? |
||
97 | $default_options['ssl'] : array(); |
||
98 | |||
99 | if (!array_key_exists("cafile", $requestSslContext)) { |
||
100 | $requestSslContext["cafile"] = dirname(__FILE__) . '/cacerts.pem'; |
||
101 | } |
||
102 | |||
103 | $options = array("http" => array_merge(self::$DEFAULT_HTTP_CONTEXT, |
||
104 | $requestHttpContext), |
||
105 | "ssl" => array_merge(self::$DEFAULT_SSL_CONTEXT, |
||
106 | $requestSslContext)); |
||
107 | |||
108 | $context = stream_context_create($options); |
||
109 | |||
110 | $response_data = file_get_contents($request->getUrl(), |
||
111 | false, |
||
112 | $context); |
||
113 | |||
114 | if (false === $response_data) { |
||
115 | throw new Google_IOException("HTTP Error: Unable to connect"); |
||
116 | } |
||
117 | |||
118 | $respHttpCode = $this->getHttpResponseCode($http_response_header); |
||
119 | $responseHeaders = $this->getHttpResponseHeaders($http_response_header); |
||
120 | |||
121 | if ($respHttpCode == 304 && $cached) { |
||
122 | // If the server responded NOT_MODIFIED, return the cached request. |
||
123 | $this->updateCachedRequest($cached, $responseHeaders); |
||
124 | return $cached; |
||
125 | } |
||
126 | |||
127 | $request->setResponseHttpCode($respHttpCode); |
||
128 | $request->setResponseHeaders($responseHeaders); |
||
129 | $request->setResponseBody($response_data); |
||
130 | // Store the request in cache (the function checks to see if the request |
||
131 | // can actually be cached) |
||
132 | $this->setCachedRequest($request); |
||
133 | return $request; |
||
134 | } |
||
135 | |||
171 |
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.