Skip to content

Commit

Permalink
cs-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtrovich committed Feb 9, 2024
1 parent 59a3f89 commit c1deb17
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 38 deletions.
53 changes: 53 additions & 0 deletions spec/system/framework/Router/DefinedRouteCollector.spec.php
Expand Up @@ -111,4 +111,57 @@

expect($expected)->toBe($definedRoutes);
});

it('Test de collection avec l\'option $reset = false', function () {
$routes = $this->getCollector();
$routes->get('journals', 'Blogs');
$routes->get('product/(:num)', 'Catalog::productLookupByID/$1');
$routes->get('feed', static fn () => 'A Closure route.');
$routes->view('about', 'pages/about');

$collector = new DefinedRouteCollector($routes);

$expected = [
[
'method' => 'GET',
'route' => 'journals',
'name' => 'journals',
'handler' => '\App\Controllers\Blogs',
],
[
'method' => 'GET',
'route' => 'product/([0-9]+)',
'name' => 'product/([0-9]+)',
'handler' => '\App\Controllers\Catalog::productLookupByID/$1',
],
[
'method' => 'GET',
'route' => 'feed',
'name' => 'feed',
'handler' => '(Closure)',
],
[
'method' => 'GET',
'route' => 'about',
'name' => 'about',
'handler' => '(View) pages/about',
],
];

$definedRoutes = [];

foreach ($collector->collect() as $route) {
$definedRoutes[] = $route;
}

expect($definedRoutes)->toBe($expected);

$definedRoutes = [];

foreach ($collector->collect(false) as $route) {
$definedRoutes[] = $route;
}

expect($definedRoutes)->toBe($expected);
});
});
10 changes: 5 additions & 5 deletions src/Config/Config.php
Expand Up @@ -240,12 +240,12 @@ public static function schema(string $key): ?Schema
} elseif (file_exists($app_schema)) {
$schema = require $app_schema;
} else {
$paths = Services::locator()->search('Config/schemas/' . $key);
$paths = Services::locator()->search('Config/schemas/' . $key);

if (isset($paths[0]) && file_exists($paths[0])) {
$schema = require $paths[0];
}
}
if (isset($paths[0]) && file_exists($paths[0])) {
$schema = require $paths[0];
}
}

return $schema ?? null;
}
Expand Down
34 changes: 20 additions & 14 deletions src/Enums/Method.php
@@ -1,5 +1,14 @@
<?php

