From da815c4c204e0f19902b43cac3faae5845c7a017 Mon Sep 17 00:00:00 2001 From: ARACOOOL Date: Wed, 1 Apr 2015 00:35:02 +0500 Subject: [PATCH] - use psr style --- .travis.yml | 2 +- dHttp/Response.php | 11 ++-- dHttp/Url.php | 126 ++++++++++++++++++++++----------------------- 3 files changed, 70 insertions(+), 69 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1b93f11..cc0f1da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -23,4 +23,4 @@ script: - phpunit --colors tests/dHttpTest --coverage-clover=coverage.xml after_success: - - codecov \ No newline at end of file + - codecov diff --git a/dHttp/Response.php b/dHttp/Response.php index 8a976ef..f53fd11 100644 --- a/dHttp/Response.php +++ b/dHttp/Response.php @@ -44,7 +44,7 @@ public function __construct(array $response) if (isset($response['options'][CURLOPT_HEADER]) && $response['options'][CURLOPT_HEADER]) { list($headers, $this->_body) = explode("\r\n\r\n", $response['response'], 2); // Parse headers - $this->_parseHeaders($headers); + $this->parseHeaders($headers); } else { $this->_body = $response['response']; } @@ -139,10 +139,11 @@ public function __call($name, $params) return null; } - /** - * Parse headers - */ - private function _parseHeaders($headers) + /** + * Parse headers + * @param $headers + */ + private function parseHeaders($headers) { $exploded = explode("\r\n", $headers); foreach($exploded as $headerString) { diff --git a/dHttp/Url.php b/dHttp/Url.php index 01551e3..2886cbd 100644 --- a/dHttp/Url.php +++ b/dHttp/Url.php @@ -7,76 +7,76 @@ */ class Url { - /** - * Validate URL - * - * @param $url - * @return string - * @throws \Exception - */ - public static function validateUrl($url) - { - if (!trim($url)) { - throw new \Exception("Provided URL '$url' cannot be empty"); - } + /** + * Validate URL + * + * @param $url + * @return string + * @throws \Exception + */ + public static function validateUrl($url) + { + if (!trim($url)) { + throw new \Exception("Provided URL '$url' cannot be empty"); + } - // Split URL into parts first - $parts = parse_url($url); + // Split URL into parts first + $parts = parse_url($url); - if (!$parts) { - throw new \Exception("Error parsing URL '$url'"); - } + if (!$parts) { + throw new \Exception("Error parsing URL '$url'"); + } - if (!array_key_exists('host', $parts)) { - throw new \Exception("Provided URL '$url' doesn't contain a hostname"); - } + if (!array_key_exists('host', $parts)) { + throw new \Exception("Provided URL '$url' doesn't contain a hostname"); + } - // Rebuild the URL - $url = self::buildUrl($parts); + // Rebuild the URL + $url = self::buildUrl($parts); - return $url; - } + return $url; + } - /** - * Re-build a URL based on an array of parts - * - * @param array $parts - * @return string - */ - public static function buildUrl(array $parts) - { - $url = ''; - $url .= (!empty($parts['scheme'])) ? $parts['scheme'] . '://' : ''; - $url .= (!empty($parts['user'])) ? $parts['user'] : ''; - $url .= (!empty($parts['pass'])) ? ':' . $parts['pass'] : ''; - //If we have a user or pass, make sure to add an "@" - $url .= (!empty($parts['user']) || !empty($parts['pass'])) ? '@' : ''; - $url .= (!empty($parts['host'])) ? $parts['host'] : ''; - $url .= (!empty($parts['port'])) ? ':' . $parts['port'] : ''; - $url .= (!empty($parts['path'])) ? $parts['path'] : ''; - $url .= (!empty($parts['query'])) ? '?' . $parts['query'] : ''; - $url .= (!empty($parts['fragment'])) ? '#' . $parts['fragment'] : ''; + /** + * Re-build a URL based on an array of parts + * + * @param array $parts + * @return string + */ + public static function buildUrl(array $parts) + { + $url = ''; + $url .= (!empty($parts['scheme'])) ? $parts['scheme'] . '://' : ''; + $url .= (!empty($parts['user'])) ? $parts['user'] : ''; + $url .= (!empty($parts['pass'])) ? ':' . $parts['pass'] : ''; + //If we have a user or pass, make sure to add an "@" + $url .= (!empty($parts['user']) || !empty($parts['pass'])) ? '@' : ''; + $url .= (!empty($parts['host'])) ? $parts['host'] : ''; + $url .= (!empty($parts['port'])) ? ':' . $parts['port'] : ''; + $url .= (!empty($parts['path'])) ? $parts['path'] : ''; + $url .= (!empty($parts['query'])) ? '?' . $parts['query'] : ''; + $url .= (!empty($parts['fragment'])) ? '#' . $parts['fragment'] : ''; - return $url; - } + return $url; + } - /** - * Checks a passed in IP against a CIDR. - * - * @param string $ip - * @param string|array $ranges - * @return bool - */ - public static function cidr_match($ip, $ranges) - { - $ranges = is_array($ranges) ? $ranges : (array)$ranges; - foreach ($ranges as $range) { - list($subnet, $mask) = explode('/', $range); - if ((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) { - return true; - } - } + /** + * Checks a passed in IP against a CIDR. + * + * @param string $ip + * @param string|array $ranges + * @return bool + */ + public static function cidrMatch($ip, $ranges) + { + $ranges = is_array($ranges) ? $ranges : (array)$ranges; + foreach ($ranges as $range) { + list($subnet, $mask) = explode('/', $range); + if ((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) { + return true; + } + } - return false; - } + return false; + } }