Skip to content

Commit da815c4

Browse files
committed
- use psr style
1 parent 93f39f2 commit da815c4

3 files changed

Lines changed: 70 additions & 69 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ script:
2323
- phpunit --colors tests/dHttpTest --coverage-clover=coverage.xml
2424

2525
after_success:
26-
- codecov
26+
- codecov

dHttp/Response.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(array $response)
4444
if (isset($response['options'][CURLOPT_HEADER]) && $response['options'][CURLOPT_HEADER]) {
4545
list($headers, $this->_body) = explode("\r\n\r\n", $response['response'], 2);
4646
// Parse headers
47-
$this->_parseHeaders($headers);
47+
$this->parseHeaders($headers);
4848
} else {
4949
$this->_body = $response['response'];
5050
}
@@ -139,10 +139,11 @@ public function __call($name, $params)
139139
return null;
140140
}
141141

142-
/**
143-
* Parse headers
144-
*/
145-
private function _parseHeaders($headers)
142+
/**
143+
* Parse headers
144+
* @param $headers
145+
*/
146+
private function parseHeaders($headers)
146147
{
147148
$exploded = explode("\r\n", $headers);
148149
foreach($exploded as $headerString) {

dHttp/Url.php

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -7,76 +7,76 @@
77
*/
88
class Url
99
{
10-
/**
11-
* Validate URL
12-
*
13-
* @param $url
14-
* @return string
15-
* @throws \Exception
16-
*/
17-
public static function validateUrl($url)
18-
{
19-
if (!trim($url)) {
20-
throw new \Exception("Provided URL '$url' cannot be empty");
21-
}
10+
/**
11+
* Validate URL
12+
*
13+
* @param $url
14+
* @return string
15+
* @throws \Exception
16+
*/
17+
public static function validateUrl($url)
18+
{
19+
if (!trim($url)) {
20+
throw new \Exception("Provided URL '$url' cannot be empty");
21+
}
2222

23-
// Split URL into parts first
24-
$parts = parse_url($url);
23+
// Split URL into parts first
24+
$parts = parse_url($url);
2525

26-
if (!$parts) {
27-
throw new \Exception("Error parsing URL '$url'");
28-
}
26+
if (!$parts) {
27+
throw new \Exception("Error parsing URL '$url'");
28+
}
2929

30-
if (!array_key_exists('host', $parts)) {
31-
throw new \Exception("Provided URL '$url' doesn't contain a hostname");
32-
}
30+
if (!array_key_exists('host', $parts)) {
31+
throw new \Exception("Provided URL '$url' doesn't contain a hostname");
32+
}
3333

34-
// Rebuild the URL
35-
$url = self::buildUrl($parts);
34+
// Rebuild the URL
35+
$url = self::buildUrl($parts);
3636

37-
return $url;
38-
}
37+
return $url;
38+
}
3939

40-
/**
41-
* Re-build a URL based on an array of parts
42-
*
43-
* @param array $parts
44-
* @return string
45-
*/
46-
public static function buildUrl(array $parts)
47-
{
48-
$url = '';
49-
$url .= (!empty($parts['scheme'])) ? $parts['scheme'] . '://' : '';
50-
$url .= (!empty($parts['user'])) ? $parts['user'] : '';
51-
$url .= (!empty($parts['pass'])) ? ':' . $parts['pass'] : '';
52-
//If we have a user or pass, make sure to add an "@"
53-
$url .= (!empty($parts['user']) || !empty($parts['pass'])) ? '@' : '';
54-
$url .= (!empty($parts['host'])) ? $parts['host'] : '';
55-
$url .= (!empty($parts['port'])) ? ':' . $parts['port'] : '';
56-
$url .= (!empty($parts['path'])) ? $parts['path'] : '';
57-
$url .= (!empty($parts['query'])) ? '?' . $parts['query'] : '';
58-
$url .= (!empty($parts['fragment'])) ? '#' . $parts['fragment'] : '';
40+
/**
41+
* Re-build a URL based on an array of parts
42+
*
43+
* @param array $parts
44+
* @return string
45+
*/
46+
public static function buildUrl(array $parts)
47+
{
48+
$url = '';
49+
$url .= (!empty($parts['scheme'])) ? $parts['scheme'] . '://' : '';
50+
$url .= (!empty($parts['user'])) ? $parts['user'] : '';
51+
$url .= (!empty($parts['pass'])) ? ':' . $parts['pass'] : '';
52+
//If we have a user or pass, make sure to add an "@"
53+
$url .= (!empty($parts['user']) || !empty($parts['pass'])) ? '@' : '';
54+
$url .= (!empty($parts['host'])) ? $parts['host'] : '';
55+
$url .= (!empty($parts['port'])) ? ':' . $parts['port'] : '';
56+
$url .= (!empty($parts['path'])) ? $parts['path'] : '';
57+
$url .= (!empty($parts['query'])) ? '?' . $parts['query'] : '';
58+
$url .= (!empty($parts['fragment'])) ? '#' . $parts['fragment'] : '';
5959

60-
return $url;
61-
}
60+
return $url;
61+
}
6262

63-
/**
64-
* Checks a passed in IP against a CIDR.
65-
*
66-
* @param string $ip
67-
* @param string|array $ranges
68-
* @return bool
69-
*/
70-
public static function cidr_match($ip, $ranges)
71-
{
72-
$ranges = is_array($ranges) ? $ranges : (array)$ranges;
73-
foreach ($ranges as $range) {
74-
list($subnet, $mask) = explode('/', $range);
75-
if ((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) {
76-
return true;
77-
}
78-
}
63+
/**
64+
* Checks a passed in IP against a CIDR.
65+
*
66+
* @param string $ip
67+
* @param string|array $ranges
68+
* @return bool
69+
*/
70+
public static function cidrMatch($ip, $ranges)
71+
{
72+
$ranges = is_array($ranges) ? $ranges : (array)$ranges;
73+
foreach ($ranges as $range) {
74+
list($subnet, $mask) = explode('/', $range);
75+
if ((ip2long($ip) & ~((1 << (32 - $mask)) - 1)) == ip2long($subnet)) {
76+
return true;
77+
}
78+
}
7979

80-
return false;
81-
}
80+
return false;
81+
}
8282
}

0 commit comments

Comments
 (0)