Skip to content

Commit e990b95

Browse files
authored
Merge pull request #563 from skipperbent/v4-development
Version 4.3.6.0
2 parents 319ce7a + a35400b commit e990b95

File tree

16 files changed

+109
-56
lines changed

16 files changed

+109
-56
lines changed

composer.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
},
3333
"require-dev": {
3434
"phpunit/phpunit": "^7",
35-
"mockery/mockery": "^1"
35+
"mockery/mockery": "^1",
36+
"phpstan/phpstan": "^0",
37+
"phpstan/phpstan-phpunit": "^0",
38+
"phpstan/phpstan-deprecation-rules": "^0",
39+
"phpstan/phpstan-strict-rules": "^0"
3640
},
3741
"scripts": {
3842
"test": [
@@ -44,4 +48,4 @@
4448
"Pecee\\": "src/Pecee/"
4549
}
4650
}
47-
}
51+
}

phpstan.neon

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
parameters:
2+
level: 6
3+
paths:
4+
- src
5+
fileExtensions:
6+
- php
7+
bootstrapFiles:
8+
- ./vendor/autoload.php
9+
ignoreErrors:
10+
reportUnmatchedIgnoredErrors: true
11+
checkMissingIterableValueType: false
12+
checkGenericClassInNonGenericObjectType: false
13+
parallel:
14+
processTimeout: 300.0
15+
jobSize: 10
16+
maximumNumberOfProcesses: 4
17+
minimumNumberOfJobsPerProcess: 4
18+
includes:
19+
- vendor/phpstan/phpstan-strict-rules/rules.neon
20+
- vendor/phpstan/phpstan-phpunit/extension.neon
21+
- vendor/phpstan/phpstan-phpunit/rules.neon
22+
- vendor/phpstan/phpstan-deprecation-rules/rules.neon

src/Pecee/Http/Input/IInputItem.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,14 @@ public function getName(): ?string;
1313

1414
public function setName(string $name): self;
1515

16+
/**
17+
* @return mixed
18+
*/
1619
public function getValue();
1720

21+
/**
22+
* @param mixed $value
23+
*/
1824
public function setValue($value): self;
1925

2026
public function __toString(): string;

src/Pecee/Http/Input/InputHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function parseFiles(array $files, ?string $parentKey = null): array
115115

