diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 41fc7a4..e7e31e2 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,9 +5,21 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -135,7 +147,7 @@
false
true
-
+
@@ -177,6 +189,8 @@
+
+
@@ -299,7 +313,7 @@
-
+
diff --git a/src/Pecee/Http/Input/InputHandler.php b/src/Pecee/Http/Input/InputHandler.php
index 1e3ac7b..b48fff2 100644
--- a/src/Pecee/Http/Input/InputHandler.php
+++ b/src/Pecee/Http/Input/InputHandler.php
@@ -73,7 +73,7 @@ class InputHandler
{
$list = [];
- foreach ((array)$_FILES as $key => $value) {
+ foreach ($_FILES as $key => $value) {
// Handle array input
if (\is_array($value['name']) === false) {
diff --git a/src/Pecee/Http/Middleware/BaseCsrfVerifier.php b/src/Pecee/Http/Middleware/BaseCsrfVerifier.php
index da1ce3e..4815e8c 100644
--- a/src/Pecee/Http/Middleware/BaseCsrfVerifier.php
+++ b/src/Pecee/Http/Middleware/BaseCsrfVerifier.php
@@ -17,7 +17,6 @@ class BaseCsrfVerifier implements IMiddleware
/**
* BaseCsrfVerifier constructor.
- * @throws \Pecee\Http\Security\Exceptions\SecurityException
*/
public function __construct()
{
diff --git a/src/Pecee/Http/Response.php b/src/Pecee/Http/Response.php
index 2e199f5..e7a7da9 100644
--- a/src/Pecee/Http/Response.php
+++ b/src/Pecee/Http/Response.php
@@ -30,7 +30,7 @@ class Response
* Redirect the response
*
* @param string $url
- * @param int $httpCode
+ * @param ?int $httpCode
*/
public function redirect(string $url, ?int $httpCode = null): void
{
@@ -86,7 +86,7 @@ class Response
/**
* Json encode
* @param array|\JsonSerializable $value
- * @param int $options JSON options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR.
+ * @param ?int $options JSON options Bitmask consisting of JSON_HEX_QUOT, JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_NUMERIC_CHECK, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES, JSON_FORCE_OBJECT, JSON_PRESERVE_ZERO_FRACTION, JSON_UNESCAPED_UNICODE, JSON_PARTIAL_OUTPUT_ON_ERROR.
* @param int $dept JSON debt.
* @throws InvalidArgumentException
*/
diff --git a/src/Pecee/Http/Url.php b/src/Pecee/Http/Url.php
index 5f34525..161dc37 100644
--- a/src/Pecee/Http/Url.php
+++ b/src/Pecee/Http/Url.php
@@ -20,7 +20,7 @@ class Url implements \JsonSerializable
/**
* Url constructor.
*
- * @param string $url
+ * @param ?string $url
* @throws MalformedUrlException
*/
public function __construct(?string $url)
@@ -385,7 +385,7 @@ class Url implements \JsonSerializable
{
$encodedUrl = preg_replace_callback(
'/[^:\/@?&=#]+/u',
- function ($matches) {
+ static function ($matches) {
return urlencode($matches[0]);
},
$url
@@ -412,7 +412,7 @@ class Url implements \JsonSerializable
if (\count($getParams) !== 0) {
if ($includeEmpty === false) {
- $getParams = array_filter($getParams, function ($item) {
+ $getParams = array_filter($getParams, static function ($item) {
return (trim($item) !== '');
});
}
diff --git a/src/Pecee/SimpleRouter/Event/EventArgument.php b/src/Pecee/SimpleRouter/Event/EventArgument.php
index 3346ffe..e1aad3e 100644
--- a/src/Pecee/SimpleRouter/Event/EventArgument.php
+++ b/src/Pecee/SimpleRouter/Event/EventArgument.php
@@ -74,7 +74,7 @@ class EventArgument implements IEventArgument
* @param string $name
* @return mixed
*/
- public function __get($name)
+ public function __get(string $name)
{
return $this->arguments[$name] ?? null;
}
@@ -83,7 +83,7 @@ class EventArgument implements IEventArgument
* @param string $name
* @return bool
*/
- public function __isset($name)
+ public function __isset(string $name)
{
return array_key_exists($name, $this->arguments);
}
@@ -93,7 +93,7 @@ class EventArgument implements IEventArgument
* @param mixed $value
* @throws \InvalidArgumentException
*/
- public function __set($name, $value)
+ public function __set(string $name, $value)
{
throw new \InvalidArgumentException('Not supported');
}
diff --git a/src/Pecee/SimpleRouter/Handlers/DebugEventHandler.php b/src/Pecee/SimpleRouter/Handlers/DebugEventHandler.php
index 690b275..fe4a954 100644
--- a/src/Pecee/SimpleRouter/Handlers/DebugEventHandler.php
+++ b/src/Pecee/SimpleRouter/Handlers/DebugEventHandler.php
@@ -16,7 +16,7 @@ class DebugEventHandler implements IEventHandler
public function __construct()
{
- $this->callback = function (EventArgument $argument) {
+ $this->callback = static function (EventArgument $argument) {
// todo: log in database
};
}
diff --git a/src/Pecee/SimpleRouter/Route/IGroupRoute.php b/src/Pecee/SimpleRouter/Route/IGroupRoute.php
index 2c18d1d..fbfddf3 100644
--- a/src/Pecee/SimpleRouter/Route/IGroupRoute.php
+++ b/src/Pecee/SimpleRouter/Route/IGroupRoute.php
@@ -59,7 +59,7 @@ interface IGroupRoute extends IRoute
* @param string $prefix
* @return static
*/
- public function setPrefix($prefix): self;
+ public function setPrefix(string $prefix): self;
/**
* Get prefix.
diff --git a/src/Pecee/SimpleRouter/Route/Route.php b/src/Pecee/SimpleRouter/Route/Route.php
index 08b8622..a955ff8 100644
--- a/src/Pecee/SimpleRouter/Route/Route.php
+++ b/src/Pecee/SimpleRouter/Route/Route.php
@@ -85,7 +85,7 @@ abstract class Route implements IRoute
/* Filter parameters with null-value */
if ($this->filterEmptyParams === true) {
- $parameters = array_filter($parameters, function ($var) {
+ $parameters = array_filter($parameters, static function ($var) {
return ($var !== null);
});
}
@@ -124,7 +124,7 @@ abstract class Route implements IRoute
return \call_user_func_array([$class, $method], $parameters);
}
- protected function parseParameters($route, $url, $parameterRegex = null)
+ protected function parseParameters($route, $url, $parameterRegex = null): ?array
{
$regex = (strpos($route, $this->paramModifiers[0]) === false) ? null :
sprintf
@@ -155,10 +155,8 @@ abstract class Route implements IRoute
/* If custom regex is defined, use that */
if (isset($this->where[$name]) === true) {
$regex = $this->where[$name];
- } else if ($parameterRegex !== null) {
- $regex = $parameterRegex;
} else {
- $regex = $this->defaultParameterRegex ?? static::PARAMETERS_DEFAULT_REGEX;
+ $regex = $parameterRegex ?? $this->defaultParameterRegex ?? static::PARAMETERS_DEFAULT_REGEX;
}
$regex = sprintf('((\/|\-)(?P<%2$s>%3$s))%1$s', $parameters[2][$key], $name, $regex);
diff --git a/src/Pecee/SimpleRouter/Route/RouteGroup.php b/src/Pecee/SimpleRouter/Route/RouteGroup.php
index 2f5e1d9..1c4cc33 100644
--- a/src/Pecee/SimpleRouter/Route/RouteGroup.php
+++ b/src/Pecee/SimpleRouter/Route/RouteGroup.php
@@ -123,7 +123,7 @@ class RouteGroup extends Route implements IGroupRoute
* @param string $prefix
* @return static
*/
- public function setPrefix($prefix): IGroupRoute
+ public function setPrefix(string $prefix): IGroupRoute
{
$this->prefix = '/' . trim($prefix, '/');
diff --git a/src/Pecee/SimpleRouter/Route/RoutePartialGroup.php b/src/Pecee/SimpleRouter/Route/RoutePartialGroup.php
index 956c248..fc3628b 100644
--- a/src/Pecee/SimpleRouter/Route/RoutePartialGroup.php
+++ b/src/Pecee/SimpleRouter/Route/RoutePartialGroup.php
@@ -38,7 +38,7 @@ class RoutePartialGroup extends RouteGroup implements IPartialGroupRoute
}
/* Set the parameters */
- $this->setParameters((array)$parameters);
+ $this->setParameters($parameters);
}
return $this->matchDomain($request);
diff --git a/src/Pecee/SimpleRouter/Route/RouteResource.php b/src/Pecee/SimpleRouter/Route/RouteResource.php
index 1795ec4..6c79f40 100644
--- a/src/Pecee/SimpleRouter/Route/RouteResource.php
+++ b/src/Pecee/SimpleRouter/Route/RouteResource.php
@@ -76,7 +76,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
return $this->url;
}
- protected function call($method)
+ protected function call($method): bool
{
$this->setCallback($this->controller . '@' . $method);
@@ -190,7 +190,7 @@ class RouteResource extends LoadableRoute implements IControllerRoute
* @param array $names
* @return static $this
*/
- public function setMethodNames(array $names)
+ public function setMethodNames(array $names): RouteResource
{
$this->methodNames = $names;
diff --git a/src/Pecee/SimpleRouter/Router.php b/src/Pecee/SimpleRouter/Router.php
index 8d70ebc..8b1378e 100644
--- a/src/Pecee/SimpleRouter/Router.php
+++ b/src/Pecee/SimpleRouter/Router.php
@@ -585,7 +585,7 @@ class Router
/* Check if callback matches (if it's not a function) */
$callback = $route->getCallback();
- if (\is_string($name) === true && \is_string($callback) === true && strpos($name, '@') !== false && strpos($callback, '@') !== false && \is_callable($callback) === false) {
+ if (\is_string($name) === true && \is_string($callback) === true && \is_callable($callback) === false && strpos($name, '@') !== false && strpos($callback, '@') !== false) {
/* Check if the entire callback is matching */
if (strpos($callback, $name) === 0 || strtolower($callback) === strtolower($name)) {
@@ -625,7 +625,6 @@ class Router
* @param array|null $getParams
* @return Url
* @throws InvalidArgumentException
- * @throws \Pecee\Http\Exceptions\MalformedUrlException
*/
public function getUrl(?string $name = null, $parameters = null, ?array $getParams = null): Url
{
diff --git a/src/Pecee/SimpleRouter/SimpleRouter.php b/src/Pecee/SimpleRouter/SimpleRouter.php
index cd1b61c..b8f4d06 100644
--- a/src/Pecee/SimpleRouter/SimpleRouter.php
+++ b/src/Pecee/SimpleRouter/SimpleRouter.php
@@ -75,7 +75,7 @@ class SimpleRouter
try {
ob_start();
static::router()->setDebugEnabled(true)->start();
- $routerOutput = ob_get_contents();
+ $routerOutput = ob_get_clean();
ob_end_clean();
} catch (\Exception $e) {
@@ -458,15 +458,8 @@ class SimpleRouter
try {
return static::router()->getUrl($name, $parameters, $getParams);
} catch (\Exception $e) {
- try {
- return new Url('/');
- } catch (MalformedUrlException $e) {
-
- }
+ return new Url('/');
}
-
- // This will never happen...
- return null;
}
/**
diff --git a/tests/Pecee/SimpleRouter/RouterUrlTest.php b/tests/Pecee/SimpleRouter/RouterUrlTest.php
index 78f9e1a..cd6c1a1 100644
--- a/tests/Pecee/SimpleRouter/RouterUrlTest.php
+++ b/tests/Pecee/SimpleRouter/RouterUrlTest.php
@@ -30,8 +30,8 @@ class RouterUrlTest extends \PHPUnit\Framework\TestCase
public function testUnicodeCharacters()
{
// Test spanish characters
- TestRouter::get('/cursos/listado/{listado?}/{category?}', 'DummyController@method1', ['defaultParameterRegex' => '[\w\p{L}\s-]+']);
- TestRouter::get('/test/{param}', 'DummyController@method1', ['defaultParameterRegex' => '[\w\p{L}\s-\í]+']);
+ TestRouter::get('/cursos/listado/{listado?}/{category?}', 'DummyController@method1', ['defaultParameterRegex' => '[\w\p{L}\s\-]+']);
+ TestRouter::get('/test/{param}', 'DummyController@method1', ['defaultParameterRegex' => '[\w\p{L}\s\-\í]+']);
TestRouter::debugNoReset('/cursos/listado/especialidad/cirugía local', 'get');
$this->assertEquals('/cursos/listado/{listado?}/{category?}/', TestRouter::router()->getRequest()->getLoadedRoute()->getUrl());