diff --git a/app/Services/NNTP/NNTPService.php b/app/Services/NNTP/NNTPService.php index 6e8729909..ad53c90b8 100644 --- a/app/Services/NNTP/NNTPService.php +++ b/app/Services/NNTP/NNTPService.php @@ -470,7 +470,7 @@ class NNTPService extends NntpClient * * @throws \Exception */ - public function getXOVER(string $range): array|string|NNTPService + public function getXOVER(string $range): mixed { // Check if we are still connected. $connected = $this->_checkConnection(); diff --git a/tests/Unit/Services/NNTPServiceGetXoverReturnTypeTest.php b/tests/Unit/Services/NNTPServiceGetXoverReturnTypeTest.php new file mode 100644 index 000000000..e1e510786 --- /dev/null +++ b/tests/Unit/Services/NNTPServiceGetXoverReturnTypeTest.php @@ -0,0 +1,68 @@ +getReturnType(); + + $this->assertNotNull($returnType, 'getXOVER() must declare a return type.'); + + $typeNames = $returnType instanceof ReflectionNamedType + ? [$returnType->getName()] + : array_map( + fn ($type) => $type->getName(), + method_exists($returnType, 'getTypes') ? $returnType->getTypes() : [] + ); + + $isUnrestricted = in_array('mixed', $typeNames, true); + $permitsNntpError = in_array(NntpError::class, $typeNames, true) || in_array(\Error::class, $typeNames, true); + + $this->assertTrue( + $isUnrestricted || $permitsNntpError, + 'getXOVER() return type ('.(string) $returnType.') excludes '.NntpError::class. + ', which the NNTP client legitimately returns on server error responses. '. + 'Every caller already guards this with NNTPService::isError(), so the '. + 'declared type must not reject it -- use `mixed`, matching every other '. + 'method on this class that can return an Error.' + ); + } + + public function test_is_error_recognizes_nntp_error_instances(): void + { + $error = new NntpError('400 no such group', 400); + + $this->assertTrue(NNTPService::isError($error)); + $this->assertFalse(NNTPService::isError('some overview data')); + } +}