From 9259c85586a35238aed9ba66a8de7743c0699e72 Mon Sep 17 00:00:00 2001 From: Timothy J Warren Date: Mon, 16 Mar 2020 15:06:55 -0400 Subject: [PATCH] Fix some style issues --- src/AnimeClient/Dispatcher.php | 40 +++++++++++++++---------------- src/AnimeClient/MenuGenerator.php | 6 ++--- src/AnimeClient/UrlGenerator.php | 10 ++++---- src/AnimeClient/Util.php | 16 ++++++------- 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/AnimeClient/Dispatcher.php b/src/AnimeClient/Dispatcher.php index f523103e..e0a98ca5 100644 --- a/src/AnimeClient/Dispatcher.php +++ b/src/AnimeClient/Dispatcher.php @@ -129,14 +129,7 @@ final class Dispatcher extends RoutingBase { } } - if ($route) - { - $parsed = $this->processRoute(new Friend($route)); - $controllerName = $parsed['controller_name']; - $actionMethod = $parsed['action_method']; - $params = $parsed['params']; - } - else + if ( ! $route) { // If not route was matched, return an appropriate http // error message @@ -144,8 +137,15 @@ final class Dispatcher extends RoutingBase { $controllerName = DEFAULT_CONTROLLER; $actionMethod = $errorRoute['action_method']; $params = $errorRoute['params']; + $this->call($controllerName, $actionMethod, $params); + return; } + $parsed = $this->processRoute(new Friend($route)); + $controllerName = $parsed['controller_name']; + $actionMethod = $parsed['action_method']; + $params = $parsed['params']; + $this->call($controllerName, $actionMethod, $params); } @@ -159,14 +159,15 @@ final class Dispatcher extends RoutingBase { */ protected function processRoute($route): array { + if ( ! array_key_exists('controller', $route->attributes)) + { + throw new LogicException('Missing controller'); + } + if (array_key_exists('controller', $route->attributes)) { $controllerName = $route->attributes['controller']; } - else - { - throw new LogicException('Missing controller'); - } // Get the full namespace for a controller if a short name is given if (strpos($controllerName, '\\') === FALSE) @@ -392,16 +393,15 @@ final class Dispatcher extends RoutingBase { if ( ! array_key_exists('tokens', $route)) { $routes[] = $this->router->$add($name, $path)->defaults($route); + continue; } - else - { - $tokens = $route['tokens']; - unset($route['tokens']); - $routes[] = $this->router->$add($name, $path) - ->defaults($route) - ->tokens($tokens); - } + $tokens = $route['tokens']; + unset($route['tokens']); + + $routes[] = $this->router->$add($name, $path) + ->defaults($route) + ->tokens($tokens); } return $routes; diff --git a/src/AnimeClient/MenuGenerator.php b/src/AnimeClient/MenuGenerator.php index d24e3b90..e04f4f89 100644 --- a/src/AnimeClient/MenuGenerator.php +++ b/src/AnimeClient/MenuGenerator.php @@ -72,10 +72,10 @@ final class MenuGenerator extends UrlGenerator { foreach ($menus as $name => $menu) { $parsed[$name] = []; - foreach ($menu['items'] as $path_name => $partial_path) + foreach ($menu['items'] as $pathName => $partialPath) { - $title = (string)$this->string($path_name)->humanize()->titleize(); - $parsed[$name][$title] = (string)$this->string($menu['route_prefix'])->append($partial_path); + $title = (string)$this->string($pathName)->humanize()->titleize(); + $parsed[$name][$title] = (string)$this->string($menu['route_prefix'])->append($partialPath); } } diff --git a/src/AnimeClient/UrlGenerator.php b/src/AnimeClient/UrlGenerator.php index 93f14951..831272cd 100644 --- a/src/AnimeClient/UrlGenerator.php +++ b/src/AnimeClient/UrlGenerator.php @@ -76,20 +76,20 @@ class UrlGenerator extends RoutingBase { // Remove any optional parameters from the route // and replace them with existing route parameters, if they exist - $path_segments = explode('/', $path); - $segment_count = count($path_segments); + $pathSegments = explode('/', $path); + $segmentCount = count($pathSegments); $segments = $this->segments(); - for ($i = 0; $i < $segment_count; $i++) + for ($i = 0; $i < $segmentCount; $i++) { if ( ! array_key_exists($i + 1, $segments)) { $segments[$i + 1] = ''; } - $path_segments[$i] = preg_replace('`{.*?}`', $segments[$i + 1], $path_segments[$i]); + $pathSegments[$i] = preg_replace('`{.*?}`', $segments[$i + 1], $pathSegments[$i]); } - $path = implode('/', $path_segments); + $path = implode('/', $pathSegments); $scheme = $this->config->get('secure_urls') !== FALSE ? 'https:' : 'http:'; diff --git a/src/AnimeClient/Util.php b/src/AnimeClient/Util.php index 3b54132f..4e03218d 100644 --- a/src/AnimeClient/Util.php +++ b/src/AnimeClient/Util.php @@ -57,25 +57,25 @@ class Util { /** * HTML selection helper function * - * @param string $a - First item to compare - * @param string $b - Second item to compare + * @param string $left - First item to compare + * @param string $right - Second item to compare * @return string */ - public static function isSelected(string $a, string $b): string + public static function isSelected(string $left, string $right): string { - return ($a === $b) ? 'selected' : ''; + return ($left === $right) ? 'selected' : ''; } /** * Inverse of selected helper function * - * @param string $a - First item to compare - * @param string $b - Second item to compare + * @param string $left - First item to compare + * @param string $right - Second item to compare * @return string */ - public static function isNotSelected(string $a, string $b): string + public static function isNotSelected(string $left, string $right): string { - return ($a !== $b) ? 'selected' : ''; + return ($left !== $right) ? 'selected' : ''; } /**