Skip to content
This repository has been archived by the owner on Sep 14, 2019. It is now read-only.

Commit

Permalink
satisfying the nagging code standards
Browse files Browse the repository at this point in the history
  • Loading branch information
triplepoint committed Mar 17, 2013
1 parent 2526c7b commit 6d976fd
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion source/Groundhog/Router/Route.php
Expand Up @@ -185,7 +185,7 @@ public function extractParametersFromRequest(RequestInterface $request)
array_shift($result);

// If the result has content
if ( !empty($result) ) {
if (!empty($result)) {
// Create a new array using the route parameter order as the keys and the request values as the values
$result = array_combine(unserialize($this->parameter_order), array_values($result));

Expand Down
20 changes: 10 additions & 10 deletions source/Groundhog/Router/RouteParserAnnotation.php
Expand Up @@ -84,13 +84,13 @@ private function includeAllPhpFiles($root_path)
// Loop through the target path and include any class files discovered
foreach (new \DirectoryIterator($root_path) as $file_in_dir) {

if ( $file_in_dir->isDot() ) {
if ($file_in_dir->isDot()) {
continue;

} else if ( $file_in_dir->isDir() ) {
} else if ($file_in_dir->isDir()) {
$this->includeAllPhpFiles($file_in_dir->getPathName());

} else if ( $file_in_dir->getExtension() == 'php' ) {
} else if ($file_in_dir->getExtension() == 'php') {
include_once $file_in_dir->getPathName();
}
}
Expand All @@ -109,15 +109,15 @@ private function fetchAllDefinedConcreteClassesOfType($interface)

$result = array();
foreach ($declared_classes as $class_name) {
if ( !($reflect = new \ReflectionClass($class_name)) ) {
if (!($reflect = new \ReflectionClass($class_name))) {
continue;
}

if ($reflect->isAbstract()) {
continue;
}

if ( !in_array($interface, $reflect->getInterfaceNames()) ) {
if (!in_array($interface, $reflect->getInterfaceNames())) {
continue;
}

Expand All @@ -143,14 +143,14 @@ private function fetchAllDefinedConcreteClassesOfType($interface)
private function extractRoutesFromMethodHeader($method_comment)
{
// If the method has a !NoRoute annotation then its marked for being skipped. Return an empty array.
if ( preg_match('/\!NoRoute/i', $method_comment) ) {
if (preg_match('/\!NoRoute/i', $method_comment)) {
return array();
}

preg_match_all('/ \!HttpRoute [ \t]+ (?P<request_method>[A-Za-z]+) [ \t]* (?P<request_route>[^ ]*) [ \t]* $/imx', $method_comment, $regex_routes, PREG_SET_ORDER);

$arr_method_routes = array();
if ( !empty($regex_routes) ) {
if (!empty($regex_routes)) {
foreach ($regex_routes as $match) {
$arr_method_routes[] = array(
'request_method' => $match['request_method'],
Expand Down Expand Up @@ -180,15 +180,15 @@ private function getRouteType($route_string)
// Does the route have wildcards?
$has_wildcards = (boolean) preg_match('/[#$]{1}([0-9])+/', $route_string);

if ( substr($route_string, 0, 2) == '//' ) {
if (substr($route_string, 0, 2) == '//') {
// Specific domain, unspecified protocol, absolute path info
$match_path = $has_wildcards ? Route::ROUTE_TYPE_ABSOLUTE_DOMAIN_WITH_WILDCARDS : Route::ROUTE_TYPE_ABSOLUTE_DOMAIN;

} else if ( substr($route_string, 0, 1) == '/' ) {
} else if (substr($route_string, 0, 1) == '/') {
// Absolute path, relative to the domain root
$match_path = $has_wildcards ? Route::ROUTE_TYPE_ABSOLUTE_PATH_WITH_WILDCARDS : Route::ROUTE_TYPE_ABSOLUTE_PATH;

} else if ( strpos($route_string, '://') !== false ) {
} else if (strpos($route_string, '://') !== false) {
// Specific domain, specific protocol, absolute paths
$match_path = $has_wildcards ? Route::ROUTE_TYPE_ABSOLUTE_PROTOCOL_WITH_WILDCARDS : Route::ROUTE_TYPE_ABSOLUTE_PROTOCOL;

Expand Down
8 changes: 4 additions & 4 deletions source/Groundhog/Router/RoutingTableStoreApc.php
Expand Up @@ -67,7 +67,7 @@ public function getRoutingTable($query_string = '')
foreach ($stored_routing_table as $route) {
$keeper = null;
foreach (explode(' ', $query_string) as $query_fragment) {
if ( preg_match('/.*'.$query_fragment.'.*/i', $route->getRawRouteString()) ||
if (preg_match('/.*'.$query_fragment.'.*/i', $route->getRawRouteString()) ||
preg_match('/.*'.$query_fragment.'.*/i', $route->getClassName()) ||
preg_match('/.*'.$query_fragment.'.*/i', $route->getRouteHttpMethod())
) {
Expand Down Expand Up @@ -99,17 +99,17 @@ public function findMatchingRoute(RequestInterface $request)
foreach ($stored_routing_table as $route) {

foreach ($arr_match_types as $route_type => $route_match) {
if ( $route->getRouteHttpMethod() == $request->getMethod() && $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) {
if ($route->getRouteHttpMethod() == $request->getMethod() && $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) {
return $route;

} else if ( $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) {
} else if ($route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) {
$arr_allowed_methods[] = $route->getRouteHttpMethod();
}
}
}

// No match found
if ( !empty($arr_allowed_methods) ) {
if (!empty($arr_allowed_methods)) {
// If there's a match on this URL, just not for the given HTTP method, return a 405
throw new ExceptionMethodNotAllowed($arr_allowed_methods);

Expand Down
12 changes: 6 additions & 6 deletions source/Groundhog/Router/RoutingTableStoreNoCache.php
Expand Up @@ -35,9 +35,9 @@ public function getRoutingTable($query_string = '')
foreach ($this->stored_routing_table as $route) {
$is_search_match = null;
foreach (explode(' ', $query_string) as $query_fragment) {
if ( preg_match('/.*'.$query_fragment.'.*/i', $route->getRawRouteString()) ||
preg_match('/.*'.$query_fragment.'.*/i', $route->getClassName()) ||
preg_match('/.*'.$query_fragment.'.*/i', $route->getRouteHttpMethod())
if (preg_match('/.*'.$query_fragment.'.*/i', $route->getRawRouteString()) ||
preg_match('/.*'.$query_fragment.'.*/i', $route->getClassName()) ||
preg_match('/.*'.$query_fragment.'.*/i', $route->getRouteHttpMethod())
) {
$is_search_match = true;
} else {
Expand All @@ -63,17 +63,17 @@ public function findMatchingRoute(RequestInterface $request)
foreach ($this->stored_routing_table as $route) {

foreach ($arr_match_types as $route_type => $route_match) {
if ( $route->getRouteHttpMethod() == $request->getMethod() && $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) {
if ($route->getRouteHttpMethod() == $request->getMethod() && $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) {
return $route;

} else if ( $route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) {
} else if ($route->getRouteType() == $route_type && preg_match($route->getRouteRegex(), $route_match)) {
$arr_allowed_methods[] = $route->getRouteHttpMethod();
}
}
}

// No match found
if ( !empty($arr_allowed_methods) ) {
if (!empty($arr_allowed_methods)) {
// If there's a match on this URL, just not for the given HTTP method, return a 405
throw new ExceptionMethodNotAllowed($arr_allowed_methods);

Expand Down
14 changes: 7 additions & 7 deletions source/Groundhog/Router/RoutingTableStoreSqlite.php
Expand Up @@ -65,7 +65,7 @@ class_name text,
);

// Remove all the auto-generated routes
if ( ! $db->exec("DELETE FROM routing_table;") ) {
if (!$db->exec("DELETE FROM routing_table;")) {
throw new Exception("Trouble truncating routing table: ".$db->lastErrorMsg());
}

Expand All @@ -78,7 +78,7 @@ class_name text,
"' AND route_regex='".$db->escapeString($route->getRouteRegex()).
"' AND route_type='".$db->escapeString($route->getRouteType())."';"
);
if ( ($arr_result = $result->fetchArray(SQLITE3_ASSOC))!==false ) {
if (($arr_result = $result->fetchArray(SQLITE3_ASSOC))!==false) {
throw new Exception(
"This handler ({$route->getClassName()}) cannot handle this route ".
"({$route->getRouteHttpMethod()} {$route->getRawRouteString()}) because that route's regex ".
Expand Down Expand Up @@ -117,7 +117,7 @@ public function getRoutingTable($query_string = '')

// Determine the query
$where_clause = '';
if ( !empty($query_string) ) {
if (!empty($query_string)) {
$where_clause = " WHERE ";
foreach (explode(' ', $query_string) as $query_fragment) {
$where_clause .= "( ";
Expand All @@ -134,7 +134,7 @@ public function getRoutingTable($query_string = '')
// Load all the routing table records
$result = $db->query($query);
$routing_table = array();
while ( $arr_result = $result->fetchArray(SQLITE3_ASSOC) ) {
while ($arr_result = $result->fetchArray(SQLITE3_ASSOC)) {
$routing_table[] = new Route(
$arr_result['route_type'],
strtoupper($arr_result['route_http_method']),
Expand Down Expand Up @@ -179,18 +179,18 @@ function ($str, $regex) {
$arr_match = $result->fetchArray(SQLITE3_ASSOC);

// if there was no perfect match, we need to find out if the URL itself was legit, in order to know whether to assemble a 405 response, or a 404 response
if ( empty($arr_match) ) {
if (empty($arr_match)) {

// Determine if there were any matches at all for this URL, with any HTTP method
$error_result = $db->query("SELECT route_http_method FROM routing_table WHERE (".implode(' OR ', $arr_route_path_where_clause).");");

// Fetch the set of allowed methods (if any) on this route
$arr_allowed_methods = array();
while ($arr_result = $error_result->fetchArray(SQLITE3_ASSOC) ) {
while ($arr_result = $error_result->fetchArray(SQLITE3_ASSOC)) {
$arr_allowed_methods[] = $arr_result['route_http_method'];
}

if ( !empty($arr_allowed_methods) ) {
if (!empty($arr_allowed_methods)) {
// If there's a match on this URL, just not for the given HTTP method, return a 405
throw new ExceptionMethodNotAllowed($arr_allowed_methods);

Expand Down

0 comments on commit 6d976fd

Please sign in to comment.