Skip to content

Commit

Permalink
Merge pull request #116 from ncou/analysis-Xpa35V
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
ncou committed Jun 23, 2019
2 parents de61be1 + 5731b4a commit ec8107d
Show file tree
Hide file tree
Showing 23 changed files with 80 additions and 144 deletions.
2 changes: 1 addition & 1 deletion src/Chiron/Handler/Formatter/HtmlFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
namespace Chiron\Handler\Formatter;

use Chiron\Http\Exception\HttpException;
use function file_get_contents;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;
use function file_get_contents;

class HtmlFormatter implements FormatterInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Chiron/Handler/Formatter/ViewFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Chiron\Handler\Formatter;

use function array_merge;
use Chiron\Http\Exception\HttpException;
use Chiron\Views\TemplateRendererInterface;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;
use function array_merge;

class ViewFormatter implements FormatterInterface
{
Expand Down
2 changes: 1 addition & 1 deletion src/Chiron/Handler/Formatter/WhoopsFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

namespace Chiron\Handler\Formatter;

use function class_exists;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;
use Whoops\Handler\PrettyPageHandler;
use Whoops\Run as Whoops;
use function class_exists;

// ajouter les informations sur la request de l'application !!!!
//https://github.com/zendframework/zend-expressive/blob/master/src/Middleware/WhoopsErrorResponseGenerator.php#L95
Expand Down
2 changes: 1 addition & 1 deletion src/Chiron/Handler/Reporter/CallableReporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace Chiron\Handler\Reporter;

use function call_user_func_array;
use Exception;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;
use function call_user_func_array;

class CallableReporter implements ReporterInterface
{
Expand Down
1 change: 0 additions & 1 deletion src/Chiron/Http/Middleware/CheckMaintenanceMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?php


// TODO : regarder ici : https://gist.github.com/harini-ua/51d577023c7e8e7b6413a717b69c5dc5

// TODO : regarder ici comment c'est fait, on vire le cache si on n'a pas de valeur pour "Retry-After" ou un "Expires" header !!!! https://github.com/juliangut/janitor/blob/master/src/Handler/Render.php
Expand Down
1 change: 0 additions & 1 deletion src/Chiron/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ public function handle(ServerRequestInterface $request): ResponseInterface
$handler = $this->buildHandler();

return $handler->handle($request);

}

protected function buildHandler(): RequestHandlerInterface
Expand Down
2 changes: 1 addition & 1 deletion src/Chiron/Provider/ConfigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function register(Container $container): void
$container->closure(Config::class, function() {
$settings['app']['settings']['basePath'] = '/';
$settings['app']['debug'] = false;
return new Config($settings);
});*/

Expand Down
10 changes: 5 additions & 5 deletions src/Chiron/Provider/HttpFactoriesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,23 +87,23 @@ public function register(Container $container): void
$kernel[RequestFactory::class] = function ($c) {
return $c->get(RequestFactoryInterface::class);
};
$kernel[ResponseFactory::class] = function ($c) {
return $c->get(ResponseFactoryInterface::class);
};
$kernel[ServerRequestFactory::class] = function ($c) {
return $c->get(ServerRequestFactoryInterface::class);
};
$kernel[UriFactory::class] = function ($c) {
return $c->get(UriFactoryInterface::class);
};
$kernel[UploadedFileFactory::class] = function ($c) {
return $c->get(UploadedFileFactoryInterface::class);
};
$kernel[StreamFactory::class] = function ($c) {
return $c->get(StreamFactoryInterface::class);
};*/
Expand Down
11 changes: 3 additions & 8 deletions src/Chiron/Routing/Controller/RedirectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,11 @@

namespace Chiron\Routing\Controller;

use Chiron\Kernel;
use Chiron\Routing\Route;
use LogicException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\ResponseInterface;

class RedirectController
{

protected $responseFactory;

public function __construct(ResponseFactoryInterface $responseFactory)
Expand All @@ -24,8 +19,8 @@ public function __construct(ResponseFactoryInterface $responseFactory)
/**
* Invoke the controller method.
*
* @param string $destination
* @param int $status
* @param string $destination
* @param int $status
*
* @return Psr\Http\Message\ResponseInterface
*/
Expand Down
13 changes: 5 additions & 8 deletions src/Chiron/Routing/Controller/ViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,6 @@

namespace Chiron\Routing\Controller;

use Chiron\Kernel;
use Chiron\Routing\Route;
use LogicException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Chiron\Views\TemplateRendererInterface;

class ViewController
Expand All @@ -19,20 +14,22 @@ class ViewController
* @var \Illuminate\Contracts\View\Factory
*/
protected $renderer;

/**
* Create a new controller instance.
*
* @param \Illuminate\Contracts\View\Factory $view
* @return void
* @param \Illuminate\Contracts\View\Factory $view
*/
public function __construct(TemplateRendererInterface $renderer)
{
$this->renderer = $renderer;
}

/**
* Invoke the controller method.
*
* @param array $args
* @param array $args
*
* @return \Illuminate\Contracts\View\View
*/
//public function __invoke(...$args)
Expand Down
1 change: 0 additions & 1 deletion src/Chiron/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ public function setAllowedMethods(array $methods): self
return $this;
}


/*
public function method(string $method, string ...$methods): self
{
Expand Down
18 changes: 9 additions & 9 deletions src/Chiron/Routing/RouteGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class RouteGroup implements MiddlewareAwareInterface, RouteCollectionInterface,
/**
* Constructor.
*
* @param string $prefix
* @param callable $callback
* @param string $prefix
* @param callable $callback
* @param RouteCollectionInterface $collection
*/
// TODO : vérifier si on pas plutot utiliser un Closure au lieu d'un callable pour le typehint
Expand Down Expand Up @@ -143,11 +143,11 @@ public function __invoke(): void
($this->callback)($this);
}

