Small code cleanup

This commit is contained in:
Timothy Warren 2019-01-07 09:08:00 -05:00
parent ac382a96a8
commit b66a35843d
4 changed files with 20 additions and 29 deletions

View File

@ -45,10 +45,10 @@ final class Dispatcher extends RoutingBase {
protected $matcher;
/**
* Class wrapper for input superglobals
* @var \Psr\Http\Message\ServerRequestInterface
* Routing array
* @var array
*/
protected $request;
protected $routes;
/**
* Routes added to router
@ -67,8 +67,7 @@ final class Dispatcher extends RoutingBase {
$router = $this->container->get('aura-router');
$this->router = $router->getMap();
$this->matcher = $router->getMatcher();
$this->request = $container->get('request');
$this->routes = $this->config->get('routes');
$this->outputRoutes = $this->setupRoutes();
}

View File

@ -39,10 +39,10 @@ class RoutingBase {
protected $config;
/**
* Routing array
* @var array
* Class wrapper for input superglobals
* @var \Psr\Http\Message\ServerRequestInterface
*/
protected $routes;
protected $request;
/**
* Constructor
@ -56,7 +56,7 @@ class RoutingBase {
{
$this->container = $container;
$this->config = $container->get('config');
$this->routes = $this->config->get('routes');
$this->request = $container->get('request');
}
/**
@ -67,8 +67,7 @@ class RoutingBase {
*/
public function path(): string
{
$request = $this->container->get('request');
$path = $request->getUri()->getPath();
$path = $this->request->getUri()->getPath();
$cleanedPath = $this->string($path)
->replace('%20', '')
->trim()
@ -117,4 +116,3 @@ class RoutingBase {
return end($segments);
}
}
// End of RoutingBase.php

View File

@ -124,7 +124,7 @@ class AnimeClientTestCase extends TestCase {
* @param array $supers
* @return void
*/
public function setSuperGlobals($supers = [])
public function setSuperGlobals($supers = []): void
{
$default = [
'_SERVER' => $_SERVER,
@ -139,7 +139,7 @@ class AnimeClientTestCase extends TestCase {
array_merge($default, $supers)
);
$this->container->setInstance('request', $request);
$this->container->set('repsone', function() {
$this->container->set('response', function() {
return new HttpResponse();
});
}
@ -151,7 +151,7 @@ class AnimeClientTestCase extends TestCase {
*
* @return string - contents of the data file
*/
public function getMockFile()
public function getMockFile(): string
{
$args = func_get_args();
array_unshift($args, TEST_DATA_DIR);

View File

@ -20,14 +20,6 @@ use Aviat\AnimeClient\RoutingBase;
class RoutingBaseTest extends AnimeClientTestCase {
protected $routingBase;
public function setUp()
{
parent::setUp();
$this->routingBase = new RoutingBase($this->container);
}
public function dataSegments()
{
return [
@ -49,7 +41,7 @@ class RoutingBaseTest extends AnimeClientTestCase {
/**
* @dataProvider dataSegments
*/
public function testSegments($requestUri, $path, $segments, $lastSegment)
public function testSegments(string $requestUri, string $path, array $segments, $lastSegment): void
{
$this->setSuperGlobals([
'_SERVER' => [
@ -57,13 +49,15 @@ class RoutingBaseTest extends AnimeClientTestCase {
]
]);
$this->assertEquals($path, $this->routingBase->path(), "Path is invalid");
$this->assertEquals($segments, $this->routingBase->segments(), "Segments array is invalid");
$this->assertEquals($lastSegment, $this->routingBase->lastSegment(), "Last segment is invalid");
$routingBase = new RoutingBase($this->container);
$this->assertEquals($path, $routingBase->path(), "Path is invalid");
$this->assertEquals($segments, $routingBase->segments(), "Segments array is invalid");
$this->assertEquals($lastSegment, $routingBase->lastSegment(), "Last segment is invalid");
foreach($segments as $i => $value)
{
$this->assertEquals($value, $this->routingBase->getSegment($i), "Segment {$i} is invalid");
$this->assertEquals($value, $routingBase->getSegment($i), "Segment {$i} is invalid");
}
}
}