116116
// Handle array input
117117
if (is_array($value['name']) === false) {
118-
$values['index'] = $parentKey ?? $key;
118+
$values = ['index' => $parentKey ?? $key];
119119

120120
try {
121121
$list[$key] = InputFile::createFromArray($values + $value);
@@ -161,7 +161,7 @@ protected function rearrangeFile(array $values, array &$index, ?array $original)
161161
try {
162162

163163
$file = InputFile::createFromArray([
164-
'index' => (empty($key) === true && empty($originalIndex) === false) ? $originalIndex : $key,
164+
'index' => ($key === '' && $originalIndex !== '') ? $originalIndex : $key,
165165
'name' => $original['name'][$key],
166166
'error' => $original['error'][$key],
167167
'tmp_name' => $original['tmp_name'][$key],

src/Pecee/Http/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public function __construct()
137137

138138
public function isSecure(): bool
139139
{
140-
return $this->getHeader('http-x-forwarded-proto') === 'https' || $this->getHeader('https') !== null || $this->getHeader('server-port') === 443;
140+
return $this->getHeader('http-x-forwarded-proto') === 'https' || $this->getHeader('https') !== null || (int)$this->getHeader('server-port') === 443;
141141
}
142142

143143
/**

src/Pecee/Http/Url.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ public function parseUrl(string $url, int $component = -1): array
387387
{
388388
$encodedUrl = preg_replace_callback(
389389
'/[^:\/@?&=#]+/u',
390-
static function ($matches) {
390+
static function ($matches): string {
391391
return urlencode($matches[0]);
392392
},
393393
$url
@@ -414,7 +414,7 @@ public static function arrayToParams(array $getParams = [], bool $includeEmpty =
414414
if (count($getParams) !== 0) {
415415

416416
if ($includeEmpty === false) {
417-
$getParams = array_filter($getParams, static function ($item) {
417+
$getParams = array_filter($getParams, static function ($item): bool {
418418
return (trim($item) !== '');
419419
});
420420
}
@@ -458,15 +458,15 @@ public function getAbsoluteUrl(bool $includeParams = true): string
458458
$port = $this->port !== null ? ':' . $this->port : '';
459459
$user = $this->username ?? '';
460460
$pass = $this->password !== null ? ':' . $this->password : '';
461-
$pass = ($user || $pass) ? $pass . '@' : '';
461+
$pass = ($user !== '' || $pass !== '') ? $pass . '@' : '';
462462

463463
return $scheme . $user . $pass . $host . $port . $this->getRelativeUrl($includeParams);
464464
}
465465

466466
/**
467467
* Specify data which should be serialized to JSON
468468
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php
469-
* @return mixed data which can be serialized by <b>json_encode</b>,
469+
* @return string data which can be serialized by <b>json_encode</b>,
470470
* which is a value of any type other than a resource.
471471
* @since 5.4.0
472472
*/

src/Pecee/SimpleRouter/Handlers/DebugEventHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DebugEventHandler implements IEventHandler
1717

1818
public function __construct()
1919
{
20-
$this->callback = static function (EventArgument $argument) {
20+
$this->callback = static function (EventArgument $argument): void {
2121
// todo: log in database
2222
};
2323
}

src/Pecee/SimpleRouter/Route/IControllerRoute.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Pecee\SimpleRouter\Route;
44

5-
interface IControllerRoute extends IRoute
5+
interface IControllerRoute extends ILoadableRoute
66
{
77
/**
88
* Get controller class-name

src/Pecee/SimpleRouter/Route/Route.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ abstract class Route implements IRoute
3030
protected $urlRegex = '/^%s\/?$/u';
3131
protected $group;
3232
protected $parent;
33+
/**
34+
* @var string|callable|null
35+
*/
3336
protected $callback;
3437
protected $defaultNamespace;
3538

@@ -67,7 +70,7 @@ public function renderRoute(Request $request, Router $router): ?string
6770

6871
/* Filter parameters with null-value */
6972
if ($this->filterEmptyParams === true) {
70-
$parameters = array_filter($parameters, static function ($var) {
73+
$parameters = array_filter($parameters, static function ($var): bool {
7174
return ($var !== null);
7275
});
7376
}
@@ -82,6 +85,7 @@ public function renderRoute(Request $request, Router $router): ?string
8285
}
8386

8487
/* When the callback is a function */
88+
8589
return $router->getClassLoader()->loadClosure($callback, $parameters);
8690
}
8791

@@ -280,7 +284,7 @@ public function setCallback($callback): IRoute
280284
}
281285

282286
/**
283-
* @return string|callable
287+
* @return string|callable|null
284288
*/
285289
public function getCallback()
286290
{
@@ -337,6 +341,11 @@ public function setClass(string $class): IRoute
337341
*/
338342
public function setNamespace(string $namespace): IRoute
339343
{
344+
// Do not set namespace when class-hinting is used
345+
if (is_array($this->callback) === true) {
346+
return $this;
347+
}
348+
340349
$ns = $this->getNamespace();
341350

342351
if ($ns !== null) {

src/Pecee/SimpleRouter/Route/RouteController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function hasName(string $name): bool
5252
public function findUrl(?string $method = null, $parameters = null, ?string $name = null): string
5353
{
5454
if (strpos($name, '.') !== false) {
55-
$found = array_search(substr($name, strrpos($name, '.') + 1), $this->names, false);
55+
$found = array_search(substr($name, strrpos($name, '.') + 1), $this->names, true);
5656
if ($found !== false) {
5757
$method = (string)$found;
5858
}
@@ -67,7 +67,7 @@ public function findUrl(?string $method = null, $parameters = null, ?string $nam
6767
foreach (Request::$requestTypes as $requestType) {
6868

6969
if (stripos($method, $requestType) === 0) {
70-
$method = (string)substr($method, strlen($requestType));
70+
$method = substr($method, strlen($requestType));
7171
break;
7272
}
7373
}

0 commit comments

Comments
 (0)