diff --git a/Controller/RoutingController.php b/Controller/RoutingController.php index c88a288..4379ce4 100644 --- a/Controller/RoutingController.php +++ b/Controller/RoutingController.php @@ -36,8 +36,6 @@ public function __construct(RoutingExtractor $extractor, SerializerInterface $se /** * Return the exposed routes as JSON * This method does not have a route and is called directly from the twig template - * - * @return \Symfony\Component\HttpFoundation\Response */ public function routingData(): JsonResponse { diff --git a/DependencyInjection/XactJSRoutingExtension.php b/DependencyInjection/XactJSRoutingExtension.php index e6fcb36..e16d7f7 100644 --- a/DependencyInjection/XactJSRoutingExtension.php +++ b/DependencyInjection/XactJSRoutingExtension.php @@ -11,13 +11,23 @@ class XactJSRoutingExtension extends Extension implements PrependExtensionInterface { - public function load(array $configs, ContainerBuilder $container) + /** + * Load the DI configuration + * + * @param mixed[] $configs + * + * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter + */ + public function load(array $configs, ContainerBuilder $container): void { $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); $loader->load('services.yaml'); } - public function prepend(ContainerBuilder $container) + /** + * Prepend the twig configuration with @XactJSRouting for accessing the template + */ + public function prepend(ContainerBuilder $container): void { $fileSystem = new Filesystem(); $projectDir = $container->getParameter('kernel.project_dir'); @@ -28,4 +38,3 @@ public function prepend(ContainerBuilder $container) $container->prependExtensionConfig('twig', $twigConfig); } } - diff --git a/Extractor/ExtractedRoute.php b/Extractor/ExtractedRoute.php index 8d24fc6..1738000 100644 --- a/Extractor/ExtractedRoute.php +++ b/Extractor/ExtractedRoute.php @@ -13,39 +13,39 @@ class ExtractedRoute { /** - * @var array + * @var string[] */ private $tokens; /** - * @var array + * @var string[] */ private $defaults; /** - * @var array + * @var string[] */ private $requirements; /** - * @var array + * @var string[] */ private $hosttokens; /** - * @var array + * @var string[] */ private $methods; /** - * @var array + * @var string[] */ private $schemes; /** * Constructor * - * @param array $tokens - * @param array $defaults - * @param array $requirements - * @param array $hosttokens - * @param array $methods - * @param array $schemes + * @param string[] $tokens + * @param string[] $defaults + * @param string[] $requirements + * @param string[] $hosttokens + * @param string[] $methods + * @param string[] $schemes */ public function __construct(array $tokens, array $defaults, array $requirements, array $hosttokens = [], array $methods = [], array $schemes = []) { @@ -60,9 +60,9 @@ public function __construct(array $tokens, array $defaults, array $requirements, /** * Return the route tokens * - * @return array + * @return string[] */ - public function getTokens() + public function getTokens(): array { return $this->tokens; } @@ -70,9 +70,9 @@ public function getTokens() /** * Return the route defaults * - * @return array + * @return string[] */ - public function getDefaults() + public function getDefaults(): array { return $this->defaults; } @@ -80,9 +80,9 @@ public function getDefaults() /** * Return the route requirements * - * @return array + * @return string[] */ - public function getRequirements() + public function getRequirements(): array { return $this->requirements; } @@ -90,9 +90,9 @@ public function getRequirements() /** * Return the route host tokens * - * @return array + * @return string[] */ - public function getHosttokens() + public function getHosttokens(): array { return $this->hosttokens; } @@ -100,9 +100,9 @@ public function getHosttokens() /** * Return the route methods * - * @return array + * @return string[] */ - public function getMethods() + public function getMethods(): array { return $this->methods; } @@ -110,9 +110,9 @@ public function getMethods() /** * Return the route schemes * - * @return array + * @return string[] */ - public function getSchemes() + public function getSchemes(): array { return $this->schemes; } diff --git a/Extractor/RoutingExtractor.php b/Extractor/RoutingExtractor.php index 5126531..04de3f2 100644 --- a/Extractor/RoutingExtractor.php +++ b/Extractor/RoutingExtractor.php @@ -33,12 +33,9 @@ class RoutingExtractor /** * Default constructor. * - * @param RouterInterface $router - * @param string $cacheDir - * @param string $appEnv - * @param array $routesToExpose + * @param object[] $routesToExpose */ - public function __construct(RouterInterface $router, $cacheDir, $appEnv, array $routesToExpose = []) + public function __construct(RouterInterface $router, string $cacheDir, string $appEnv, array $routesToExpose = []) { $this->router = $router; $this->routesToExpose = $routesToExpose; @@ -59,7 +56,7 @@ public function getRoutes() $compiledRoute = $route->compile(); $defaults = array_intersect_key( $route->getDefaults(), - array_fill_keys($compiledRoute->getVariables(), NULL) + array_fill_keys($compiledRoute->getVariables(), null) ); $requirements = $route->getRequirements(); $hostTokens = method_exists($compiledRoute, 'getHostTokens') ? $compiledRoute->getHostTokens() : []; @@ -86,12 +83,14 @@ public function getExposedRoutes() $pattern = $this->buildPattern(); foreach ($collection->all() as $name => $route) { - if (FALSE === $route->getOption('expose')) { + if (false === $route->getOption('expose')) { continue; } - if (($route->getOption('expose') && (TRUE === $route->getOption('expose') || 'true' === $route->getOption('expose'))) - || ('' !== $pattern && preg_match('#' . $pattern . '#', $name))) { + if ( + ($route->getOption('expose') && (true === $route->getOption('expose') || 'true' === $route->getOption('expose'))) + || ('' !== $pattern && preg_match('#' . $pattern . '#', $name)) + ) { $routes[$name] = $route; } } @@ -126,10 +125,8 @@ public function getHost() /** * Check whether server is serving this request from a non-standard port. - * - * @return bool */ - protected function usesNonStandardPort() + protected function usesNonStandardPort(): bool { return $this->usesNonStandardHttpPort() || $this->usesNonStandardHttpsPort(); } @@ -167,10 +164,8 @@ public function getResources() /** * Convert the routesToExpose array in a regular expression pattern. - * - * @return string */ - protected function buildPattern() + protected function buildPattern(): string { $patterns = []; foreach ($this->routesToExpose as $toExpose) { @@ -182,20 +177,16 @@ protected function buildPattern() /** * Checks whether server is serving HTTP over a non-standard port. - * - * @return bool */ - private function usesNonStandardHttpPort() + private function usesNonStandardHttpPort(): bool { return 'http' === $this->getScheme() && '80' != $this->router->getContext()->getHttpPort(); } /** * Checks whether server is serving HTTPS over a non-standard port. - * - * @return bool */ - private function usesNonStandardHttpsPort() + private function usesNonStandardHttpsPort(): bool { return 'https' === $this->getScheme() && '443' != $this->router->getContext()->getHttpsPort(); }