Skip to content

Commit 1fa3c3c

Browse files
Ninerianclaude
andcommitted
chore: raise phpstan to level 8 and fix null safety
- Updated phpstan.neon.dist to level 8 - Added null checks for ReflectionClass::getConstructor() calls in test files - Enhanced PluginSession to handle nullable instanceId parameter - Used PHP 8+ null coalescing throw operator for clean error handling - Improved null safety across test and source files Key improvements: - All ReflectionMethod calls now safely handle null returns - deleteInstance method properly validates required instanceId parameter - Modern PHP syntax for null safety with descriptive error messages - No breaking changes to existing functionality 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 3d223be commit 1fa3c3c

File tree

4 files changed

+11
-10
lines changed

4 files changed

+11
-10
lines changed

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: 7
2+
level: 8
33
paths:
44
- ./src
55
- ./test

src/PluginSession.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ public function __construct(
8686
// delete the instance if the special sub is in the token data
8787
// exits the request
8888
if ($sso && $remoteCallHandler && $sso->isDeleteInstanceCall()) {
89-
$this->deleteInstance($sso->getInstanceId(), $remoteCallHandler);
89+
$instanceId = $sso->getInstanceId() ?: throw new SSOException('Instance id is required for deleteInstance');
90+
$this->deleteInstance($instanceId, $remoteCallHandler);
9091
}
9192

9293
// starts the session

test/PluginSessionTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function testConstructorWorksAsExpected(): void
115115
->with($this->pluginId);
116116

117117
$reflectedClass = new ReflectionClass($this->classname);
118-
$constructor = $reflectedClass->getConstructor();
118+
$constructor = $reflectedClass->getConstructor() ?: throw new \Exception('Constructor not found');
119119
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
120120

121121
$this->setupEnvironment($this->pluginInstanceId, null, false);
@@ -143,7 +143,7 @@ public function testConstructorRejectsSpoofedPID(): void
143143
$this->expectException(SSOException::class);
144144

145145
$reflectedClass = new ReflectionClass($this->classname);
146-
$constructor = $reflectedClass->getConstructor();
146+
$constructor = $reflectedClass->getConstructor() ?: throw new \Exception('Constructor not found');
147147
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
148148
}
149149

@@ -168,7 +168,7 @@ public function testConstructorRefuseEmptyPluginId(): void
168168
$this->expectExceptionMessage('Empty plugin ID.');
169169

170170
$reflectedClass = new ReflectionClass($this->classname);
171-
$constructor = $reflectedClass->getConstructor();
171+
$constructor = $reflectedClass->getConstructor() ?: throw new \Exception('Constructor not found');
172172
$constructor->invoke($mock, '', $this->publicKey);
173173
}
174174

@@ -193,7 +193,7 @@ public function testConstructorRefuseEmptySecret(): void
193193
$this->expectExceptionMessage('Parameter appSecret for SSOToken is empty.');
194194

195195
$reflectedClass = new ReflectionClass($this->classname);
196-
$constructor = $reflectedClass->getConstructor();
196+
$constructor = $reflectedClass->getConstructor() ?: throw new \Exception('Constructor not found');
197197
$constructor->invoke($mock, $this->pluginId, '');
198198
}
199199

@@ -218,7 +218,7 @@ public function testConstructorRefuseEmptyEnv(): void
218218
$this->expectExceptionMessage('Missing PID or JWT query parameter in Request.');
219219

220220
$reflectedClass = new ReflectionClass($this->classname);
221-
$constructor = $reflectedClass->getConstructor();
221+
$constructor = $reflectedClass->getConstructor() ?: throw new \Exception('Constructor not found');
222222
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
223223
}
224224

@@ -243,7 +243,7 @@ public function testConstructorRefuseHavingBothJwtAndPid(): void
243243
$this->expectExceptionMessage('Tried to initialize the session with both PID and JWT provided.');
244244

245245
$reflectedClass = new ReflectionClass($this->classname);
246-
$constructor = $reflectedClass->getConstructor();
246+
$constructor = $reflectedClass->getConstructor() ?: throw new \Exception('Constructor not found');
247247
$constructor->invoke($mock, $this->pluginId, $this->publicKey);
248248
}
249249

test/SSOTokenTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function testConstructorRefuseEmptySecret(): void
6868
$this->expectExceptionMessage('Parameter appSecret for SSOToken is empty.');
6969

7070
$reflectedClass = new ReflectionClass(SSOToken::class);
71-
$constructor = $reflectedClass->getConstructor();
71+
$constructor = $reflectedClass->getConstructor() ?: throw new \Exception('Constructor not found');
7272
$constructor->invoke($mock, ' ', 'fake token');
7373
}
7474

@@ -91,7 +91,7 @@ public function testConstructorRefuseEmptyToken(): void
9191
$this->expectExceptionMessage('Parameter tokenData for SSOToken is empty.');
9292

9393
$reflectedClass = new ReflectionClass(SSOToken::class);
94-
$constructor = $reflectedClass->getConstructor();
94+
$constructor = $reflectedClass->getConstructor() ?: throw new \Exception('Constructor not found');
9595
$constructor->invoke($mock, 'fake secret', ' ');
9696
}
9797

0 commit comments

Comments
 (0)