Skip to content

Commit 0df644d

Browse files
committed
maintenance: phpstan type safety
1 parent 45859e8 commit 0df644d

2 files changed

Lines changed: 41 additions & 7 deletions

File tree

src/Path/DynamicPath.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ public function get(?string $key = null, bool $extra = false):?string {
4848
return null;
4949
}
5050

51+
/**
52+
* @param array<string> $filePathParts
53+
* @param array<string> $requestPathParts
54+
*/
5155
private function handleNullKey(
5256
array $filePathParts,
5357
array $requestPathParts,
@@ -60,7 +64,14 @@ private function handleNullKey(
6064
return $requestPathParts[count($filePathParts) - 1] ?? null;
6165
}
6266

63-
private function getExtraPath(array $filePathParts, array $requestPathParts):string {
67+
/**
68+
* @param array<string> $filePathParts
69+
* @param array<string> $requestPathParts
70+
*/
71+
private function getExtraPath(
72+
array $filePathParts,
73+
array $requestPathParts,
74+
):string {
6475
$test = "";
6576
for($ppi = count($filePathParts), $len = count($requestPathParts); $ppi < $len; $ppi++) {
6677
$test .= $requestPathParts[$ppi] . "/";
@@ -72,7 +83,11 @@ private function matchesKey(string $placeholder, string $key):bool {
7283
return ltrim($placeholder, "@") === $key;
7384
}
7485

75-
private function getMatchedKey(array $requestPathParts, int $index):?string {
86+
/** @param array<string> $requestPathParts */
87+
private function getMatchedKey(
88+
array $requestPathParts,
89+
int $index,
90+
):?string {
7691
return $requestPathParts[$index] ?? null;
7792
}
7893

src/RouterCallback.php

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,26 @@ public function isAllowedMethod(string $requestMethod):bool {
5050
return $this->isMethodAllowed($requestMethod, $allowedMethods);
5151
}
5252

53-
private function getAllowedMethods(): array {
53+
/** @return array<string> */
54+
private function getAllowedMethods():array {
5455
$methodsArgument = $this->attribute->getArguments()["methods"] ?? [];
5556
return $this->mapAttributeToMethods($this->attribute->getName(), $methodsArgument);
5657
}
5758

58-
private function mapAttributeToMethods(string $attributeName, array $methodsArgument): array {
59+
/**
60+
* @param array<string> $methodsArgument
61+
* @return array<string>
62+
*/
63+
private function mapAttributeToMethods(
64+
string $attributeName,
65+
array $methodsArgument,
66+
):array {
5967
$attributeMethodMap = $this->getAttributeMethodMap();
6068
return $attributeMethodMap[$attributeName] ?? $methodsArgument;
6169
}
6270

63-
private function getAttributeMethodMap(): array {
71+
/** @return array<class-string, array<string>> */
72+
private function getAttributeMethodMap():array {
6473
return [
6574
Any::class => HttpRoute::METHODS_ALL,
6675
Connect::class => [HttpRoute::METHOD_CONNECT],
@@ -75,11 +84,21 @@ private function getAttributeMethodMap(): array {
7584
];
7685
}
7786

78-
private function normalizeMethods(array $methods): array {
87+
/**
88+
* @param array<string> $methods
89+
* @return array<string>
90+
*/
91+
private function normalizeMethods(array $methods):array {
7992
return array_map("strtoupper", $methods);
8093
}
8194

82-
private function isMethodAllowed(string $requestMethod, array $allowedMethods): bool {
95+
/**
96+
* @param array<string> $allowedMethods
97+
*/
98+
private function isMethodAllowed(
99+
string $requestMethod,
100+
array $allowedMethods,
101+
):bool {
83102
return in_array(strtoupper($requestMethod), $allowedMethods, true);
84103
}
85104

0 commit comments

Comments
 (0)