/*
public function collectRoutes(): RouteGroupInterface
{
$callable = $this->callableResolver->resolve($this->callable);
$callable($this->routeCollectorProxy);
return $this;
}*/
/*
public function collectRoutes(): RouteGroupInterface
{
$callable = $this->callableResolver->resolve($this->callable);
$callable($this->routeCollectorProxy);
return $this;
}*/
}
35 changes: 13 additions & 22 deletions src/Chiron/Routing/RouteUrlGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,14 @@

namespace Chiron\Routing;

use Chiron\Routing\Traits\MiddlewareAwareInterface;
use Chiron\Routing\Traits\MiddlewareAwareTrait;
use Chiron\Routing\Traits\RouteCollectionInterface;
use Chiron\Routing\Traits\RouteCollectionTrait;
use Chiron\Routing\Traits\StrategyAwareInterface;
use Chiron\Routing\Traits\StrategyAwareTrait;
use FastRoute\DataGenerator;
use FastRoute\RouteParser\Std;
use InvalidArgumentException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use RuntimeException;

//https://github.com/symfony/routing/blob/master/Generator/UrlGenerator.php
//https://github.com/illuminate/routing/blob/master/RouteUrlGenerator.php

class RouteUrlGenerator
{

/** @var FastRoute\RouteParser\Std */
private $parser;

Expand Down Expand Up @@ -61,9 +50,9 @@ public function __construct(Router $router)
/**
* Build the path for a named route including the base path.
*
* @param string $routeName Route name
* @param array $substitutions Named argument replacement data
* @param array $queryParams Optional query string parameters
* @param string $routeName Route name
* @param array $substitutions Named argument replacement data
* @param array $queryParams Optional query string parameters
*
* @throws InvalidArgumentException If named route does not exist
* @throws InvalidArgumentException If required data not provided
Expand All @@ -85,7 +74,7 @@ public function urlFor(string $routeName, array $substitutions = [], array $quer
/**
* Build the path for a named route excluding the base path.
*
* @param string $routeName Route name
* @param string $routeName Route name
* @param array $substitutions Named argument replacement data
* @param array $queryParams Optional query string parameters
*
Expand Down Expand Up @@ -173,8 +162,9 @@ public function relativeUrlFor(string $routeName, array $substitutions = [], arr
/**
* Add a query string to the URI.
*
* @param string $url
* @param array $parameters
* @param string $url
* @param array $parameters
*
* @return mixed|string
*/
protected function addQueryString(string $url, array $parameters): string
Expand All @@ -187,23 +177,24 @@ protected function addQueryString(string $url, array $parameters): string
}
$url .= $this->getRouteQueryString($parameters);

