Skip to content

Commit 6a8fd92

Browse files
Ninerianclaude
andcommitted
chore: raise phpstan to level 6 and fix all type annotations
- Updated phpstan.neon.dist to level 6 - Added comprehensive array type annotations (array<string,mixed>) - Added missing return type declarations for all methods - Added missing property type declarations - Fixed PHPUnit mock template type resolution - Added proper DocBlock annotations for complex types - Removed unused properties - Applied fixes across src/ and test/ directories Major improvements: - AbstractToken.php: array types and return types - SSOData traits: comprehensive type annotations - Test classes: complete type coverage and mock annotations 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 57fa3de commit 6a8fd92

14 files changed

Lines changed: 141 additions & 68 deletions

phpstan.neon.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
level: 4
2+
level: 6
33
paths:
44
- ./src
55
- ./test

src/AbstractToken.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ abstract class AbstractToken
2525

2626
private Configuration $config;
2727

28+
/**
29+
* @var Constraint[]
30+
*/
2831
private array $constraints;
2932

3033
/**
@@ -102,13 +105,22 @@ protected function hasClaim(string $claim): bool
102105
*
103106
* @return mixed
104107
*/
105-
protected function getClaim(string $claim)
108+
/**
109+
* Get a claim without checking for existence.
110+
*
111+
* @param string $claim name.
112+
*
113+
* @return mixed
114+
*/
115+
protected function getClaim(string $claim): mixed
106116
{
107117
return $this->token->claims()->get($claim);
108118
}
109119

