From 7e584de9e84d842ab236eb96259cb745732ce203 Mon Sep 17 00:00:00 2001 From: radnan Date: Thu, 20 Jun 2013 13:38:08 -0500 Subject: [PATCH] return early if rule is * and remove one level of nesting --- src/Composer/Util/NoProxyPattern.php | 56 ++++++++++++++-------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/Composer/Util/NoProxyPattern.php b/src/Composer/Util/NoProxyPattern.php index 0ace86551..a5e74d802 100644 --- a/src/Composer/Util/NoProxyPattern.php +++ b/src/Composer/Util/NoProxyPattern.php @@ -54,40 +54,40 @@ class NoProxyPattern } foreach ($this->rules as $rule) { + if ($rule == '*') { + return true; + } + $match = false; - if ($rule == '*') { - $match = true; - } else { - list($ruleHost) = explode(':', $rule); - list($base) = explode('/', $ruleHost); + list($ruleHost) = explode(':', $rule); + list($base) = explode('/', $ruleHost); - if (filter_var($base, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { - // ip or cidr match + if (filter_var($base, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { + // ip or cidr match - if (!isset($ip)) { - $ip = gethostbyname($host); - } - - if (strpos($ruleHost, '/') === false) { - $match = $ip === $ruleHost; - } else { - $match = self::inCIDRBlock($ruleHost, $ip); - } - } else { - // match end of domain - - $haystack = '.' . trim($host, '.') . '.'; - $needle = '.'. trim($ruleHost, '.') .'.'; - $match = stripos(strrev($haystack), strrev($needle)) === 0; + if (!isset($ip)) { + $ip = gethostbyname($host); } - // final port check - if ($match && strpos($rule, ':') !== false) { - list(, $rulePort) = explode(':', $rule); - if (!empty($rulePort) && $port != $rulePort) { - $match = false; - } + if (strpos($ruleHost, '/') === false) { + $match = $ip === $ruleHost; + } else { + $match = self::inCIDRBlock($ruleHost, $ip); + } + } else { + // match end of domain + + $haystack = '.' . trim($host, '.') . '.'; + $needle = '.'. trim($ruleHost, '.') .'.'; + $match = stripos(strrev($haystack), strrev($needle)) === 0; + } + + // final port check + if ($match && strpos($rule, ':') !== false) { + list(, $rulePort) = explode(':', $rule); + if (!empty($rulePort) && $port != $rulePort) { + $match = false; } }