/**
* This file is part of Blitz PHP framework.
*
* (c) 2022 Dimitri Sitchet Tomkeu <devcode.dst@gmail.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace BlitzPHP\Enums;

use InvalidArgumentException;
Expand All @@ -9,7 +18,7 @@
*/
abstract class Method
{
/**
/**
* Sûr : Non
* Idempotent : Non
* Cacheable : Non
Expand Down Expand Up @@ -90,22 +99,19 @@ abstract class Method
*/
public const TRACE = 'TRACE';

/**
* @param string $name
*/
public static function fromName(string $name): string
{
return match (strtolower($name)) {
'connect' => self::CONNECT,
'delete' => self::DELETE,
'get' => self::GET,
'head' => self::HEAD,
'options' => self::OPTIONS,
'patch' => self::PATCH,
'post' => self::POST,
'put' => self::PUT,
'trace' => self::TRACE,
default => throw new InvalidArgumentException('Nom de methode inconnu')
'connect' => self::CONNECT,
'delete' => self::DELETE,
'get' => self::GET,
'head' => self::HEAD,
'options' => self::OPTIONS,
'patch' => self::PATCH,
'post' => self::POST,
'put' => self::PUT,
'trace' => self::TRACE,
default => throw new InvalidArgumentException('Nom de methode inconnu')
};
}

Expand Down
24 changes: 12 additions & 12 deletions src/Router/AutoRouter.php
Expand Up @@ -49,8 +49,8 @@ final class AutoRouter implements AutoRouterInterface
*/
private array $params = [];

/**
* Whether to translate dashes in URIs for controller/method to CamelCase.
/**
* Indique si on doit traduire les tirets de l'URL pour les controleurs/methodes en CamelCase.
* E.g., blog-controller -> BlogController
*/
private bool $translateUriToCamelCase;
Expand Down Expand Up @@ -121,7 +121,7 @@ public function __construct(
) {
$this->namespace = rtrim($namespace, '\\');

$routingConfig = (object) config('routing');
$routingConfig = (object) config('routing');
$this->moduleRoutes = $routingConfig->module_routes;
$this->translateUriToCamelCase = $routingConfig->translate_uri_to_camel_case;

Expand Down Expand Up @@ -154,7 +154,7 @@ private function searchFirstController(): bool

$controllerPos = -1;

while ($segments !== []) {
while ($segments !== []) {
$segment = array_shift($segments);
$controllerPos++;

Expand All @@ -167,11 +167,11 @@ private function searchFirstController(): bool

$controller = $this->makeController($controller . '\\' . $class);

if (class_exists($controller)) {
if (class_exists($controller)) {
$this->controller = $controller;
$this->controllerPos = $controllerPos;

$this->checkUriForController($controller);
$this->checkUriForController($controller);

// Le premier élément peut être un nom de méthode.
$this->params = $segments;
Expand Down Expand Up @@ -253,7 +253,7 @@ private function searchLastDefaultController(): bool
*/
public function getRoute(string $uri, string $httpVerb): array
{
$this->uri = $uri;
$this->uri = $uri;
$httpVerb = strtolower($httpVerb);

// Reinitialise les parametres de la methode du controleur.
Expand Down Expand Up @@ -292,14 +292,14 @@ public function getRoute(string $uri, string $httpVerb): array
/** @var string[] $params */
$params = $this->params;

$methodParam = array_shift($params);
$methodParam = array_shift($params);

$method = '';
if ($methodParam !== null) {
$method = $httpVerb . ucfirst($this->translateURIDashes($methodParam));

$this->checkUriForMethod($method);
}
$this->checkUriForMethod($method);
}

if ($methodParam !== null && method_exists($this->controller, $method)) {
// Methode trouvee.
Expand Down Expand Up @@ -441,7 +441,7 @@ private function checkUnderscore(string $uri): void
* Vérifier l'URI du contrôleur pour $translateUriToCamelCase
*
* @param string $classname Nom de classe du contrôleur généré à partir de l'URI.
* La casse peut être un peu incorrecte.
* La casse peut être un peu incorrecte.
*/
private function checkUriForController(string $classname): void
{
Expand All @@ -460,7 +460,7 @@ private function checkUriForController(string $classname): void
* Vérifier l'URI pour la méthode $translateUriToCamelCase
*
* @param string $method Nom de la méthode du contrôleur généré à partir de l'URI.
* La casse peut être un peu incorrecte.
* La casse peut être un peu incorrecte.
*/
private function checkUriForMethod(string $method): void
{
Expand Down
2 changes: 1 addition & 1 deletion src/Router/RouteBuilder.php
Expand Up @@ -152,7 +152,7 @@ public function form(string $from, $to, array $options = []): void
$this->attributes = [];

if (isset($options['unique'])) {
$this->collection->form($from, $to, $options);
$this->collection->form($from, $to, $options);

return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/Router/RouteCollection.php
Expand Up @@ -469,7 +469,7 @@ public function getDefaultNamespace(): string
return $this->defaultNamespace;
}

/**
/**
* Pour `klinge route:list`
*
* @return array<string, string>
Expand Down Expand Up @@ -527,8 +527,8 @@ public function shouldUseSupportedLocalesOnly(): bool

/**
* {@inheritDoc}
*
* @internal
*
* @internal
*/
public function getRegisteredControllers(?string $verb = '*'): array
{
Expand Down Expand Up @@ -1592,7 +1592,7 @@ private function formatRouteName(string $name): string
return str_replace(['/', '\\', '_', '.', ' '], '.', $name);
}

/**
/**
* @param (Closure(mixed...): (ResponseInterface|string|void))|string $handler
*/
private function getControllerName(Closure|string $handler): ?string
Expand Down
2 changes: 1 addition & 1 deletion src/Router/Router.php
Expand Up @@ -32,7 +32,7 @@
*/
class Router implements RouterInterface
{
/**
/**
* List of allowed HTTP methods (and CLI for command line use).
*/
public const HTTP_METHODS = [
Expand Down
2 changes: 1 addition & 1 deletion src/Spec/CliOutputHelper.php
Expand Up @@ -50,7 +50,7 @@ public static function tearDownAfterClass(): void
{
// Make sure we clean up after ourselves:
if (is_dir($dirname = pathinfo(static::$ou, PATHINFO_DIRNAME))) {
Fs::deleteDirectories($dirname);
Fs::cleanDirectory($dirname);
}
}

Expand Down

0 comments on commit c1deb17

Please sign in to comment.