return is_null($fragment) ? $url : $url."#{$fragment}";
return is_null($fragment) ? $url : $url . "#{$fragment}";
}

/**
* Get the query string for a given route.
*
* @param array $parameters
* @param array $parameters
*
* @return string
*/
protected function getRouteQueryString(array $parameters): string
{
$query = http_build_query($parameters, '', '&', PHP_QUERY_RFC3986);

return '?'.$query;
return '?' . $query;
}


/**
/*
* Returns the target path as relative reference from the base path.
*
* Only the URIs path component (no schema, host etc.) is relevant and must be given, starting with a slash.
Expand Down
6 changes: 3 additions & 3 deletions src/Chiron/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function __construct(DataGenerator $generator = null)
// build parent route collector
$this->generator = ($generator) ?? new DataGenerator\GroupCountBased();

// TODO utiliser ce bout de code et faire un tableau de pattern dans la classe de ce type ['slug' => 'xxxx', 'number' => 'yyyy']
// TODO utiliser ce bout de code et faire un tableau de pattern dans la classe de ce type ['slug' => 'xxxx', 'number' => 'yyyy']
/*
array_walk($this->patternMatchers, function ($value, $key) {
$this->addPatternMatcher($key, $value);
Expand Down Expand Up @@ -341,7 +341,7 @@ private function injectRoute(string $routeId, array $httpMethod, string $routePa
foreach ($routeDatas as $routeData) {
// TODO : réactiver le try catch si on souhaite pouvoir gérer les doublons de routes.
//try {
$this->generator->addRoute($method, $routeData, $routeId);
$this->generator->addRoute($method, $routeData, $routeId);
//} catch (\Throwable $e) {
//}
}
Expand Down Expand Up @@ -396,7 +396,7 @@ public function removeNamedRoute(string $name)
unset($this->routes[array_search($route, $this->routes)]);
}

/**
/*
* {@inheritdoc}
*/
/*
Expand Down
20 changes: 11 additions & 9 deletions src/Chiron/Routing/Traits/RouteCollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ public function any(string $pattern, $handler): Route
return $this->map($pattern, $handler);
}

/**
/**
* Create a redirect from one URI to another.
*
* @param string $url
* @param string $destination
* @param int $status
* @param string $url
* @param string $destination
* @param int $status
*
* @return \Chiron\Routing\Route
*/
Expand All @@ -189,24 +189,26 @@ public function redirect(string $url, string $destination, int $status = 302): R
->setDefault('destination', $destination)
->setDefault('status', $status);
}

/**
* Create a permanent redirect from one URI to another.
*
* @param string $url
* @param string $destination
* @param string $url
* @param string $destination
*
* @return \Chiron\Routing\Route
*/
public function permanentRedirect(string $url, string $destination): Route
{
return $this->redirect($url, $destination, 301);
}

/**
* Register a new route that returns a view.
*
* @param string $url
* @param string $view
* @param array $params
* @param string $url
* @param string $view
* @param array $params
*
* @return \Chiron\Routing\Route
*/
Expand Down
1 change: 1 addition & 0 deletions src/Chiron/Support/Helpers/misc2.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ function logging_extension()

default:
throw new Exception('Logging time[' . $logging_time . '] not found');

break;
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Http/Middleware/ErrorHandlerMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@
use Chiron\Http\Psr\ServerRequest;
use Chiron\Http\Psr\Uri;
use Chiron\Tests\Utils\RequestHandlerCallable;
use const E_USER_DEPRECATED;
use Error;
use function error_reporting;
use Exception;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Psr\Http\Message\ResponseFactoryInterface;
use RuntimeException;
use Throwable;
use const E_USER_DEPRECATED;
use function error_reporting;
use function trigger_error;

class ErrorHandlerMiddlewareTest extends TestCase
Expand Down

0 comments on commit ec8107d

Please sign in to comment.