110120
/**
111121
* Get an array of all available claims and their values.
122+
*
123+
* @return array<string, mixed>
112124
*/
113125
protected function getAllClaims(): array
114126
{

src/RemoteCall/AbstractRemoteCallHandler.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class AbstractRemoteCallHandler implements RemoteCallInterface
3232
*
3333
* This will tell Staffbase that everything went OK.
3434
*/
35-
public function exitSuccess()
35+
public function exitSuccess(): void
3636
{
3737
header("HTTP/1.1 200 OK");
3838
exit;
@@ -43,7 +43,7 @@ public function exitSuccess()
4343
*
4444
* This will tell Staffbase that it should try again later.
4545
*/
46-
public function exitFailure()
46+
public function exitFailure(): void
4747
{
4848
header('HTTP/1.1 500 Internal Server Error');
4949
exit;

src/RemoteCall/RemoteCallInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ interface RemoteCallInterface
3131
*
3232
* This will tell Staffbase that everything went OK.
3333
*/
34-
public function exitSuccess();
34+
public function exitSuccess(): void;
3535

3636
/**
3737
* Stop the execution by providing a non 2XX HTTP response
3838
*
3939
* This will tell Staffbase that it should try again later.
4040
*/
41-
public function exitFailure();
41+
public function exitFailure(): void;
4242
}

src/SSOData/ClaimAccessTrait.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ abstract protected function hasClaim(string $claim): bool;
3737
*
3838
* @return mixed
3939
*/
40+
/**
41+
* @return mixed
42+
*/
4043
abstract protected function getClaim(string $claim);
41-
4244
/**
4345
* Get an array of all available claims and their values.
4446
*
4547
* @return array
4648
*/
49+
/**
50+
* @return array<string, mixed>
51+
*/
4752
abstract protected function getAllClaims(): array;
4853

4954
/**

src/SSOData/SSODataTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public function getLocale(): string
200200
/**
201201
* Get the user tags.
202202
*
203-
* @return array|null
203+
* @return array<mixed>|null
204204
*/
205205
public function getTags(): ?array
206206
{

src/SSOData/SharedDataTrait.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ trait SharedDataTrait
3838
*/
3939
public function getAudience(): ?string
4040
{
41-
/** @var array|string|null $audience */
41+
/** @var array<string>|string|null $audience */
4242
$audience = $this->getClaimSafe(SharedClaimsInterface::CLAIM_AUDIENCE);
4343

4444
if (is_array($audience)) {
@@ -129,7 +129,7 @@ public function getRole(): ?string
129129
/**
130130
* Get all stored data.
131131
*
132-
* @return array
132+
* @return array<string,mixed>
133133
*/
134134
public function getData(): array
135135
{

src/SSOTokenGenerator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class SSOTokenGenerator
3737
*
3838
* @return string Encoded token.
3939
*/
40+
/**
41+
* @param array<string,mixed> $tokenData
42+
*/
4043
public static function createSignedTokenFromData(string $privateKey, array $tokenData, Signer $signer = null): string
4144
{
4245

@@ -49,6 +52,9 @@ public static function createSignedTokenFromData(string $privateKey, array $toke
4952
* @param array $tokenData
5053
* @return Token
5154
*/
55+
/**
56+
* @param array<string,mixed> $tokenData
57+
*/
5258
private static function buildToken(Configuration $config, array $tokenData): Token
5359
{
5460
$builder = $config->builder();

src/SessionHandling/SessionHandlerTrait.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,25 +52,25 @@ protected function closeSession(): void
5252
/**
5353
* Checks if the given key is set
5454
*
55-
* @param mixed $key
55+
* @param string $key
5656
* @param string|null $parentKey
5757
*
5858
* @return bool
5959
*/
60-
public function hasSessionVar($key, ?string $parentKey = null): bool
60+
public function hasSessionVar(string $key, ?string $parentKey = null): bool
6161
{
6262
return isset($_SESSION[$this->pluginInstanceId][$parentKey ?? self::$KEY_DATA][$key]);
6363
}
6464

6565
/**
6666
* Get a previously set session variable.
6767
*
68-
* @param mixed $key
68+
* @param string $key
6969
* @param string|null $parentKey
7070
*
7171
* @return mixed|null
7272
*/
73-
public function getSessionVar($key, ?string $parentKey = null)
73+
public function getSessionVar(string $key, ?string $parentKey = null)
7474
{
7575
return $_SESSION[$this->pluginInstanceId][$parentKey ?? self::$KEY_DATA][$key] ?? null;
7676
}
@@ -80,7 +80,7 @@ public function getSessionVar($key, ?string $parentKey = null)
8080
*
8181
* @param string|null $parentKey
8282
*
83-
* @return array
83+
* @return array<string,mixed>
8484
*/
8585
public function getSessionData(?string $parentKey = null): array
8686
{
@@ -94,7 +94,10 @@ public function getSessionData(?string $parentKey = null): array
9494
* @param string|null $parentKey
9595
*
9696
*/
97-
public function setSessionData($data, ?string $parentKey = null): void
97+
/**
98+
* @param array<string,mixed> $data
99+
*/
100+
public function setSessionData(array $data, ?string $parentKey = null): void
98101
{
99102
$_SESSION[$this->pluginInstanceId][$parentKey ?? self::$KEY_DATA] = $data;
100103
}
@@ -106,7 +109,11 @@ public function setSessionData($data, ?string $parentKey = null): void
106109
* @param mixed $val
107110
* @param string|null $parentKey
108111
*/
109-
public function setSessionVar($key, $val, ?string $parentKey = null): void
112+
/**
113+
* @param string $key
114+
* @param mixed $val
115+
*/
116+
public function setSessionVar(string $key, mixed $val, ?string $parentKey = null): void
110117
{
111118
$_SESSION[$this->pluginInstanceId][$parentKey ?? self::$KEY_DATA][$key] = $val;
112119
}
@@ -118,7 +125,7 @@ public function setSessionVar($key, $val, ?string $parentKey = null): void
118125
* @param String|null $sessionId
119126
* @return bool true on success or false on failure.
120127
*/
121-
public function destroySession(String $sessionId = null): bool
128+
public function destroySession(?string $sessionId = null): bool
122129
{
123130
$sessionId = $sessionId ?: $this->sessionId;
124131

@@ -140,7 +147,7 @@ public function destroySession(String $sessionId = null): bool
140147
return $result;
141148
}
142149

143-
private function createCompatibleSessionId(String $string): String
150+
private function createCompatibleSessionId(string $string): string
144151
{
145152
$notAllowedCharsPattern = '/[^a-zA-Z0-9,-]/';
146153
return preg_replace($notAllowedCharsPattern, '-', $string);

src/SessionHandling/SessionTokenDataTrait.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ protected function hasClaim(string $claim): bool
4444
*
4545
* @return mixed
4646
*/
47-
protected function getClaim(string $claim)
47+
/**
48+
* @return mixed
49+
*/
50+
protected function getClaim(string $claim): mixed
4851
{
4952
return $this->getSessionVar($claim, self::$keySso);
5053
}
@@ -54,17 +57,18 @@ protected function getClaim(string $claim)
5457
*
5558
* @return array
5659
*/
60+
/**
61+
* @return array<string,mixed>
62+
*/
5763
protected function getAllClaims(): array
5864
{
5965
return $this->getSessionData(self::$keySso);
6066
}
6167

6268
/**
63-
*
64-
* @param $data
65-
* @return void
69+
* @param array<string,mixed> $data
6670
*/
67-
protected function setClaims($data): void
71+
protected function setClaims(array $data): void
6872
{
6973
$this->setSessionData($data, self::$keySso);
7074
}

0 commit comments

Comments
 (0)